blob: 12c01172bb6996566e4b3ae88f723671864ab858 [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 Gunnd4575212021-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 Choic7ebc0f2021-11-15 23:46:41 +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 Reddy864fe982021-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 Sasindranbf5c79c2021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Sasindranbf5c79c2021-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 Sasindranbf5c79c2021-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 Sasindranbf5c79c2021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Reddy864fe982021-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 Spivackbb777522021-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 Spivackbb777522021-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 =
2062 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2063 notifyRequester(request);
2064 break;
2065
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 default:
2067 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2068 break;
2069 }
2070 }
Jake Hambye994d462014-02-03 13:10:13 -08002071
Pengquan Menga1bb6272018-09-06 09:59:22 -07002072 private void notifyRequester(MainThreadRequest request) {
2073 synchronized (request) {
2074 request.notifyAll();
2075 }
2076 }
2077
Jake Hambye994d462014-02-03 13:10:13 -08002078 private void handleNullReturnEvent(Message msg, String command) {
2079 AsyncResult ar = (AsyncResult) msg.obj;
2080 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2081 if (ar.exception == null) {
2082 request.result = true;
2083 } else {
2084 request.result = false;
2085 if (ar.exception instanceof CommandException) {
2086 loge(command + ": CommandException: " + ar.exception);
2087 } else {
2088 loge(command + ": Unknown exception");
2089 }
2090 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002091 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 }
2094
2095 /**
2096 * Posts the specified command to be executed on the main thread,
2097 * waits for the request to complete, and returns the result.
2098 * @see #sendRequestAsync
2099 */
2100 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002101 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2102 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002103 }
2104
2105 /**
2106 * Posts the specified command to be executed on the main thread,
2107 * waits for the request to complete, and returns the result.
2108 * @see #sendRequestAsync
2109 */
2110 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2111 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002112 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002113 }
2114
2115 /**
2116 * Posts the specified command to be executed on the main thread,
2117 * waits for the request to complete, and returns the result.
2118 * @see #sendRequestAsync
2119 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002120 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002121 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2122 }
2123
2124 /**
2125 * Posts the specified command to be executed on the main thread,
2126 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2127 * if not timeout or null otherwise.
2128 * @see #sendRequestAsync
2129 */
2130 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2131 long timeoutInMs) {
2132 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002133 }
2134
2135 /**
2136 * Posts the specified command to be executed on the main thread,
2137 * waits for the request to complete, and returns the result.
2138 * @see #sendRequestAsync
2139 */
Nathan Harold92bed182018-10-12 18:16:49 -07002140 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002141 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002142 }
2143
2144 /**
2145 * Posts the specified command to be executed on the main thread,
2146 * waits for the request to complete, and returns the result.
2147 * @see #sendRequestAsync
2148 */
2149 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002150 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2151 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002152 }
2153
2154 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002155 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2156 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2157 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002158 * @see #sendRequestAsync
2159 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002160 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2161 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2163 throw new RuntimeException("This method will deadlock if called from the main thread.");
2164 }
2165
Nathan Harold92bed182018-10-12 18:16:49 -07002166 MainThreadRequest request = null;
2167 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2168 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2169 } else if (phone != null) {
2170 request = new MainThreadRequest(argument, phone, workSource);
2171 } else {
2172 request = new MainThreadRequest(argument, subId, workSource);
2173 }
2174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 Message msg = mMainThreadHandler.obtainMessage(command, request);
2176 msg.sendToTarget();
2177
Rambo Wang0f050d82021-02-12 11:43:36 -08002178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002180 if (timeoutInMs >= 0) {
2181 // Wait for at least timeoutInMs before returning null request result
2182 long now = SystemClock.elapsedRealtime();
2183 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002184 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002185 try {
2186 request.wait(deadline - now);
2187 } catch (InterruptedException e) {
2188 // Do nothing, go back and check if request is completed or timeout
2189 } finally {
2190 now = SystemClock.elapsedRealtime();
2191 }
2192 }
2193 } else {
2194 // Wait for the request to complete
2195 while (request.result == null) {
2196 try {
2197 request.wait();
2198 } catch (InterruptedException e) {
2199 // Do nothing, go back and wait until the request is complete
2200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 }
2202 }
2203 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002204 if (request.result == null) {
2205 Log.wtf(LOG_TAG,
2206 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 return request.result;
2209 }
2210
2211 /**
2212 * Asynchronous ("fire and forget") version of sendRequest():
2213 * Posts the specified command to be executed on the main thread, and
2214 * returns immediately.
2215 * @see #sendRequest
2216 */
2217 private void sendRequestAsync(int command) {
2218 mMainThreadHandler.sendEmptyMessage(command);
2219 }
2220
2221 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002222 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002223 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002224 */
2225 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002226 sendRequestAsync(command, argument, null, null);
2227 }
2228
2229 /**
2230 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2231 * @see {@link #sendRequest(int,Object)}
2232 */
2233 private void sendRequestAsync(
2234 int command, Object argument, Phone phone, WorkSource workSource) {
2235 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002236 Message msg = mMainThreadHandler.obtainMessage(command, request);
2237 msg.sendToTarget();
2238 }
2239
2240 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 * Initialize the singleton PhoneInterfaceManager instance.
2242 * This is only done once, at startup, from PhoneApp.onCreate().
2243 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002244 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 synchronized (PhoneInterfaceManager.class) {
2246 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002247 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 } else {
2249 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2250 }
2251 return sInstance;
2252 }
2253 }
2254
2255 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002256 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002259 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002260 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002262 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002264 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002265 mTelephonySharedPreferences =
2266 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002267 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002268 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002269 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002270 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002271
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 publish();
2273 }
2274
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002275 private Phone getDefaultPhone() {
2276 Phone thePhone = getPhone(getDefaultSubscription());
2277 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2278 }
2279
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 private void publish() {
2281 if (DBG) log("publish: " + this);
2282
Peter Wangc035ce42020-01-08 21:00:22 -08002283 TelephonyFrameworkInitializer
2284 .getTelephonyServiceManager()
2285 .getTelephonyServiceRegisterer()
2286 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 }
2288
Stuart Scott584921c2015-01-15 17:10:34 -08002289 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002290 if (request.phone != null) {
2291 return request.phone;
2292 } else {
2293 return getPhoneFromSubId(request.subId);
2294 }
2295 }
2296
2297 private Phone getPhoneFromSubId(int subId) {
2298 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2299 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002300 }
2301
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002302 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002303 Phone phone = getPhoneFromRequest(request);
2304 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002305 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002306 }
2307
Wink Saville36469e72014-06-11 15:17:00 -07002308 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002309 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002310 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312
Kai Shif70f46f2021-03-03 13:59:46 -08002313 private void sendEraseModemConfig(@NonNull Phone phone) {
2314 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2315 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2316 }
2317
2318 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2319 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2320 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002321 }
2322
Peter Wang44b186e2020-01-13 23:33:09 -08002323 private boolean isImsAvailableOnDevice() {
2324 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2325 if (pm == null) {
2326 // For some reason package manger is not available.. This will fail internally anyway,
2327 // so do not throw error and allow.
2328 return true;
2329 }
2330 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2331 }
2332
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002334 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
Wink Savilleb564aae2014-10-23 10:18:09 -07002337 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 if (DBG) log("dial: " + number);
2339 // No permission check needed here: This is just a wrapper around the
2340 // ACTION_DIAL intent, which is available to any app since it puts up
2341 // the UI before it does anything.
2342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 String url = createTelUrl(number);
2346 if (url == null) {
2347 return;
2348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350 // PENDING: should we just silently fail if phone is offhook or ringing?
2351 PhoneConstants.State state = mCM.getState(subId);
2352 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2353 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2354 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2355 mApp.startActivity(intent);
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360 }
2361
2362 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002363 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002364 }
2365
Wink Savilleb564aae2014-10-23 10:18:09 -07002366 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 if (DBG) log("call: " + number);
2368
2369 // This is just a wrapper around the ACTION_CALL intent, but we still
2370 // need to do a permission check since we're calling startActivity()
2371 // from the context of the phone app.
2372 enforceCallPermission();
2373
Jordan Liu1617b712019-07-10 15:06:26 -07002374 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 != AppOpsManager.MODE_ALLOWED) {
2376 return;
2377 }
2378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 String url = createTelUrl(number);
2382 if (url == null) {
2383 return;
2384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002386 boolean isValid = false;
2387 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2388 if (slist != null) {
2389 for (SubscriptionInfo subInfoRecord : slist) {
2390 if (subInfoRecord.getSubscriptionId() == subId) {
2391 isValid = true;
2392 break;
2393 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002394 }
Wink Saville08874612014-08-31 19:19:58 -07002395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 if (!isValid) {
2397 return;
2398 }
Wink Saville08874612014-08-31 19:19:58 -07002399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002400 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2401 intent.putExtra(SUBSCRIPTION_KEY, subId);
2402 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2403 mApp.startActivity(intent);
2404 } finally {
2405 Binder.restoreCallingIdentity(identity);
2406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 }
2408
Wink Savilleb564aae2014-10-23 10:18:09 -07002409 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002410 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002411 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2412 }
2413
Wink Savilleb564aae2014-10-23 10:18:09 -07002414 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002415 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002416 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2417 }
2418
Wink Savilleb564aae2014-10-23 10:18:09 -07002419 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421
2422 final long identity = Binder.clearCallingIdentity();
2423 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002424 Phone phone = getPhone(subId);
2425 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426 checkSimPin.start();
2427 return checkSimPin.unlockSim(null, pin);
2428 } finally {
2429 Binder.restoreCallingIdentity(identity);
2430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
Wink Savilleb564aae2014-10-23 10:18:09 -07002433 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435
2436 final long identity = Binder.clearCallingIdentity();
2437 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002438 Phone phone = getPhone(subId);
2439 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440 checkSimPuk.start();
2441 return checkSimPuk.unlockSim(puk, pin);
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
2444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
2447 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002448 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 * a synchronous one.
2450 */
2451 private static class UnlockSim extends Thread {
2452
2453 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002454 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455
2456 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002457 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2458 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459
2460 // For replies from SimCard interface
2461 private Handler mHandler;
2462
2463 // For async handler to identify request type
2464 private static final int SUPPLY_PIN_COMPLETE = 100;
2465
Michele Berionne5e411512020-11-13 02:36:59 +00002466 UnlockSim(int phoneId, IccCard simCard) {
2467 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 mSimCard = simCard;
2469 }
2470
2471 @Override
2472 public void run() {
2473 Looper.prepare();
2474 synchronized (UnlockSim.this) {
2475 mHandler = new Handler() {
2476 @Override
2477 public void handleMessage(Message msg) {
2478 AsyncResult ar = (AsyncResult) msg.obj;
2479 switch (msg.what) {
2480 case SUPPLY_PIN_COMPLETE:
2481 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2482 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002483 mRetryCount = msg.arg1;
2484 if (ar.exception != null) {
2485 if (ar.exception instanceof CommandException &&
2486 ((CommandException)(ar.exception)).getCommandError()
2487 == CommandException.Error.PASSWORD_INCORRECT) {
2488 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002489 } //When UiccCardApp dispose,handle message and return exception
2490 else if (ar.exception instanceof CommandException &&
2491 ((CommandException) (ar.exception)).getCommandError()
2492 == CommandException.Error.ABORTED) {
2493 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002494 } else {
2495 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2496 }
2497 } else {
2498 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 mDone = true;
2501 UnlockSim.this.notifyAll();
2502 }
2503 break;
2504 }
2505 }
2506 };
2507 UnlockSim.this.notifyAll();
2508 }
2509 Looper.loop();
2510 }
2511
2512 /*
2513 * Use PIN or PUK to unlock SIM card
2514 *
2515 * If PUK is null, unlock SIM card with PIN
2516 *
2517 * If PUK is not null, unlock SIM card with PUK and set PIN code
2518 */
Wink Saville9de0f752013-10-22 19:04:03 -07002519 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520
2521 while (mHandler == null) {
2522 try {
2523 wait();
2524 } catch (InterruptedException e) {
2525 Thread.currentThread().interrupt();
2526 }
2527 }
2528 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2529
2530 if (puk == null) {
2531 mSimCard.supplyPin(pin, callback);
2532 } else {
2533 mSimCard.supplyPuk(puk, pin, callback);
2534 }
2535
2536 while (!mDone) {
2537 try {
2538 Log.d(LOG_TAG, "wait for done");
2539 wait();
2540 } catch (InterruptedException e) {
2541 // Restore the interrupted status
2542 Thread.currentThread().interrupt();
2543 }
2544 }
2545 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002546 int[] resultArray = new int[2];
2547 resultArray[0] = mResult;
2548 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002549
2550 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002551 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002552 }
2553
Wink Saville9de0f752013-10-22 19:04:03 -07002554 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 }
2556 }
2557
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002558 /**
2559 * This method has been removed due to privacy and stability concerns.
2560 */
2561 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002563 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2564 return;
Wink Saville36469e72014-06-11 15:17:00 -07002565 }
2566
Nathan Harold1f889d82020-06-04 17:05:26 -07002567 @Override
2568 public void updateServiceLocationWithPackageName(String callingPackage) {
2569 mApp.getSystemService(AppOpsManager.class)
2570 .checkPackage(Binder.getCallingUid(), callingPackage);
2571
Nathan Haroldf096d982020-11-18 17:18:06 -08002572 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002573 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2574 // Callers targeting S have no business invoking this method.
2575 return;
2576 }
2577
2578 LocationAccessPolicy.LocationPermissionResult locationResult =
2579 LocationAccessPolicy.checkLocationPermission(mApp,
2580 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2581 .setCallingPackage(callingPackage)
2582 .setCallingFeatureId(null)
2583 .setCallingPid(Binder.getCallingPid())
2584 .setCallingUid(Binder.getCallingUid())
2585 .setMethod("updateServiceLocation")
2586 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2587 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2588 .build());
2589 // Apps that lack location permission have no business calling this method;
2590 // however, because no permission was declared in the public API, denials must
2591 // all be "soft".
2592 switch (locationResult) {
2593 case DENIED_HARD: /* fall through */
2594 case DENIED_SOFT:
2595 return;
2596 }
2597
2598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 final long identity = Binder.clearCallingIdentity();
2600 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002601 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002603 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002610 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002611 @Override
2612 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002613 return isRadioOnWithFeature(callingPackage, null);
2614 }
2615
2616
2617 @Override
2618 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2619 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2620 callingFeatureId);
2621 }
2622
2623 @Deprecated
2624 @Override
2625 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2626 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002627 }
2628
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002629 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002630 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2631 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002633 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002634 return false;
2635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 return isRadioOnForSubscriber(subId);
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
2642 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002643 }
2644
2645 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 final Phone phone = getPhone(subId);
2649 if (phone != null) {
2650 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2651 } else {
2652 return false;
2653 }
2654 } finally {
2655 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 }
2658
2659 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002660 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 }
Wink Saville36469e72014-06-11 15:17:00 -07002662
Wink Savilleb564aae2014-10-23 10:18:09 -07002663 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665
2666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 final Phone phone = getPhone(subId);
2669 if (phone != null) {
2670 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2671 }
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002674 }
Wink Saville36469e72014-06-11 15:17:00 -07002675 }
2676
2677 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002678 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002679 }
2680
Wink Savilleb564aae2014-10-23 10:18:09 -07002681 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 final Phone phone = getPhone(subId);
2687 if (phone == null) {
2688 return false;
2689 }
2690 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2691 toggleRadioOnOffForSubscriber(subId);
2692 }
2693 return true;
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
Wink Saville36469e72014-06-11 15:17:00 -07002698
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002699 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002700 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002701 /*
2702 * If any of the Radios are available, it will need to be
2703 * shutdown. So return true if any Radio is available.
2704 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2708 Phone phone = PhoneFactory.getPhone(i);
2709 if (phone != null && phone.isRadioAvailable()) return true;
2710 }
2711 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2712 return false;
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002715 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002716 }
2717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002719 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 enforceModifyPermission();
2721
2722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2725 logv("Shutting down Phone " + i);
2726 shutdownRadioUsingPhoneId(i);
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002730 }
2731 }
2732
2733 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002734 Phone phone = PhoneFactory.getPhone(phoneId);
2735 if (phone != null && phone.isRadioAvailable()) {
2736 phone.shutdownRadio();
2737 }
2738 }
2739
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742
2743 final long identity = Binder.clearCallingIdentity();
2744 try {
2745 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2746 if (defaultPhone != null) {
2747 defaultPhone.setRadioPower(turnOn);
2748 return true;
2749 } else {
2750 loge("There's no default phone.");
2751 return false;
2752 }
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002755 }
Wink Saville36469e72014-06-11 15:17:00 -07002756 }
2757
Wink Savilleb564aae2014-10-23 10:18:09 -07002758 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 final Phone phone = getPhone(subId);
2764 if (phone != null) {
2765 phone.setRadioPower(turnOn);
2766 return true;
2767 } else {
2768 return false;
2769 }
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002773 }
2774
Wink Saville36469e72014-06-11 15:17:00 -07002775 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 public boolean enableDataConnectivity() {
2778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779
2780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 int subId = mSubscriptionController.getDefaultDataSubId();
2783 final Phone phone = getPhone(subId);
2784 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002785 phone.getDataEnabledSettings().setDataEnabled(
2786 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 return true;
2788 } else {
2789 return false;
2790 }
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 }
2795
Wink Saville36469e72014-06-11 15:17:00 -07002796 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002797 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 public boolean disableDataConnectivity() {
2799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 int subId = mSubscriptionController.getDefaultDataSubId();
2804 final Phone phone = getPhone(subId);
2805 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002806 phone.getDataEnabledSettings().setDataEnabled(
2807 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 return true;
2809 } else {
2810 return false;
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
Sanket Padawe356d7632015-06-22 14:03:32 -07002817 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002818 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 final Phone phone = getPhone(subId);
2822 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002823 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 } else {
2825 return false;
2826 }
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
2831
2832 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002833 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002834 }
2835
pkanwarae03a6b2016-11-06 20:37:09 -08002836 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837 enforceCallPermission();
2838
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2842 return;
2843 }
2844 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2845 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
2848 }
pkanwar32d516d2016-10-14 19:37:38 -07002849 };
2850
Wink Savilleb564aae2014-10-23 10:18:09 -07002851 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2857 return false;
2858 }
2859 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002863 }
2864
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002865 /**
2866 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2867 * tag on getCallState Binder call.
2868 */
2869 @Deprecated
2870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002872 if (CompatChanges.isChangeEnabled(
2873 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2874 Binder.getCallingUid())) {
2875 // Do not allow this API to be called on API version 31+, it should only be
2876 // called on old apps using this Binder call directly.
2877 throw new SecurityException("This method can only be used for applications "
2878 + "targeting API version 30 or less.");
2879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 final long identity = Binder.clearCallingIdentity();
2881 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002882 Phone phone = getPhone(getDefaultSubscription());
2883 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2884 PhoneConstantConversions.convertCallState(phone.getState());
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
2888 }
2889
2890 @Override
2891 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2892 if (CompatChanges.isChangeEnabled(
2893 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2894 Binder.getCallingUid())) {
2895 // Check READ_PHONE_STATE for API version 31+
2896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2897 featureId, "getCallStateForSubscription")) {
2898 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2899 + "targeting API level 31+.");
2900 }
2901 }
2902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2906 PhoneConstantConversions.convertCallState(phone.getState());
2907 } finally {
2908 Binder.restoreCallingIdentity(identity);
2909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
2911
Sanket Padawe356d7632015-06-22 14:03:32 -07002912 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002913 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002914 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2915 }
2916
2917 @Override
2918 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 final long identity = Binder.clearCallingIdentity();
2920 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002921 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 if (phone != null) {
Jack Yu4accbd92021-11-29 11:36:17 -08002923 if (phone.isUsingNewDataStack()) {
2924 return phone.getDataNetworkController().getInternetDataNetworkState();
2925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2927 } else {
2928 return PhoneConstantConversions.convertDataState(
2929 PhoneConstants.DataState.DISCONNECTED);
2930 }
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 }
2935
Sanket Padawe356d7632015-06-22 14:03:32 -07002936 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002937 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002938 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2939 }
2940
2941 @Override
2942 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 final long identity = Binder.clearCallingIdentity();
2944 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002945 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 if (phone != null) {
2947 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2948 } else {
2949 return TelephonyManager.DATA_ACTIVITY_NONE;
2950 }
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 }
2955
2956 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002957 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002958 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002959 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002960
2961 LocationAccessPolicy.LocationPermissionResult locationResult =
2962 LocationAccessPolicy.checkLocationPermission(mApp,
2963 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2964 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002965 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002966 .setCallingPid(Binder.getCallingPid())
2967 .setCallingUid(Binder.getCallingUid())
2968 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002969 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002970 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2971 .build());
2972 switch (locationResult) {
2973 case DENIED_HARD:
2974 throw new SecurityException("Not allowed to access cell location");
2975 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002976 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2977 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002978 }
2979
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002980 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002984 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002985 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
Svetoslav64fad262015-04-14 14:35:21 -07002989 }
2990
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002992 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002993 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2994 // registered cell info, so return a NULL country instead.
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002997 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2998 // Get default phone in this case.
2999 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3000 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003001 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003003 if (phone == null) return "";
3004 ServiceStateTracker sst = phone.getServiceStateTracker();
3005 if (sst == null) return "";
3006 LocaleTracker lt = sst.getLocaleTracker();
3007 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003008 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003012 }
3013
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003014 /**
3015 * This method was removed due to potential issues caused by performing partial
3016 * updates of service state, and lack of a credible use case.
3017 *
3018 * This has the ability to break the telephony implementation by disabling notification of
3019 * changes in device connectivity. DO NOT USE THIS!
3020 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003021 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003022 public void enableLocationUpdates() {
3023 mApp.enforceCallingOrSelfPermission(
3024 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003025 }
3026
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003027 /**
3028 * This method was removed due to potential issues caused by performing partial
3029 * updates of service state, and lack of a credible use case.
3030 *
3031 * This has the ability to break the telephony implementation by disabling notification of
3032 * changes in device connectivity. DO NOT USE THIS!
3033 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003034 @Override
3035 public void disableLocationUpdates() {
3036 mApp.enforceCallingOrSelfPermission(
3037 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003038 }
3039
3040 @Override
3041 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003042 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3043 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003044 try {
3045 mApp.getSystemService(AppOpsManager.class)
3046 .checkPackage(Binder.getCallingUid(), callingPackage);
3047 } catch (SecurityException e) {
3048 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3049 throw e;
3050 }
3051
Nathan Haroldf096d982020-11-18 17:18:06 -08003052 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003053 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3054 throw new SecurityException(
3055 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3056 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003057
Jordan Liu1617b712019-07-10 15:06:26 -07003058 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3060 return null;
3061 }
Svetoslav64fad262015-04-14 14:35:21 -07003062
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003063 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003065 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003066 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067
Nathan Haroldf180aac2018-06-01 18:43:55 -07003068 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3069 for (CellInfo ci : info) {
3070 if (ci instanceof CellInfoGsm) {
3071 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3072 } else if (ci instanceof CellInfoWcdma) {
3073 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003076 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003077 }
3078
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003079 private List<CellInfo> getCachedCellInfo() {
3080 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3081 for (Phone phone : PhoneFactory.getPhones()) {
3082 List<CellInfo> info = phone.getAllCellInfo();
3083 if (info != null) cellInfos.addAll(info);
3084 }
3085 return cellInfos;
3086 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003087
3088 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003089 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003090 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003091 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003092
3093 LocationAccessPolicy.LocationPermissionResult locationResult =
3094 LocationAccessPolicy.checkLocationPermission(mApp,
3095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3096 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003097 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003098 .setCallingPid(Binder.getCallingPid())
3099 .setCallingUid(Binder.getCallingUid())
3100 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003101 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003102 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3103 .build());
3104 switch (locationResult) {
3105 case DENIED_HARD:
3106 throw new SecurityException("Not allowed to access cell info");
3107 case DENIED_SOFT:
3108 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003109 }
3110
Nathan Haroldf096d982020-11-18 17:18:06 -08003111 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003112 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3113 return getCachedCellInfo();
3114 }
3115
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003116 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003117 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3121 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003122 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003123 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124 if (info != null) cellInfos.addAll(info);
3125 }
3126 return cellInfos;
3127 } finally {
3128 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 }
3130 }
3131
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003132 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003133 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3134 String callingFeatureId) {
3135 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3136 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003137 }
3138
3139 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003140 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3141 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003142 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003143 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003144 }
3145
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003146 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3147 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003148 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003149 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003150
3151 LocationAccessPolicy.LocationPermissionResult locationResult =
3152 LocationAccessPolicy.checkLocationPermission(mApp,
3153 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3154 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003155 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003156 .setCallingPid(Binder.getCallingPid())
3157 .setCallingUid(Binder.getCallingUid())
3158 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003159 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3160 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003161 .build());
3162 switch (locationResult) {
3163 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003164 if (TelephonyPermissions
3165 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003166 // Safetynet logging for b/154934934
3167 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3168 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003169 throw new SecurityException("Not allowed to access cell info");
3170 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003171 if (TelephonyPermissions
3172 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003173 // Safetynet logging for b/154934934
3174 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3175 }
Nathan Harold5320c422019-05-09 10:26:08 -07003176 try {
3177 cb.onCellInfo(new ArrayList<CellInfo>());
3178 } catch (RemoteException re) {
3179 // Drop without consequences
3180 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003181 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003182 }
3183
Nathan Harolda939a962019-05-09 10:13:47 -07003184
3185 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003186 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3187
3188 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3189 }
3190
3191 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003193 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003194 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195
3196 final long identity = Binder.clearCallingIdentity();
3197 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003198 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 } finally {
3200 Binder.restoreCallingIdentity(identity);
3201 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003202 }
3203
Shishir Agrawala9f32182016-04-12 12:00:16 -07003204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003205 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003206 Phone phone = PhoneFactory.getPhone(slotIndex);
3207 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003208 return null;
3209 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003210 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003211 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003212 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003213 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003214 return null;
3215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 return phone.getImei();
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003223 }
3224
3225 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003226 public String getTypeAllocationCodeForSlot(int slotIndex) {
3227 Phone phone = PhoneFactory.getPhone(slotIndex);
3228 String tac = null;
3229 if (phone != null) {
3230 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003231 try {
3232 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3233 } catch (IndexOutOfBoundsException e) {
3234 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3235 return null;
3236 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003237 }
3238 return tac;
3239 }
3240
3241 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003242 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003243 try {
3244 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3245 } catch (SecurityException se) {
3246 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3247 throw new SecurityException("Package " + callingPackage + " does not belong to "
3248 + Binder.getCallingUid());
3249 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003250 Phone phone = PhoneFactory.getPhone(slotIndex);
3251 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003252 return null;
3253 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003254
Jeff Davidson913390f2018-02-23 17:11:49 -08003255 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003256 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003257 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003258 return null;
3259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260
3261 final long identity = Binder.clearCallingIdentity();
3262 try {
3263 return phone.getMeid();
3264 } finally {
3265 Binder.restoreCallingIdentity(identity);
3266 }
Jack Yu2af8d712017-03-15 17:14:14 -07003267 }
3268
3269 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003270 public String getManufacturerCodeForSlot(int slotIndex) {
3271 Phone phone = PhoneFactory.getPhone(slotIndex);
3272 String manufacturerCode = null;
3273 if (phone != null) {
3274 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003275 try {
3276 manufacturerCode =
3277 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3278 } catch (IndexOutOfBoundsException e) {
3279 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3280 return null;
3281 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003282 }
3283 return manufacturerCode;
3284 }
3285
3286 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003287 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3288 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003289 Phone phone = PhoneFactory.getPhone(slotIndex);
3290 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003291 return null;
3292 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003293 int subId = phone.getSubId();
3294 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003295 mApp, subId, callingPackage, callingFeatureId,
3296 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003297 return null;
3298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299
3300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 return phone.getDeviceSvn();
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003306 }
3307
fionaxu43304da2017-11-27 22:51:16 -08003308 @Override
3309 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 final Phone phone = getPhone(subId);
3313 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
fionaxu43304da2017-11-27 22:51:16 -08003317 }
3318
3319 @Override
3320 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 final Phone phone = getPhone(subId);
3324 return phone == null ? null : phone.getCarrierName();
3325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
fionaxu43304da2017-11-27 22:51:16 -08003328 }
3329
calvinpanffe225e2018-11-01 19:43:06 +08003330 @Override
chen xu0026ca62019-03-06 15:28:50 -08003331 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 final Phone phone = getPhone(subId);
3335 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003336 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
3340 }
3341
3342 @Override
chen xu0026ca62019-03-06 15:28:50 -08003343 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003347 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003348 } finally {
3349 Binder.restoreCallingIdentity(identity);
3350 }
3351 }
3352
chen xu651eec72018-11-11 19:03:44 -08003353 @Override
chen xu864e11c2018-12-06 22:10:03 -08003354 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3355 if (!isSubscriptionMccMnc) {
3356 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3357 }
chen xu651eec72018-11-11 19:03:44 -08003358 final Phone phone = PhoneFactory.getPhone(slotIndex);
3359 if (phone == null) {
3360 return TelephonyManager.UNKNOWN_CARRIER_ID;
3361 }
3362 final long identity = Binder.clearCallingIdentity();
3363 try {
3364 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
3368 }
3369
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003370 //
3371 // Internal helper methods.
3372 //
3373
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003374 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003375 * Make sure the caller is the calling package itself
3376 *
3377 * @throws SecurityException if the caller is not the calling package
3378 */
3379 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3380 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003381 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3382 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003383 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003384 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003385 } catch (PackageManager.NameNotFoundException e) {
3386 // packageUid is -1
3387 }
3388 if (packageUid != callingUid) {
3389 throw new SecurityException(message + ": Package " + callingPackage
3390 + " does not belong to " + callingUid);
3391 }
3392 }
3393
3394 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003395 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3396 *
3397 * @throws SecurityException if the caller does not have the required permission
3398 */
3399 private void enforceModifyPermission() {
3400 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3401 }
3402
Shuo Qian3b6ee772019-11-13 17:43:31 -08003403 private void enforceActiveEmergencySessionPermission() {
3404 mApp.enforceCallingOrSelfPermission(
3405 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3406 }
3407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003408 /**
3409 * Make sure the caller has the CALL_PHONE permission.
3410 *
3411 * @throws SecurityException if the caller does not have the required permission
3412 */
3413 private void enforceCallPermission() {
3414 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3415 }
3416
paulhu5a773602019-08-23 19:17:33 +08003417 private void enforceSettingsPermission() {
3418 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003419 }
3420
Michele Berionne5e411512020-11-13 02:36:59 +00003421 private void enforceRebootPermission() {
3422 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3423 }
3424
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003425 private String createTelUrl(String number) {
3426 if (TextUtils.isEmpty(number)) {
3427 return null;
3428 }
3429
Jake Hambye994d462014-02-03 13:10:13 -08003430 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 }
3432
Ihab Awadf9e92732013-12-05 18:02:52 -08003433 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003434 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3435 }
3436
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003437 private static void logv(String msg) {
3438 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3439 }
3440
Ihab Awadf9e92732013-12-05 18:02:52 -08003441 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003442 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3443 }
3444
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003445 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003446 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003447 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003448 }
3449
Sanket Padawe356d7632015-06-22 14:03:32 -07003450 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003451 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452 final long identity = Binder.clearCallingIdentity();
3453 try {
3454 final Phone phone = PhoneFactory.getPhone(slotIndex);
3455 if (phone == null) {
3456 return PhoneConstants.PHONE_TYPE_NONE;
3457 } else {
3458 return phone.getPhoneType();
3459 }
3460 } finally {
3461 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 }
3464
3465 /**
3466 * Returns the CDMA ERI icon index to display
3467 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003468 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003469 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3470 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3471 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003472 }
3473
Sanket Padawe356d7632015-06-22 14:03:32 -07003474 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003475 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3476 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003478 mApp, subId, callingPackage, callingFeatureId,
3479 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003480 return -1;
3481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003482
3483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 final Phone phone = getPhone(subId);
3486 if (phone != null) {
3487 return phone.getCdmaEriIconIndex();
3488 } else {
3489 return -1;
3490 }
3491 } finally {
3492 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003494 }
3495
3496 /**
3497 * Returns the CDMA ERI icon mode,
3498 * 0 - ON
3499 * 1 - FLASHING
3500 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003501 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003502 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3503 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3504 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003505 }
3506
Sanket Padawe356d7632015-06-22 14:03:32 -07003507 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003508 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3509 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003511 mApp, subId, callingPackage, callingFeatureId,
3512 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003513 return -1;
3514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 final Phone phone = getPhone(subId);
3519 if (phone != null) {
3520 return phone.getCdmaEriIconMode();
3521 } else {
3522 return -1;
3523 }
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003527 }
3528
3529 /**
3530 * Returns the CDMA ERI text,
3531 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003533 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3534 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3535 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003536 }
3537
Sanket Padawe356d7632015-06-22 14:03:32 -07003538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003539 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3540 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003542 mApp, subId, callingPackage, callingFeatureId,
3543 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003544 return null;
3545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 final Phone phone = getPhone(subId);
3550 if (phone != null) {
3551 return phone.getCdmaEriText();
3552 } else {
3553 return null;
3554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003558 }
3559
3560 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003561 * Returns the CDMA MDN.
3562 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003563 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003564 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3566 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567
3568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003571 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572 return phone.getLine1Number();
3573 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575 return null;
3576 }
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003579 }
3580 }
3581
3582 /**
3583 * Returns the CDMA MIN.
3584 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003585 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003586 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3588 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589
3590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 final Phone phone = getPhone(subId);
3593 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3594 return phone.getCdmaMin();
3595 } else {
3596 return null;
3597 }
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003600 }
3601 }
3602
Hall Liud892bec2018-11-30 14:51:45 -08003603 @Override
3604 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3605 INumberVerificationCallback callback, String callingPackage) {
3606 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3607 != PERMISSION_GRANTED) {
3608 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3609 }
3610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3611
3612 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3613 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003614 throw new SecurityException("Calling package must be configured in the device config: "
3615 + "calling package: " + callingPackage
3616 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003617 }
3618
3619 if (range == null) {
3620 throw new NullPointerException("Range must be non-null");
3621 }
3622
3623 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003624 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003625
3626 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3627 }
3628
Junda Liuca05d5d2014-08-14 22:36:34 -07003629 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003630 * Returns true if CDMA provisioning needs to run.
3631 */
3632 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633 final long identity = Binder.clearCallingIdentity();
3634 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003635 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003636 } finally {
3637 Binder.restoreCallingIdentity(identity);
3638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003639 }
3640
3641 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003642 * Sets the voice mail number of a given subId.
3643 */
3644 @Override
3645 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003646 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3647 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3652 new Pair<String, String>(alphaTag, number), new Integer(subId));
3653 return success;
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003657 }
3658
Ta-wei Yen87c49842016-05-13 21:19:52 -07003659 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003660 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003662 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3663 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003664 if (!TextUtils.equals(callingPackage, systemDialer)) {
3665 throw new SecurityException("caller must be system dialer");
3666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3671 if (phoneAccountHandle == null) {
3672 return null;
3673 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003674 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675 } finally {
3676 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003677 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003678 }
3679
3680 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003681 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3682 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003685 mApp, subId, callingPackage, callingFeatureId,
3686 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003687 return null;
3688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003690 final long identity = Binder.clearCallingIdentity();
3691 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003696 }
3697
3698 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003699 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3700 VisualVoicemailSmsFilterSettings settings) {
3701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003710 }
3711
3712 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003713 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003719 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003723 }
3724
3725 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003726 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3727 String callingPackage, int subId) {
3728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729
3730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003737 }
3738
3739 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003740 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003741 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003746 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003750 }
3751
3752 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003753 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3754 String callingAttributionTag, int subId, String number, int port, String text,
3755 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003756 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003757 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003758 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003759 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003760 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3761 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003762 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003763
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003764 /**
fionaxu0152e512016-11-14 13:36:14 -08003765 * Sets the voice activation state of a given subId.
3766 */
3767 @Override
3768 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3770 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003771
3772 final long identity = Binder.clearCallingIdentity();
3773 try {
3774 final Phone phone = getPhone(subId);
3775 if (phone != null) {
3776 phone.setVoiceActivationState(activationState);
3777 } else {
3778 loge("setVoiceActivationState fails with invalid subId: " + subId);
3779 }
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003782 }
3783 }
3784
3785 /**
3786 * Sets the data activation state of a given subId.
3787 */
3788 @Override
3789 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3791 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
3793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 final Phone phone = getPhone(subId);
3796 if (phone != null) {
3797 phone.setDataActivationState(activationState);
3798 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003799 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003803 }
3804 }
3805
3806 /**
3807 * Returns the voice activation state of a given subId.
3808 */
3809 @Override
3810 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003811 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
fionaxu0152e512016-11-14 13:36:14 -08003813 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 if (phone != null) {
3817 return phone.getVoiceActivationState();
3818 } else {
3819 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3820 }
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003823 }
3824 }
3825
3826 /**
3827 * Returns the data activation state of a given subId.
3828 */
3829 @Override
3830 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832
fionaxu0152e512016-11-14 13:36:14 -08003833 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 if (phone != null) {
3837 return phone.getDataActivationState();
3838 } else {
3839 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003843 }
3844 }
3845
3846 /**
Wink Saville36469e72014-06-11 15:17:00 -07003847 * Returns the unread count of voicemails for a subId
3848 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003850 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3851 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003853 mApp, subId, callingPackage, callingFeatureId,
3854 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003855 return 0;
3856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 final Phone phone = getPhone(subId);
3860 if (phone != null) {
3861 return phone.getVoiceMessageCount();
3862 } else {
3863 return 0;
3864 }
3865 } finally {
3866 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003868 }
3869
3870 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003871 * returns true, if the device is in a state where both voice and data
3872 * are supported simultaneously. This can change based on location or network condition.
3873 */
3874 @Override
3875 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = getPhone(subId);
3879 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
3882 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003883 }
3884
3885 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003886 * Send the dialer code if called from the current default dialer or the caller has
3887 * carrier privilege.
3888 * @param inputCode The dialer code to send
3889 */
3890 @Override
3891 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003892 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003893 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003894 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3895 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003896 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003897 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003898 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003900
3901 final long identity = Binder.clearCallingIdentity();
3902 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003903 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 } finally {
3905 Binder.restoreCallingIdentity(identity);
3906 }
fionaxu235cc5e2017-03-06 22:25:57 -08003907 }
3908
Pengquan Menga1bb6272018-09-06 09:59:22 -07003909 @Override
3910 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003911 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003912 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003913 mApp, subId, "getNetworkSelectionMode");
3914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 if (!isActiveSubscription(subId)) {
3917 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3918 }
3919 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3920 } finally {
3921 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003922 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003923 }
3924
Brad Ebinger35c841c2018-10-01 10:40:55 -07003925 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003926 public boolean isInEmergencySmsMode() {
3927 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 for (Phone phone : PhoneFactory.getPhones()) {
3931 if (phone.isInEmergencySmsMode()) {
3932 return true;
3933 }
3934 }
3935 } finally {
3936 Binder.restoreCallingIdentity(identity);
3937 }
3938 return false;
3939 }
3940
shilu366312e2019-12-17 09:28:10 -08003941 /**
3942 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3943 * @param subId The subscription to use to check the configuration.
3944 * @param c The callback that will be used to send the result.
3945 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003946 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003947 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3948 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003949 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003950 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003951
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003952 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3953 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3954 "IMS not available on device.");
3955 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 final long token = Binder.clearCallingIdentity();
3957 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003958 int slotId = getSlotIndexOrException(subId);
3959 verifyImsMmTelConfiguredOrThrow(slotId);
3960 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003961 } catch (ImsException e) {
3962 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003963 } finally {
3964 Binder.restoreCallingIdentity(token);
3965 }
3966 }
3967
shilu366312e2019-12-17 09:28:10 -08003968 /**
3969 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3970 * @param subId The subscription to use to check the configuration.
3971 * @param c The callback that will be used to send the result.
3972 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003974 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003975 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003976 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003977 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3978 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3979 }
Meng Wangafbc5852019-09-19 17:37:13 -07003980 final long token = Binder.clearCallingIdentity();
3981 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003982 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3983 .removeRegistrationCallbackForSubscription(c, subId);
3984 } catch (ImsException e) {
3985 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3986 + "is inactive, ignoring unregister.");
3987 // If the subscription is no longer active, just return, since the callback
3988 // will already have been removed internally.
3989 } finally {
3990 Binder.restoreCallingIdentity(token);
3991 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 }
3993
Brad Ebingera34a6c22019-10-22 17:36:18 -07003994 /**
3995 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3996 */
3997 @Override
3998 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3999 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4000 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4001 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4002 "IMS not available on device.");
4003 }
4004 final long token = Binder.clearCallingIdentity();
4005 try {
4006 Phone phone = getPhone(subId);
4007 if (phone == null) {
4008 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4009 + subId + "'");
4010 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4011 }
4012 phone.getImsRegistrationState(regState -> {
4013 try {
4014 consumer.accept((regState == null)
4015 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4016 } catch (RemoteException e) {
4017 // Ignore if the remote process is no longer available to call back.
4018 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4019 }
4020 });
4021 } finally {
4022 Binder.restoreCallingIdentity(token);
4023 }
4024 }
4025
4026 /**
4027 * Get the transport type for the IMS service registration state.
4028 */
4029 @Override
4030 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004031 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004032 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004033 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4034 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4035 "IMS not available on device.");
4036 }
4037 final long token = Binder.clearCallingIdentity();
4038 try {
4039 Phone phone = getPhone(subId);
4040 if (phone == null) {
4041 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4042 + subId + "'");
4043 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4044 }
4045 phone.getImsRegistrationTech(regTech -> {
4046 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4047 int regTechConverted = (regTech == null)
4048 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4049 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4050 regTechConverted);
4051 try {
4052 consumer.accept(regTechConverted);
4053 } catch (RemoteException e) {
4054 // Ignore if the remote process is no longer available to call back.
4055 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4056 }
4057 });
4058 } finally {
4059 Binder.restoreCallingIdentity(token);
4060 }
4061 }
4062
shilu366312e2019-12-17 09:28:10 -08004063 /**
4064 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4065 * @param subId The subscription to use to check the configuration.
4066 * @param c The callback that will be used to send the result.
4067 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004069 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4070 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004071 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004072 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004073 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4074 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4075 "IMS not available on device.");
4076 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 final long token = Binder.clearCallingIdentity();
4078 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004079 int slotId = getSlotIndexOrException(subId);
4080 verifyImsMmTelConfiguredOrThrow(slotId);
4081 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004082 } catch (ImsException e) {
4083 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 } finally {
4085 Binder.restoreCallingIdentity(token);
4086 }
4087 }
4088
shilu366312e2019-12-17 09:28:10 -08004089 /**
4090 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4091 * @param subId The subscription to use to check the configuration.
4092 * @param c The callback that will be used to send the result.
4093 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004095 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004096 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004097 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004098 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4099 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4100 }
Meng Wangafbc5852019-09-19 17:37:13 -07004101
4102 final long token = Binder.clearCallingIdentity();
4103 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004104 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004105 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004106 } catch (ImsException e) {
4107 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4108 + "is inactive, ignoring unregister.");
4109 // If the subscription is no longer active, just return, since the callback
4110 // will already have been removed internally.
4111 } finally {
4112 Binder.restoreCallingIdentity(token);
4113 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 }
4115
4116 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004117 public boolean isCapable(int subId, int capability, int regTech) {
4118 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 final long token = Binder.clearCallingIdentity();
4120 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004121 int slotId = getSlotIndexOrException(subId);
4122 verifyImsMmTelConfiguredOrThrow(slotId);
4123 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4126 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004127 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004128 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4129 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 } finally {
4131 Binder.restoreCallingIdentity(token);
4132 }
4133 }
4134
4135 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004136 public boolean isAvailable(int subId, int capability, int regTech) {
4137 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 final long token = Binder.clearCallingIdentity();
4139 try {
4140 Phone phone = getPhone(subId);
4141 if (phone == null) return false;
4142 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004143 } catch (com.android.ims.ImsException e) {
4144 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4145 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 } finally {
4147 Binder.restoreCallingIdentity(token);
4148 }
4149 }
4150
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004151 /**
4152 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4153 * subscription.
4154 * @param subId The subscription to use to check the configuration.
4155 * @param callback The callback that will be used to send the result.
4156 * @param capability The MmTelFeature capability that will be used to send the result.
4157 * @param transportType The transport type of the MmTelFeature capability.
4158 */
4159 @Override
4160 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4161 int transportType) {
4162 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4163 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4164 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4165 "IMS not available on device.");
4166 }
4167 final long token = Binder.clearCallingIdentity();
4168 try {
4169 int slotId = getSlotIndex(subId);
4170 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4171 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4172 + subId + "'");
4173 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4174 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004175 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004176 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4177 transportType, aBoolean -> {
4178 try {
4179 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4180 } catch (RemoteException e) {
4181 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4182 + "running. Ignore");
4183 }
4184 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004185 } catch (ImsException e) {
4186 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004187 } finally {
4188 Binder.restoreCallingIdentity(token);
4189 }
4190 }
4191
shilu366312e2019-12-17 09:28:10 -08004192 /**
4193 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4194 * @param subId The subscription to use to check the configuration.
4195 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 @Override
4197 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004198 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004199 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004200
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 final long token = Binder.clearCallingIdentity();
4202 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004203 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004204 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004205 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004206 } catch (ImsException e) {
4207 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 } finally {
4209 Binder.restoreCallingIdentity(token);
4210 }
4211 }
4212
4213 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004214 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004216 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 final long identity = Binder.clearCallingIdentity();
4218 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004219 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004220 // This setting doesn't require an active ImsService connection, so do not verify. The
4221 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004222 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 } catch (ImsException e) {
4224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
4228 }
4229
shilu366312e2019-12-17 09:28:10 -08004230 /**
4231 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4232 * @param subId The subscription to use to check the configuration.
4233 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004235 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004236 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004237 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 final long identity = Binder.clearCallingIdentity();
4239 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004240 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004241 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004242 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004243 } catch (ImsException e) {
4244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
4248 }
4249
4250 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004251 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004253 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004254 final long identity = Binder.clearCallingIdentity();
4255 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004256 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004257 // This setting doesn't require an active ImsService connection, so do not verify. The
4258 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004260 } catch (ImsException e) {
4261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
4265 }
4266
shilu366312e2019-12-17 09:28:10 -08004267 /**
4268 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4269 * @param subId The subscription to use to check the configuration.
4270 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 @Override
4272 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004273 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004274 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 final long identity = Binder.clearCallingIdentity();
4276 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004277 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004278 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004280 } catch (ImsException e) {
4281 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
4285 }
4286
4287 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004288 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004290 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 final long identity = Binder.clearCallingIdentity();
4292 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004293 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004294 // This setting doesn't require an active ImsService connection, so do not verify. The
4295 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004297 } catch (ImsException e) {
4298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
4302 }
4303
shilu366312e2019-12-17 09:28:10 -08004304 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004305 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4306 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4307 * @param subId The subscription to use to check the configuration.
4308 */
4309 @Override
4310 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004311 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004312 mApp, subId, "isCrossSimCallingEnabledByUser");
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004315 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004316 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004317 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004318 } catch (ImsException e) {
4319 throw new ServiceSpecificException(e.getCode());
4320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
4325 /**
4326 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4327 * Requires MODIFY_PHONE_STATE permission.
4328 * @param subId The subscription to use to check the configuration.
4329 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4330 * false otherwise
4331 */
4332 @Override
4333 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4335 "setCrossSimCallingEnabled");
4336 final long identity = Binder.clearCallingIdentity();
4337 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004339 // This setting doesn't require an active ImsService connection, so do not verify. The
4340 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004341 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004342 } catch (ImsException e) {
4343 throw new ServiceSpecificException(e.getCode());
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
4346 }
4347 }
4348
4349 /**
shilu366312e2019-12-17 09:28:10 -08004350 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4351 * @param subId The subscription to use to check the configuration.
4352 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004353 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004354
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004356 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004357 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 final long identity = Binder.clearCallingIdentity();
4359 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004361 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004362 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004363 } catch (ImsException e) {
4364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
4368 }
4369
4370 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004371 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004373 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 final long identity = Binder.clearCallingIdentity();
4375 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004377 // This setting doesn't require an active ImsService connection, so do not verify. The
4378 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (ImsException e) {
4381 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
4385 }
4386
4387 @Override
4388 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4390 "setVoWiFiNonPersistent");
4391 final long identity = Binder.clearCallingIdentity();
4392 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004394 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004396 } catch (ImsException e) {
4397 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
4401 }
4402
shilu366312e2019-12-17 09:28:10 -08004403 /**
4404 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4405 * @param subId The subscription to use to check the configuration.
4406 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004407 @Override
4408 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004409 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004410 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004411 final long identity = Binder.clearCallingIdentity();
4412 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004413 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004414 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004415 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004416 } catch (ImsException e) {
4417 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004418 } finally {
4419 Binder.restoreCallingIdentity(identity);
4420 }
4421 }
4422
4423 @Override
4424 public void setVoWiFiModeSetting(int subId, int mode) {
4425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4426 "setVoWiFiModeSetting");
4427 final long identity = Binder.clearCallingIdentity();
4428 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004429 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004430 // This setting doesn't require an active ImsService connection, so do not verify. The
4431 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004432 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004433 } catch (ImsException e) {
4434 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
4438 }
4439
4440 @Override
4441 public int getVoWiFiRoamingModeSetting(int subId) {
4442 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4443 final long identity = Binder.clearCallingIdentity();
4444 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004446 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004447 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004448 } catch (ImsException e) {
4449 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
4453 }
4454
4455 @Override
4456 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4458 "setVoWiFiRoamingModeSetting");
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004462 // This setting doesn't require an active ImsService connection, so do not verify. The
4463 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004465 } catch (ImsException e) {
4466 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 } finally {
4468 Binder.restoreCallingIdentity(identity);
4469 }
4470 }
4471
4472 @Override
4473 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4475 "setRttCapabilityEnabled");
4476 final long identity = Binder.clearCallingIdentity();
4477 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004479 // This setting doesn't require an active ImsService connection, so do not verify. The
4480 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004482 } catch (ImsException e) {
4483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
4487 }
4488
shilu366312e2019-12-17 09:28:10 -08004489 /**
4490 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4491 * @param subId The subscription to use to check the configuration.
4492 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 @Override
4494 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004495 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004496 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 final long identity = Binder.clearCallingIdentity();
4498 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004499 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004500 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004501 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004502 } catch (ImsException e) {
4503 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
4507 }
4508
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004509 @Override
4510 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4511 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4512 final long identity = Binder.clearCallingIdentity();
4513 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004514 if (!isImsAvailableOnDevice()) {
4515 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4516 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004517 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 int slotId = getSlotIndexOrException(subId);
4519 verifyImsMmTelConfiguredOrThrow(slotId);
4520 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004521 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004522 } catch (ImsException e) {
4523 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 }
4528
4529 @Override
4530 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4531 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4532 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004533 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4534 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4535 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004536 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004537 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004538 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004539 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004540 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4541 + "is inactive, ignoring unregister.");
4542 // If the subscription is no longer active, just return, since the callback will already
4543 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004544 } finally {
4545 Binder.restoreCallingIdentity(identity);
4546 }
4547 }
4548
allenwtsu99c623b2020-01-03 18:24:23 +08004549
4550 private void checkModifyPhoneStatePermission(int subId, String message) {
4551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4552 message);
4553 }
4554
4555 private boolean isImsProvisioningRequired(int subId, int capability,
4556 boolean isMmtelCapability) {
4557 Phone phone = getPhone(subId);
4558 if (phone == null) {
4559 loge("phone instance null for subid " + subId);
4560 return false;
4561 }
4562 if (isMmtelCapability) {
4563 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4564 return false;
4565 }
4566 } else {
4567 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4568 return false;
4569 }
4570 }
4571 return true;
4572 }
4573
4574 @Override
4575 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4576 boolean isProvisioned) {
4577 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4578
4579 final long identity = Binder.clearCallingIdentity();
4580 try {
4581 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4582 if (!isImsProvisioningRequired(subId, capability, false)) {
4583 return;
4584 }
4585
4586 // this capability requires provisioning, route to the correct API.
4587 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4588 switch (capability) {
4589 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4590 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4591 ims.setEabProvisioned(isProvisioned);
4592 break;
4593 default: {
4594 throw new IllegalArgumentException("Tried to set provisioning for "
4595 + "rcs capability '" + capability + "', which does not require "
4596 + "provisioning.");
4597 }
4598 }
4599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
4602
4603 }
4604
4605
4606 @Override
4607 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4608 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4609 final long identity = Binder.clearCallingIdentity();
4610 try {
4611 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4612 if (!isImsProvisioningRequired(subId, capability, false)) {
4613 return true;
4614 }
4615
4616 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4617 switch (capability) {
4618 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4619 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4620 return ims.isEabProvisionedOnDevice();
4621
4622 default: {
4623 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4624 + "capability '" + capability + "', which does not require "
4625 + "provisioning.");
4626 }
4627 }
4628
4629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
4632 }
4633
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004634 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004635 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4636 boolean isProvisioned) {
4637 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004638 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4639 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4640 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004641 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4642 }
allenwtsu99c623b2020-01-03 18:24:23 +08004643 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004644 final long identity = Binder.clearCallingIdentity();
4645 try {
4646 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004647 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004648 return;
4649 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004650 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4651 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4652 loge("setImsProvisioningStatusForCapability: called for technology that does "
4653 + "not support provisioning - " + tech);
4654 return;
4655 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004656
4657 // this capability requires provisioning, route to the correct API.
4658 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4659 switch (capability) {
4660 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4661 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4662 ims.setVolteProvisioned(isProvisioned);
4663 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4664 ims.setWfcProvisioned(isProvisioned);
4665 }
4666 break;
4667 }
4668 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4669 // There is currently no difference in VT provisioning type.
4670 ims.setVtProvisioned(isProvisioned);
4671 break;
4672 }
4673 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4674 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4675 // change the capability of the feature instead if needed.
4676 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4677 == isProvisioned) {
4678 // No change in provisioning.
4679 return;
4680 }
4681 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4682 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004683 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004684 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004685 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4686 + ", Exception" + e.getMessage());
4687 }
4688 break;
4689 }
4690 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004691 throw new IllegalArgumentException("Tried to set provisioning for "
4692 + "MmTel capability '" + capability + "', which does not require "
4693 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004694 }
4695 }
4696
4697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
4700 }
4701
4702 @Override
4703 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4704 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004705 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4706 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4707 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4709 }
4710 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4711 final long identity = Binder.clearCallingIdentity();
4712 try {
4713 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004714 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004715 return true;
4716 }
4717
Brad Ebinger0d79c572021-04-17 15:20:49 -07004718 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4719 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4720 loge("getImsProvisioningStatusForCapability: called for technology that does "
4721 + "not support provisioning - " + tech);
4722 return true;
4723 }
4724
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004725 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4726 switch (capability) {
4727 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4728 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4729 return ims.isVolteProvisionedOnDevice();
4730 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4731 return ims.isWfcProvisionedOnDevice();
4732 }
4733 // This should never happen, since we are checking tech above to make sure it
4734 // is either LTE or IWLAN.
4735 throw new IllegalArgumentException("Invalid radio technology for voice "
4736 + "capability.");
4737 }
4738 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4739 // There is currently no difference in VT provisioning type.
4740 return ims.isVtProvisionedOnDevice();
4741 }
4742 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4743 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4744 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4745 }
4746 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004747 throw new IllegalArgumentException(
4748 "Tried to get provisioning for MmTel capability '" + capability
4749 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004750 }
4751 }
4752
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
4755 }
4756 }
4757
4758 @Override
4759 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4760 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4761 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4762 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4763 }
4764 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4765 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4766 return (provisionedBits & capability) > 0;
4767 }
4768
4769 @Override
4770 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4771 boolean isProvisioned) {
4772 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4773 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4774 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4775 }
4776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4777 "setProvisioningStatusForCapability");
4778 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4779 // If the current provisioning status for capability already matches isProvisioned,
4780 // do nothing.
4781 if (((provisionedBits & capability) > 0) == isProvisioned) {
4782 return;
4783 }
4784 if (isProvisioned) {
4785 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4786 } else {
4787 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4788 }
4789 }
4790
4791 /**
4792 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4793 * technology. The bitfield should mirror the bitfield defined by
4794 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4795 */
4796 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4797 String key = getMmTelProvisioningKey(subId, tech);
4798 // Default is no capabilities are provisioned.
4799 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4800 }
4801
4802 /**
4803 * Sets the MmTel capability provisioning bitfield (defined by
4804 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4805 * technology specified.
4806 *
4807 * Note: This is a synchronous command and should not be called on UI thread.
4808 */
4809 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4810 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4811 String key = getMmTelProvisioningKey(subId, tech);
4812 editor.putInt(key, newField);
4813 editor.commit();
4814 }
4815
4816 private static String getMmTelProvisioningKey(int subId, int tech) {
4817 // resulting key is provision_ims_mmtel_{subId}_{tech}
4818 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4819 }
4820
4821 /**
4822 * Query CarrierConfig to see if the specified capability requires provisioning for the
4823 * carrier associated with the subscription id.
4824 */
4825 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4826 int capability) {
4827 CarrierConfigManager configManager = new CarrierConfigManager(context);
4828 PersistableBundle c = configManager.getConfigForSubId(subId);
4829 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004830 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004831 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4832 false);
4833 boolean requireVoiceVtProvisioning = c.getBoolean(
4834 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4835
4836 // First check to make sure that the capability requires provisioning.
4837 switch (capability) {
4838 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4839 // intentional fallthrough
4840 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4841 if (requireVoiceVtProvisioning) {
4842 // Voice and Video requires provisioning
4843 return true;
4844 }
4845 break;
4846 }
4847 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4848 if (requireUtProvisioning) {
4849 // UT requires provisioning
4850 return true;
4851 }
4852 break;
4853 }
4854 }
4855 return false;
4856 }
4857
allenwtsu99c623b2020-01-03 18:24:23 +08004858 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4859 int capability) {
4860 CarrierConfigManager configManager = new CarrierConfigManager(context);
4861 PersistableBundle c = configManager.getConfigForSubId(subId);
4862
4863 boolean requireRcsProvisioning = c.getBoolean(
4864 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4865
4866 // First check to make sure that the capability requires provisioning.
4867 switch (capability) {
4868 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4869 // intentional fallthrough
4870 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4871 if (requireRcsProvisioning) {
4872 // OPTION or PRESENCE requires provisioning
4873 return true;
4874 }
4875 break;
4876 }
4877 }
4878 return false;
4879 }
4880
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004881 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004882 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004883 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4884 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4885 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004886 enforceReadPrivilegedPermission("getImsProvisioningInt");
4887 final long identity = Binder.clearCallingIdentity();
4888 try {
4889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 int slotId = getSlotIndex(subId);
4891 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4892 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4893 + subId + "' for key:" + key);
4894 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4895 }
calvinpanb5a34062021-02-08 19:59:36 +08004896 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004897 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004898 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4899 + subId + "' for key:" + key);
4900 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
4904 }
4905
4906 @Override
4907 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004908 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4909 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4910 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004911 enforceReadPrivilegedPermission("getImsProvisioningString");
4912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004915 int slotId = getSlotIndex(subId);
4916 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4917 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4918 + subId + "' for key:" + key);
4919 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4920 }
calvinpanb5a34062021-02-08 19:59:36 +08004921 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004922 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004923 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4924 + subId + "' for key:" + key);
4925 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004926 } finally {
4927 Binder.restoreCallingIdentity(identity);
4928 }
4929 }
4930
4931 @Override
4932 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4934 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4935 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4937 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004938 final long identity = Binder.clearCallingIdentity();
4939 try {
4940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004941 int slotId = getSlotIndex(subId);
4942 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4943 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4944 + subId + "' for key:" + key);
4945 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4946 }
calvinpanb5a34062021-02-08 19:59:36 +08004947 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4948 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004949 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004950 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004951 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
4955 }
4956
4957 @Override
4958 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4960 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4961 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4963 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004964 final long identity = Binder.clearCallingIdentity();
4965 try {
4966 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004967 int slotId = getSlotIndex(subId);
4968 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4969 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4970 + subId + "' for key:" + key);
4971 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4972 }
calvinpanb5a34062021-02-08 19:59:36 +08004973 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4974 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004975 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004976 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004977 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004978 } finally {
4979 Binder.restoreCallingIdentity(identity);
4980 }
4981 }
4982
Brad Ebinger919631e2021-06-02 17:46:35 -07004983 /**
4984 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4985 * for the given slot ID or no ImsResolver instance has been created.
4986 * @param slotId The slot ID that the IMS service is created for.
4987 * @throws ImsException If there is no ImsService configured for this slot.
4988 */
4989 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4990 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4991 ImsFeature.FEATURE_MMTEL)) {
4992 throw new ImsException("This subscription does not support MMTEL over IMS",
4993 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4994 }
4995 }
4996
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004997 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004998 int slotId = SubscriptionManager.getSlotIndex(subId);
4999 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005000 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5001 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005002 }
5003 return slotId;
5004 }
5005
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005006 private int getSlotIndex(int subId) {
5007 int slotId = SubscriptionManager.getSlotIndex(subId);
5008 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5009 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5010 }
5011 return slotId;
5012 }
5013
Wink Saville36469e72014-06-11 15:17:00 -07005014 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005015 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005016 */
5017 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005018 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5019 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005020 try {
5021 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5022 } catch (SecurityException se) {
5023 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5024 throw new SecurityException("Package " + callingPackage + " does not belong to "
5025 + Binder.getCallingUid());
5026 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005027 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005028 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005029 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005030 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005031 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005032 mApp, subId, callingPackage, callingFeatureId,
5033 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005034 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5035 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 final Phone phone = getPhone(subId);
5040 if (phone != null) {
5041 return phone.getServiceState().getDataNetworkType();
5042 } else {
5043 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5044 }
5045 } finally {
5046 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005048 }
5049
5050 /**
5051 * Returns the data network type
5052 */
5053 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005054 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005055 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5056 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005057 }
5058
5059 /**
5060 * Returns the data network type for a subId
5061 */
5062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005063 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5064 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005065 String functionName = "getDataNetworkTypeForSubscriber";
5066 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5067 mApp, functionName)) {
5068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5069 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5070 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5071 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005072 }
5073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 final Phone phone = getPhone(subId);
5077 if (phone != null) {
5078 return phone.getServiceState().getDataNetworkType();
5079 } else {
5080 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5081 }
5082 } finally {
5083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005085 }
5086
5087 /**
Wink Saville36469e72014-06-11 15:17:00 -07005088 * Returns the Voice network type for a subId
5089 */
5090 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005091 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5092 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005093 String functionName = "getVoiceNetworkTypeForSubscriber";
5094 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5095 mApp, functionName)) {
5096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5097 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5098 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5099 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005100 }
5101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 final long identity = Binder.clearCallingIdentity();
5103 try {
5104 final Phone phone = getPhone(subId);
5105 if (phone != null) {
5106 return phone.getServiceState().getVoiceNetworkType();
5107 } else {
5108 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5109 }
5110 } finally {
5111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005113 }
5114
5115 /**
5116 * @return true if a ICC card is present
5117 */
5118 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005119 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005120 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5121 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005122 }
5123
5124 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005125 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005126 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005127 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005128 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 final long identity = Binder.clearCallingIdentity();
5130 try {
5131 final Phone phone = PhoneFactory.getPhone(slotIndex);
5132 if (phone != null) {
5133 return phone.getIccCard().hasIccCard();
5134 } else {
5135 return false;
5136 }
5137 } finally {
5138 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005140 }
5141
5142 /**
5143 * Return if the current radio is LTE on CDMA. This
5144 * is a tri-state return value as for a period of time
5145 * the mode may be unknown.
5146 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005147 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005148 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005149 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005150 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005151 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005152 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5153 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5154 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005155 }
5156
Sanket Padawe356d7632015-06-22 14:03:32 -07005157 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005158 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5159 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005160 try {
5161 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5162 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005163 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5164 }
5165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 final long identity = Binder.clearCallingIdentity();
5167 try {
5168 final Phone phone = getPhone(subId);
5169 if (phone == null) {
5170 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5171 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005172 return TelephonyProperties.lte_on_cdma_device()
5173 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 }
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005177 }
Wink Saville36469e72014-06-11 15:17:00 -07005178 }
5179
Wink Saville36469e72014-06-11 15:17:00 -07005180 /**
5181 * {@hide}
5182 * Returns Default subId, 0 in the case of single standby.
5183 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005184 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005185 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005186 }
5187
Shishir Agrawala9f32182016-04-12 12:00:16 -07005188 private int getSlotForDefaultSubscription() {
5189 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5190 }
5191
Wink Savilleb564aae2014-10-23 10:18:09 -07005192 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005193 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005194 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005195
Pengquan Menge92a50d2018-09-21 15:54:48 -07005196 private boolean isActiveSubscription(int subId) {
5197 return mSubscriptionController.isActiveSubId(subId);
5198 }
5199
Ihab Awadf2177b72013-11-25 13:33:23 -08005200 /**
5201 * @see android.telephony.TelephonyManager.WifiCallingChoices
5202 */
5203 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 final long identity = Binder.clearCallingIdentity();
5205 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005206 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5208 getWhenToMakeWifiCallsDefaultPreference());
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005212 }
5213
5214 /**
5215 * @see android.telephony.TelephonyManager.WifiCallingChoices
5216 */
5217 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005221 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005226 }
5227
Sailesh Nepald1e68152013-12-12 19:08:02 -08005228 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005229 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005230 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005231 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005232
Jordan Liu4c733742019-02-28 12:03:40 -08005233 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5234 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5235 if (phoneId == -1) {
5236 throw new IllegalArgumentException("Given slot index: " + slotIndex
5237 + " does not correspond to an active phone");
5238 }
5239 return PhoneFactory.getPhone(phoneId);
5240 }
5241
Shishir Agrawal566b7612013-10-28 14:41:00 -07005242 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005243 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5244 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5246 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005248 if (DBG) {
5249 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5250 }
5251 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5252 p2);
5253 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005254
Jordan Liu4c733742019-02-28 12:03:40 -08005255
5256 @Override
5257 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5258 int slotIndex, String callingPackage, String aid, int p2) {
5259 enforceModifyPermission();
5260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5261 if (DBG) {
5262 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5263 }
5264 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5265 callingPackage, aid, p2);
5266 }
5267
5268 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5269 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 if (TextUtils.equals(ISDR_AID, aid)) {
5273 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005274 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5275 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 if (bestComponent == null
5277 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5278 loge("The calling package is not allowed to access ISD-R.");
5279 throw new SecurityException(
5280 "The calling package is not allowed to access ISD-R.");
5281 }
Derek Tan740e1672017-06-27 14:56:27 -07005282 }
Derek Tan740e1672017-06-27 14:56:27 -07005283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005285 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5286 null /* workSource */);
5287 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 return response;
5289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005292 }
5293
5294 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005295 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5297 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005298 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5299 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5300 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005301
Jordan Liu4c733742019-02-28 12:03:40 -08005302 @Override
5303 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5304 enforceModifyPermission();
5305 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5306 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5307 channel);
5308 }
5309
5310 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 final long identity = Binder.clearCallingIdentity();
5312 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 if (channel < 0) {
5314 return false;
5315 }
Jordan Liu4c733742019-02-28 12:03:40 -08005316 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5317 null /* workSource */);
5318 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 return success;
5320 } finally {
5321 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005322 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005323 }
5324
5325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005326 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005327 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5329 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005330 if (DBG) {
5331 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5332 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5333 + p3 + " data=" + data);
5334 }
5335 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5336 command, p1, p2, p3, data);
5337 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005338
Jordan Liu4c733742019-02-28 12:03:40 -08005339 @Override
5340 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5341 int command, int p1, int p2, int p3, String data) {
5342 enforceModifyPermission();
5343 if (DBG) {
5344 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5345 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5346 + p3 + " data=" + data);
5347 }
5348 return iccTransmitApduLogicalChannelWithPermission(
5349 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5350 data);
5351 }
5352
5353 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5354 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 final long identity = Binder.clearCallingIdentity();
5356 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005357 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 return "";
5359 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005362 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5363 null /* workSource */);
5364 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 // Append the returned status code to the end of the response payload.
5367 String s = Integer.toHexString(
5368 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5369 if (response.payload != null) {
5370 s = IccUtils.bytesToHexString(response.payload) + s;
5371 }
5372 return s;
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005375 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005376 }
Jake Hambye994d462014-02-03 13:10:13 -08005377
Evan Charltonc66da362014-05-16 14:06:40 -07005378 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005379 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5380 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5382 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005384 if (DBG) {
5385 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5386 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5387 }
5388 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5389 cla, command, p1, p2, p3, data);
5390 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005391
Jordan Liu4c733742019-02-28 12:03:40 -08005392 @Override
5393 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5394 int command, int p1, int p2, int p3, String data) {
5395 enforceModifyPermission();
5396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5397 if (DBG) {
5398 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5399 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5400 + " data=" + data);
5401 }
5402
5403 return iccTransmitApduBasicChannelWithPermission(
5404 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5405 p2, p3, data);
5406 }
5407
5408 // open APDU basic channel assuming the caller has sufficient permissions
5409 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5410 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5414 && TextUtils.equals(ISDR_AID, data)) {
5415 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005416 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5417 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 if (bestComponent == null
5419 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5420 loge("The calling package is not allowed to select ISD-R.");
5421 throw new SecurityException(
5422 "The calling package is not allowed to select ISD-R.");
5423 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005424 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005427 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5428 null /* workSource */);
5429 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005430
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 // Append the returned status code to the end of the response payload.
5432 String s = Integer.toHexString(
5433 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5434 if (response.payload != null) {
5435 s = IccUtils.bytesToHexString(response.payload) + s;
5436 }
5437 return s;
5438 } finally {
5439 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005440 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005441 }
5442
5443 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005444 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005445 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5447 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
5451 if (DBG) {
5452 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5453 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5454 }
5455
5456 IccIoResult response =
5457 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5458 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5459 subId);
5460
5461 if (DBG) {
5462 log("Exchange SIM_IO [R]" + response);
5463 }
5464
5465 byte[] result = null;
5466 int length = 2;
5467 if (response.payload != null) {
5468 length = 2 + response.payload.length;
5469 result = new byte[length];
5470 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5471 } else {
5472 result = new byte[length];
5473 }
5474
5475 result[length - 1] = (byte) response.sw2;
5476 result[length - 2] = (byte) response.sw1;
5477 return result;
5478 } finally {
5479 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005480 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005481 }
5482
Nathan Haroldb3014052017-01-25 15:57:32 -08005483 /**
5484 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5485 * on a particular subscription
5486 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005487 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5488 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005490 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005491 return null;
5492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493
5494 final long identity = Binder.clearCallingIdentity();
5495 try {
5496 if (appType != TelephonyManager.APPTYPE_USIM
5497 && appType != TelephonyManager.APPTYPE_SIM) {
5498 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5499 return null;
5500 }
5501 Object response = sendRequest(
5502 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5503 if (response instanceof String[]) {
5504 return (String[]) response;
5505 }
yincheng zhao2737e882019-09-06 17:06:54 -07005506 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005508 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 } finally {
5510 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005511 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005512 }
5513
yincheng zhao2737e882019-09-06 17:06:54 -07005514 /**
5515 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5516 * subscription.
5517 *
5518 * @param subId the id of the subscription.
5519 * @param appType the uicc app type, must be USIM or SIM.
5520 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5521 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005522 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005523 * @return number of fplmns that is successfully written to the SIM.
5524 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005525 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5526 String callingFeatureId) {
5527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5528 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005529 if (DBG) logv("no permissions for setForbiddenplmns");
5530 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5531 }
5532 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5533 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5534 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5535 }
5536 if (fplmns == null) {
5537 throw new IllegalArgumentException("Fplmn List provided is null");
5538 }
5539 for (String fplmn : fplmns) {
5540 if (!CellIdentity.isValidPlmn(fplmn)) {
5541 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5542 }
5543 }
5544 final long identity = Binder.clearCallingIdentity();
5545 try {
5546 Object response = sendRequest(
5547 CMD_SET_FORBIDDEN_PLMNS,
5548 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5549 subId);
5550 return (int) response;
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
5554 }
5555
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005556 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005557 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5559 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5564 if (response.payload == null) {
5565 return "";
5566 }
Evan Charltonc66da362014-05-16 14:06:40 -07005567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005568 // Append the returned status code to the end of the response payload.
5569 String s = Integer.toHexString(
5570 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5571 s = IccUtils.bytesToHexString(response.payload) + s;
5572 return s;
5573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
Evan Charltonc66da362014-05-16 14:06:40 -07005576 }
5577
Jake Hambye994d462014-02-03 13:10:13 -08005578 /**
5579 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5580 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5581 *
5582 * @param itemID the ID of the item to read
5583 * @return the NV item as a String, or null on error.
5584 */
5585 @Override
5586 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005587 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5589 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005594 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5596 return value;
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
Jake Hambye994d462014-02-03 13:10:13 -08005600 }
5601
5602 /**
5603 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5604 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5605 *
5606 * @param itemID the ID of the item to read
5607 * @param itemValue the value to write, as a String
5608 * @return true on success; false on any failure
5609 */
5610 @Override
5611 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005612 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5614 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615
5616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5619 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005620 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5622 return success;
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Jake Hambye994d462014-02-03 13:10:13 -08005626 }
5627
5628 /**
5629 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5630 * Used for device configuration by some CDMA operators.
5631 *
5632 * @param preferredRoamingList byte array containing the new PRL
5633 * @return true on success; false on any failure
5634 */
5635 @Override
5636 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5638 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639
5640 final long identity = Binder.clearCallingIdentity();
5641 try {
5642 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5643 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5644 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5645 return success;
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
Jake Hambye994d462014-02-03 13:10:13 -08005649 }
5650
5651 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005652 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005653 * Used for device configuration by some CDMA operators.
5654 *
chen xu6dac5ab2018-10-26 17:39:23 -07005655 * @param slotIndex - device slot.
5656 *
Jake Hambye994d462014-02-03 13:10:13 -08005657 * @return true on success; false on any failure
5658 */
5659 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005660 public boolean resetModemConfig(int slotIndex) {
5661 Phone phone = PhoneFactory.getPhone(slotIndex);
5662 if (phone != null) {
5663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5664 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665
chen xu6dac5ab2018-10-26 17:39:23 -07005666 final long identity = Binder.clearCallingIdentity();
5667 try {
5668 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5669 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5670 return success;
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
5673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 }
chen xu6dac5ab2018-10-26 17:39:23 -07005675 return false;
5676 }
5677
5678 /**
5679 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5680 *
5681 * @param slotIndex - device slot.
5682 *
5683 * @return true on success; false on any failure
5684 */
5685 @Override
5686 public boolean rebootModem(int slotIndex) {
5687 Phone phone = PhoneFactory.getPhone(slotIndex);
5688 if (phone != null) {
5689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5690 mApp, phone.getSubId(), "rebootModem");
5691
5692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5695 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5696 return success;
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
5700 }
5701 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005702 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005703
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005704 public String[] getPcscfAddress(String apnType, String callingPackage,
5705 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005706 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5708 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005709 return new String[0];
5710 }
5711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 final long identity = Binder.clearCallingIdentity();
5713 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005714 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 } finally {
5716 Binder.restoreCallingIdentity(identity);
5717 }
Wink Saville36469e72014-06-11 15:17:00 -07005718 }
5719
Brad Ebinger51f743a2017-01-23 13:50:20 -08005720 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005721 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5722 * {@link #disableIms(int)}.
5723 * @param slotIndex device slot.
5724 */
5725 public void resetIms(int slotIndex) {
5726 enforceModifyPermission();
5727
5728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 if (mImsResolver == null) {
5731 // may happen if the does not support IMS.
5732 return;
5733 }
5734 mImsResolver.disableIms(slotIndex);
5735 mImsResolver.enableIms(slotIndex);
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
5739 }
5740
5741 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005742 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5743 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005744 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005745 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005746 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747
5748 final long identity = Binder.clearCallingIdentity();
5749 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005750 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005751 // may happen if the device does not support IMS.
5752 return;
5753 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005754 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005758 }
5759
5760 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005761 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5762 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005763 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005764 public void disableIms(int slotId) {
5765 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005769 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005770 // may happen if the device does not support IMS.
5771 return;
5772 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005773 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005777 }
5778
5779 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005780 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5781 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005782 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005783 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005784 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005785 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005790 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5791 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005792 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005793 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005797 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005798 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005799 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5800 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005801 @Override
5802 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005803 enforceModifyPermission();
5804
5805 final long identity = Binder.clearCallingIdentity();
5806 try {
5807 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005808 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005809 } finally {
5810 Binder.restoreCallingIdentity(identity);
5811 }
5812 }
5813
5814 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005815 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005816 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005817 */
5818 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820
5821 final long identity = Binder.clearCallingIdentity();
5822 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005823 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005824 // may happen if the device does not support IMS.
5825 return null;
5826 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005827 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828 } finally {
5829 Binder.restoreCallingIdentity(identity);
5830 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005831 }
5832
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005833 /**
5834 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005835 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005836 */
5837 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839
5840 final long identity = Binder.clearCallingIdentity();
5841 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005843 // may happen if the device does not support IMS.
5844 return null;
5845 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005846 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005850 }
5851
Brad Ebinger884c07b2018-02-15 16:17:40 -08005852 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005853 * Sets the ImsService Package Name that Telephony will bind to.
5854 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005855 * @param slotIndex the slot ID that the ImsService should bind for.
5856 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005857 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005858 * @param featureTypes An integer array of feature types associated with a packageName.
5859 * @param packageName The name of the package that the current configuration will be replaced
5860 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005861 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005862 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5864 int[] featureTypes, String packageName) {
5865 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5868 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 final long identity = Binder.clearCallingIdentity();
5872 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005873 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005874 // may happen if the device does not support IMS.
5875 return false;
5876 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 Map<Integer, String> featureConfig = new HashMap<>();
5878 for (int featureType : featureTypes) {
5879 featureConfig.put(featureType, packageName);
5880 }
5881 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5882 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005886 }
5887
5888 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005889 * Clears any carrier ImsService overrides for the slot index specified that were previously
5890 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5891 *
5892 * This should only be used for testing.
5893 *
5894 * @param slotIndex the slot ID that the ImsService should bind for.
5895 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5896 */
5897 @Override
5898 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5899 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5900 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5901 "clearCarrierImsServiceOverride");
5902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5903 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5904 "clearCarrierImsServiceOverride");
5905
5906 final long identity = Binder.clearCallingIdentity();
5907 try {
5908 if (mImsResolver == null) {
5909 // may happen if the device does not support IMS.
5910 return false;
5911 }
5912 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
5916 }
5917
5918 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005919 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005920 *
5921 * @param slotId The slot that the ImsService is associated with.
5922 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5923 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005925 * @return the package name of the ImsService configuration.
5926 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5928 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005929 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005931 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005932 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5933 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 final long identity = Binder.clearCallingIdentity();
5936 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005937 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005938 // may happen if the device does not support IMS.
5939 return "";
5940 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005941 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005942 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5943 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005947 }
5948
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005949 /**
5950 * Get the MmTelFeature state associated with the requested subscription id.
5951 * @param subId The subscription that the MmTelFeature is associated with.
5952 * @param callback A callback with an integer containing the
5953 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5954 */
5955 @Override
5956 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5957 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5958 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5959 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5960 "IMS not available on device.");
5961 }
5962 final long token = Binder.clearCallingIdentity();
5963 try {
5964 int slotId = getSlotIndex(subId);
5965 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5966 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5967 + subId + "'");
5968 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5969 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005970 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005971 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5972 try {
5973 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5974 } catch (RemoteException e) {
5975 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5976 + "Ignore");
5977 }
5978 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005979 } catch (ImsException e) {
5980 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005981 } finally {
5982 Binder.restoreCallingIdentity(token);
5983 }
5984 }
5985
Daniel Brightbb5840b2021-01-12 15:48:18 -08005986 /**
5987 * Sets the ims registration state on all valid {@link Phone}s.
5988 */
5989 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005990 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991
5992 final long identity = Binder.clearCallingIdentity();
5993 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005994 // NOTE: Before S, this method only set the default phone.
5995 for (final Phone phone : PhoneFactory.getPhones()) {
5996 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5997 phone.setImsRegistrationState(registered);
5998 }
5999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 } finally {
6001 Binder.restoreCallingIdentity(identity);
6002 }
Wink Saville36469e72014-06-11 15:17:00 -07006003 }
6004
6005 /**
Stuart Scott54788802015-03-30 13:18:01 -07006006 * Set the network selection mode to automatic.
6007 *
6008 */
6009 @Override
6010 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6012 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013
6014 final long identity = Binder.clearCallingIdentity();
6015 try {
shilufc958392020-01-20 11:36:01 -08006016 if (!isActiveSubscription(subId)) {
6017 return;
6018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006020 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6021 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
Stuart Scott54788802015-03-30 13:18:01 -07006025 }
6026
Jack Yud10cdd42020-09-28 20:28:01 -07006027 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006028 * Ask the radio to connect to the input network and change selection mode to manual.
6029 *
6030 * @param subId the id of the subscription.
6031 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6032 * the operator to attach to.
6033 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6034 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6035 * normal network selection next time.
6036 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006037 */
6038 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006039 public boolean setNetworkSelectionModeManual(
6040 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6042 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006043
6044 if (!isActiveSubscription(subId)) {
6045 return false;
6046 }
6047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 final long identity = Binder.clearCallingIdentity();
6049 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006050 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006052 if (DBG) {
6053 log("setNetworkSelectionModeManual: subId: " + subId
6054 + " operator: " + operatorInfo);
6055 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006060 }
shilu84f6e8b2019-12-19 13:58:01 -08006061 /**
6062 * Get the manual network selection
6063 *
6064 * @param subId the id of the subscription.
6065 *
6066 * @return the previously saved user selected PLMN
6067 */
6068 @Override
6069 public String getManualNetworkSelectionPlmn(int subId) {
6070 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006071 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006072 mApp, subId, "getManualNetworkSelectionPlmn");
6073
6074 final long identity = Binder.clearCallingIdentity();
6075 try {
6076 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006077 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006078 }
6079
6080 final Phone phone = getPhone(subId);
6081 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006082 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006083 }
6084 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6085 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6086 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
6090 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006091
6092 /**
6093 * Scans for available networks.
6094 */
6095 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006096 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6097 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6099 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006100 LocationAccessPolicy.LocationPermissionResult locationResult =
6101 LocationAccessPolicy.checkLocationPermission(mApp,
6102 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6103 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006104 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006105 .setCallingPid(Binder.getCallingPid())
6106 .setCallingUid(Binder.getCallingUid())
6107 .setMethod("getCellNetworkScanResults")
6108 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006109 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6110 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006111 .build());
6112 switch (locationResult) {
6113 case DENIED_HARD:
6114 throw new SecurityException("Not allowed to access scan results -- location");
6115 case DENIED_SOFT:
6116 return null;
6117 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118
Pengquan Menga1bb6272018-09-06 09:59:22 -07006119 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 try {
6121 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006122 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 } finally {
6125 Binder.restoreCallingIdentity(identity);
6126 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006127 }
6128
6129 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006130 * Get the call forwarding info, given the call forwarding reason.
6131 */
6132 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006133 public void getCallForwarding(int subId, int callForwardingReason,
6134 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006135 enforceReadPrivilegedPermission("getCallForwarding");
6136 long identity = Binder.clearCallingIdentity();
6137 try {
6138 if (DBG) {
6139 log("getCallForwarding: subId " + subId
6140 + " callForwardingReason" + callForwardingReason);
6141 }
Hall Liu27d24262020-09-18 19:04:59 -07006142
6143 Phone phone = getPhone(subId);
6144 if (phone == null) {
6145 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006146 callback.onError(
6147 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006148 } catch (RemoteException e) {
6149 // ignore
6150 }
6151 return;
6152 }
6153
6154 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6155 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6156 @Override
6157 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6158 try {
6159 callback.onCallForwardingInfoAvailable(info);
6160 } catch (RemoteException e) {
6161 // ignore
6162 }
6163 }
6164
6165 @Override
6166 public void onError(int error) {
6167 try {
6168 callback.onError(error);
6169 } catch (RemoteException e) {
6170 // ignore
6171 }
6172 }
6173 });
6174 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006175 } finally {
6176 Binder.restoreCallingIdentity(identity);
6177 }
6178 }
6179
6180 /**
6181 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6182 * reason, the number to forward, and the timeout before the forwarding is attempted.
6183 */
6184 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006185 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6186 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006187 enforceModifyPermission();
6188 long identity = Binder.clearCallingIdentity();
6189 try {
6190 if (DBG) {
6191 log("setCallForwarding: subId " + subId
6192 + " callForwardingInfo" + callForwardingInfo);
6193 }
Hall Liu27d24262020-09-18 19:04:59 -07006194
6195 Phone phone = getPhone(subId);
6196 if (phone == null) {
6197 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006198 callback.accept(
6199 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006200 } catch (RemoteException e) {
6201 // ignore
6202 }
6203 return;
6204 }
6205
6206 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6207 FunctionalUtils.ignoreRemoteException(callback::accept));
6208
6209 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006210 } finally {
6211 Binder.restoreCallingIdentity(identity);
6212 }
6213 }
6214
6215 /**
Hall Liu27d24262020-09-18 19:04:59 -07006216 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006217 */
6218 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006219 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006220 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006221 long identity = Binder.clearCallingIdentity();
6222 try {
Hall Liu27d24262020-09-18 19:04:59 -07006223 Phone phone = getPhone(subId);
6224 if (phone == null) {
6225 try {
6226 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6227 } catch (RemoteException e) {
6228 // ignore
6229 }
6230 return;
6231 }
SongFerngWang0e767992021-03-31 22:08:45 +08006232 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6233 PersistableBundle c = configManager.getConfigForSubId(subId);
6234 boolean requireUssd = c.getBoolean(
6235 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006236
Shuo Qian4a594052020-01-23 11:59:30 -08006237 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006238 if (requireUssd) {
6239 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6240 getSubscriptionCarrierId(subId));
6241 String newUssdCommand = "";
6242 try {
6243 newUssdCommand = carrierXmlParser.getFeature(
6244 CarrierXmlParser.FEATURE_CALL_WAITING)
6245 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6246 } catch (NullPointerException e) {
6247 loge("Failed to generate USSD number" + e);
6248 }
6249 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6250 mMainThreadHandler, callback, carrierXmlParser,
6251 CarrierXmlParser.SsEntry.SSAction.QUERY);
6252 final String ussdCommand = newUssdCommand;
6253 Executors.newSingleThreadExecutor().execute(() -> {
6254 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6255 });
6256 } else {
6257 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6258 callback::accept);
6259 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6260 }
Shuo Qian4a594052020-01-23 11:59:30 -08006261 } finally {
6262 Binder.restoreCallingIdentity(identity);
6263 }
6264 }
6265
6266 /**
Hall Liu27d24262020-09-18 19:04:59 -07006267 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006268 */
6269 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006270 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006271 enforceModifyPermission();
6272 long identity = Binder.clearCallingIdentity();
6273 try {
Hall Liu27d24262020-09-18 19:04:59 -07006274 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6275
6276 Phone phone = getPhone(subId);
6277 if (phone == null) {
6278 try {
6279 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6280 } catch (RemoteException e) {
6281 // ignore
6282 }
6283 return;
6284 }
6285
SongFerngWang0e767992021-03-31 22:08:45 +08006286 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6287 PersistableBundle c = configManager.getConfigForSubId(subId);
6288 boolean requireUssd = c.getBoolean(
6289 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006290
SongFerngWang0e767992021-03-31 22:08:45 +08006291 if (DBG) log("getCallWaitingStatus: subId " + subId);
6292 if (requireUssd) {
6293 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6294 getSubscriptionCarrierId(subId));
6295 CarrierXmlParser.SsEntry.SSAction ssAction =
6296 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6297 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6298 String newUssdCommand = "";
6299 try {
6300 newUssdCommand = carrierXmlParser.getFeature(
6301 CarrierXmlParser.FEATURE_CALL_WAITING)
6302 .makeCommand(ssAction, null);
6303 } catch (NullPointerException e) {
6304 loge("Failed to generate USSD number" + e);
6305 }
6306 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6307 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6308 final String ussdCommand = newUssdCommand;
6309 Executors.newSingleThreadExecutor().execute(() -> {
6310 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6311 });
6312 } else {
6313 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6314 FunctionalUtils.ignoreRemoteException(callback::accept));
6315
6316 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6317 }
Shuo Qian4a594052020-01-23 11:59:30 -08006318 } finally {
6319 Binder.restoreCallingIdentity(identity);
6320 }
6321 }
6322
6323 /**
yinxub1bed742017-04-17 11:45:04 -07006324 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006325 *
yinxub1bed742017-04-17 11:45:04 -07006326 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006327 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6328 * location related information which will be sent if the caller already possess
6329 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006330 * @param request contains the radio access networks with bands/channels to scan
6331 * @param messenger callback messenger for scan results or errors
6332 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006333 * @return the id of the requested scan which can be used to stop the scan.
6334 */
6335 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006336 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6337 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006338 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6340 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006341 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006342 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6343 if (!renounceFineLocationAccess) {
6344 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6345 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6346 .setCallingPackage(callingPackage)
6347 .setCallingFeatureId(callingFeatureId)
6348 .setCallingPid(Binder.getCallingPid())
6349 .setCallingUid(Binder.getCallingUid())
6350 .setMethod("requestNetworkScan")
6351 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6352 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6353 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6354 .build());
6355 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006356 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006357 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6358 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006359 if (e != null) {
6360 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6361 throw e;
6362 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006363 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006364 return TelephonyScanManager.INVALID_SCAN_ID;
6365 }
6366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 }
Hall Liu912dfd32019-04-25 14:02:26 -07006368 int callingUid = Binder.getCallingUid();
6369 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006370 final long identity = Binder.clearCallingIdentity();
6371 try {
6372 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006373 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006374 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006375 } finally {
6376 Binder.restoreCallingIdentity(identity);
6377 }
yinxu504e1392017-04-12 16:03:22 -07006378 }
6379
Hall Liub2ac8ef2019-02-28 15:56:23 -08006380 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006381 NetworkScanRequest request, int subId, String callingPackage) {
6382 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006383 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6384 boolean hasNetworkScanPermission =
6385 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6386 == PERMISSION_GRANTED;
6387
6388 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6389 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6390 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006391 }
6392
6393 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6394 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006395 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6396 return new SecurityException("Specific channels must not be"
6397 + " scanned without location access.");
6398 }
6399 }
6400 }
6401
Hall Liub2ac8ef2019-02-28 15:56:23 -08006402 return null;
6403 }
6404
yinxu504e1392017-04-12 16:03:22 -07006405 /**
6406 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006407 *
6408 * @param subId id of the subscription
6409 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006410 */
6411 @Override
6412 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6414 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415
Hall Liu912dfd32019-04-25 14:02:26 -07006416 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 final long identity = Binder.clearCallingIdentity();
6418 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006419 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 } finally {
6421 Binder.restoreCallingIdentity(identity);
6422 }
yinxu504e1392017-04-12 16:03:22 -07006423 }
6424
6425 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006426 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006427 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006428 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006429 */
6430 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006431 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006432 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006433 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006434 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006435
6436 final long identity = Binder.clearCallingIdentity();
6437 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006438 if (DBG) log("getAllowedNetworkTypesBitmask");
6439 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6440 int networkTypesBitmask = (result != null ? result[0] : -1);
6441 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6442 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006446 }
6447
6448 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006449 * Get the allowed network types for certain reason.
6450 *
6451 * @param subId the id of the subscription.
6452 * @param reason the reason the allowed network type change is taking place
6453 * @return the allowed network types.
6454 */
6455 @Override
6456 public long getAllowedNetworkTypesForReason(int subId,
6457 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006458 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006459 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6463 } finally {
6464 Binder.restoreCallingIdentity(identity);
6465 }
6466 }
6467
6468 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006469 * Enable/Disable E-UTRA-NR Dual Connectivity
6470 * @param subId subscription id of the sim card
6471 * @param nrDualConnectivityState expected NR dual connectivity state
6472 * This can be passed following states
6473 * <ol>
6474 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6475 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6476 * <li>Disable NR dual connectivity and force secondary cell to be released
6477 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6478 * </ol>
6479 * @return operation result.
6480 */
6481 @Override
6482 public int setNrDualConnectivityState(int subId,
6483 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6485 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006486 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006487 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6488 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6489 }
6490
Sooraj Sasindran37444802020-08-11 10:40:43 -07006491 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6495 nrDualConnectivityState, subId,
6496 workSource);
6497 if (DBG) log("enableNRDualConnectivity result: " + result);
6498 return result;
6499 } finally {
6500 Binder.restoreCallingIdentity(identity);
6501 }
6502 }
6503
6504 /**
6505 * Is E-UTRA-NR Dual Connectivity enabled
6506 * @return true if dual connectivity is enabled else false
6507 */
6508 @Override
6509 public boolean isNrDualConnectivityEnabled(int subId) {
6510 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006511 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006512 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006513 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006514 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6515 return false;
6516 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006517 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6518 final long identity = Binder.clearCallingIdentity();
6519 try {
6520 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6521 null, subId, workSource);
6522 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6523 return isEnabled;
6524 } finally {
6525 Binder.restoreCallingIdentity(identity);
6526 }
6527 }
6528
6529 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006530 * Set the allowed network types of the device and
6531 * provide the reason triggering the allowed network change.
6532 *
6533 * @param subId the id of the subscription.
6534 * @param reason the reason the allowed network type change is taking place
6535 * @param allowedNetworkTypes the allowed network types.
6536 * @return true on success; false on any failure.
6537 */
6538 @Override
6539 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006540 @TelephonyManager.AllowedNetworkTypesReason int reason,
6541 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6543 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006544 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006545 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6546 return false;
6547 }
6548 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6549 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006550 return false;
6551 }
6552
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006553 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6554 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6555
6556
6557 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6558 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6559 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006560 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006561
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006562 final long identity = Binder.clearCallingIdentity();
6563 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006564 Boolean success = (Boolean) sendRequest(
6565 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6566 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6567
6568 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6569 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572 }
6573 }
6574
6575 /**
Miaoa84611c2019-03-15 09:21:10 +08006576 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006577 *
Miaoa84611c2019-03-15 09:21:10 +08006578 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006579 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006580 * @hide
6581 */
6582 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006583 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006584 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006585 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006586 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587 try {
Miaoa84611c2019-03-15 09:21:10 +08006588 if (phone != null) {
6589 return phone.hasMatchedTetherApnSetting();
6590 } else {
6591 return false;
6592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593 } finally {
6594 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006595 }
Junda Liu475951f2014-11-07 16:45:03 -08006596 }
6597
6598 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006599 * Get the user enabled state of Mobile Data.
6600 *
6601 * TODO: remove and use isUserDataEnabled.
6602 * This can't be removed now because some vendor codes
6603 * calls through ITelephony directly while they should
6604 * use TelephonyManager.
6605 *
6606 * @return true on enabled
6607 */
6608 @Override
6609 public boolean getDataEnabled(int subId) {
6610 return isUserDataEnabled(subId);
6611 }
6612
6613 /**
6614 * Get whether mobile data is enabled per user setting.
6615 *
6616 * There are other factors deciding whether mobile data is actually enabled, but they are
6617 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006618 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006619 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6620 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006621 *
6622 * @return {@code true} if data is enabled else {@code false}
6623 */
6624 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006625 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006626 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006627 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006628 try {
6629 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6630 functionName);
6631 } catch (Exception e) {
6632 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6633 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006634 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006636 mApp, subId, functionName);
6637
Robert Greenwalt646120a2014-05-23 11:54:03 -07006638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639
6640 final long identity = Binder.clearCallingIdentity();
6641 try {
6642 int phoneId = mSubscriptionController.getPhoneId(subId);
6643 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6644 Phone phone = PhoneFactory.getPhone(phoneId);
6645 if (phone != null) {
6646 boolean retVal = phone.isUserDataEnabled();
6647 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6648 return retVal;
6649 } else {
6650 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6651 return false;
6652 }
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006655 }
6656 }
6657
6658 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006659 * Checks if the device is capable of mobile data by considering whether whether the
6660 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6661 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006662 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006663 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006664 */
6665 @Override
6666 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006667 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006668 try {
6669 try {
6670 mApp.enforceCallingOrSelfPermission(
6671 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006672 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006673 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006674 try {
6675 mApp.enforceCallingOrSelfPermission(
6676 android.Manifest.permission.READ_PHONE_STATE,
6677 functionName);
6678 } catch (Exception e2) {
6679 mApp.enforceCallingOrSelfPermission(
6680 permission.READ_BASIC_PHONE_STATE, functionName);
6681 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006682 }
6683 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006684 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006686
6687 final long identity = Binder.clearCallingIdentity();
6688 try {
6689 int phoneId = mSubscriptionController.getPhoneId(subId);
6690 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6691 Phone phone = PhoneFactory.getPhone(phoneId);
6692 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006693 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6695 return retVal;
6696 } else {
6697 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6698 return false;
6699 }
6700 } finally {
6701 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006702 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006703 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006704
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006705 /**
6706 * Check if data is enabled for a specific reason
6707 * @param subId Subscription index
6708 * @param reason the reason the data enable change is taking place
6709 * @return {@code true} if the overall data is enabled; {@code false} if not.
6710 */
6711 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006712 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006713 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006714 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006716 try {
6717 mApp.enforceCallingOrSelfPermission(
6718 android.Manifest.permission.ACCESS_NETWORK_STATE,
6719 functionName);
6720 } catch (Exception e) {
6721 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6722 functionName);
6723 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006724 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006725 try {
6726 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006727 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006728 } catch (Exception e2) {
6729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006730 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006731 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006732 }
6733
6734
6735 final long identity = Binder.clearCallingIdentity();
6736 try {
6737 int phoneId = mSubscriptionController.getPhoneId(subId);
6738 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006739 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006740 + " reason=" + reason);
6741 }
6742 Phone phone = PhoneFactory.getPhone(phoneId);
6743 if (phone != null) {
6744 boolean retVal;
6745 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6746 retVal = phone.isUserDataEnabled();
6747 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006748 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006749 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006750 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006751 return retVal;
6752 } else {
6753 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006754 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006755 + subId + " retVal=false");
6756 }
6757 return false;
6758 }
6759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
6762 }
6763
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006764 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006765 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006766 if (uid == Process.PHONE_UID) {
6767 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6768 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006769 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6770 }
6771
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006772 //load access rules from carrier configs, and check those as well: b/139133814
6773 SubscriptionController subController = SubscriptionController.getInstance();
6774 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6775 || subController == null) return privilegeFromSim;
6776
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006777 PackageManager pkgMgr = phone.getContext().getPackageManager();
6778 String[] packages = pkgMgr.getPackagesForUid(uid);
6779
6780 final long identity = Binder.clearCallingIdentity();
6781 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006782 int subId = phone.getSubId();
6783 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6784 // A test override is in place for the privileges for this subId, so don't try to
6785 // read the subscription privileges.
6786 return privilegeFromSim;
6787 }
6788 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006789 SubscriptionManager subManager = (SubscriptionManager)
6790 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6791 for (String pkg : packages) {
6792 if (subManager.canManageSubscription(subInfo, pkg)) {
6793 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6794 }
6795 }
6796 return privilegeFromSim;
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
6799 }
6800 }
6801
6802 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6803 String pkgName) {
6804 //load access rules from carrier configs, and check those as well: b/139133814
6805 SubscriptionController subController = SubscriptionController.getInstance();
6806 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6807 || subController == null) return privilegeFromSim;
6808
6809 final long identity = Binder.clearCallingIdentity();
6810 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006811 int subId = phone.getSubId();
6812 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6813 // A test override is in place for the privileges for this subId, so don't try to
6814 // read the subscription privileges.
6815 return privilegeFromSim;
6816 }
6817 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006818 SubscriptionManager subManager = (SubscriptionManager)
6819 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6820 return subManager.canManageSubscription(subInfo, pkgName)
6821 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6822 } finally {
6823 Binder.restoreCallingIdentity(identity);
6824 }
6825 }
6826
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006827 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006828 public int getCarrierPrivilegeStatus(int subId) {
6829 final Phone phone = getPhone(subId);
6830 if (phone == null) {
6831 loge("getCarrierPrivilegeStatus: Invalid subId");
6832 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6833 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006834 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6835 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006836 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006837 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6838 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006839
6840 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006841 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006842 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006843 }
Junda Liu29340342014-07-10 15:23:27 -07006844
6845 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006846 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006847 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006848 final Phone phone = getPhone(subId);
6849 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006850 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006851 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6852 }
6853 UiccProfile profile =
6854 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6855 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006856 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006857 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6858 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006859 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006860 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006861 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006862 }
6863
6864 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006865 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006866 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006867 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006868 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006869 }
6870
6871 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006872 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6873 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006874 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006875 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6876 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006877 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006878 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006879 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006880 }
6881
6882 @Override
6883 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006884 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006885 if (TextUtils.isEmpty(pkgName))
6886 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006887 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6888 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006889 UiccPort port = UiccController.getInstance().getUiccPort(i);
6890 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006891 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006892 continue;
6893 }
6894
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006895 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006896 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006897 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006898 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6899 break;
6900 }
6901 }
6902
6903 return result;
Junda Liu29340342014-07-10 15:23:27 -07006904 }
Derek Tan89e89d42014-07-08 17:00:10 -07006905
6906 @Override
Junda Liue64de782015-04-16 17:19:16 -07006907 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006908 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006909 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6910 loge("phoneId " + phoneId + " is not valid.");
6911 return null;
6912 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006913 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6914 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006915 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006916 return null ;
6917 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006918 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006919 }
6920
Amith Yamasani6e118872016-02-19 12:53:51 -08006921 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006922 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006923 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006924 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006925 List<String> privilegedPackages = new ArrayList<>();
6926 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006927 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006928 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006929 if (port != null) {
6930 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006931 if (packages == null) {
6932 // Only check packages in user 0 for now
6933 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006934 PackageManager.MATCH_DISABLED_COMPONENTS
6935 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006936 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006937 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006938 }
6939 for (int p = packages.size() - 1; p >= 0; p--) {
6940 PackageInfo pkgInfo = packages.get(p);
6941 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006942 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006943 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006944 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006945 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006946 privilegedPackages.add(pkgInfo.packageName);
6947 }
6948 }
6949 }
6950 }
6951 return privilegedPackages;
6952 }
6953
chen xuf7e9fe82019-05-09 19:31:02 -07006954 @Override
6955 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006956 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6957
6958 final long identity = Binder.clearCallingIdentity();
6959
chen xuf7e9fe82019-05-09 19:31:02 -07006960 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006961 try {
6962 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6963 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6964 }
6965 } finally {
6966 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006967 }
6968 return privilegedPackages;
6969 }
6970
Wink Savilleb564aae2014-10-23 10:18:09 -07006971 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006972 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006973 UiccPort port = phone == null ? null : phone.getUiccPort();
6974 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006975 return null;
6976 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006977 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006978 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006979 return null;
6980 }
6981 return iccId;
6982 }
6983
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006984 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006985 public void setCallComposerStatus(int subId, int status) {
6986 enforceModifyPermission();
6987
6988 final long identity = Binder.clearCallingIdentity();
6989 try {
6990 Phone phone = getPhone(subId);
6991 if (phone != null) {
6992 Phone defaultPhone = phone.getImsPhone();
6993 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6994 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6995 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006996 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6997 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006998 }
6999 }
Shuo Qian284ae752020-12-22 19:10:14 -08007000 } catch (ImsException e) {
7001 throw new ServiceSpecificException(e.getCode());
7002 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007003 Binder.restoreCallingIdentity(identity);
7004 }
7005 }
7006
7007 @Override
7008 public int getCallComposerStatus(int subId) {
7009 enforceReadPrivilegedPermission("getCallComposerStatus");
7010
7011 final long identity = Binder.clearCallingIdentity();
7012 try {
7013 Phone phone = getPhone(subId);
7014 if (phone != null) {
7015 Phone defaultPhone = phone.getImsPhone();
7016 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7017 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7018 return imsPhone.getCallComposerStatus();
7019 }
7020 }
7021 } finally {
7022 Binder.restoreCallingIdentity(identity);
7023 }
7024 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7025 }
7026
7027 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007028 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7029 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007030 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007031 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 final String iccId = getIccId(subId);
7036 final Phone phone = getPhone(subId);
7037 if (phone == null) {
7038 return false;
7039 }
7040 final String subscriberId = phone.getSubscriberId();
7041
7042 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007043 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 + subscriberId + " to " + number);
7045 }
7046
7047 if (TextUtils.isEmpty(iccId)) {
7048 return false;
7049 }
7050
7051 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7052
7053 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7054 if (alphaTag == null) {
7055 editor.remove(alphaTagPrefKey);
7056 } else {
7057 editor.putString(alphaTagPrefKey, alphaTag);
7058 }
7059
7060 // Record both the line number and IMSI for this ICCID, since we need to
7061 // track all merged IMSIs based on line number
7062 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7063 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7064 if (number == null) {
7065 editor.remove(numberPrefKey);
7066 editor.remove(subscriberPrefKey);
7067 } else {
7068 editor.putString(numberPrefKey, number);
7069 editor.putString(subscriberPrefKey, subscriberId);
7070 }
7071
7072 editor.commit();
7073 return true;
7074 } finally {
7075 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007076 }
Derek Tan7226c842014-07-02 17:42:23 -07007077 }
7078
7079 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007080 public String getLine1NumberForDisplay(int subId, String callingPackage,
7081 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007082 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007084 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007085 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007086 return null;
7087 }
Derek Tan97ebb422014-09-05 16:55:38 -07007088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 String iccId = getIccId(subId);
7092 if (iccId != null) {
7093 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7094 if (DBG_MERGE) {
7095 log("getLine1NumberForDisplay returning "
7096 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7097 }
7098 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7101 return null;
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007104 }
Derek Tan7226c842014-07-02 17:42:23 -07007105 }
7106
7107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007108 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007111 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007112 return null;
7113 }
Derek Tan97ebb422014-09-05 16:55:38 -07007114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 final long identity = Binder.clearCallingIdentity();
7116 try {
7117 String iccId = getIccId(subId);
7118 if (iccId != null) {
7119 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7120 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7121 }
7122 return null;
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007125 }
Derek Tan7226c842014-07-02 17:42:23 -07007126 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007127
7128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007129 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7130 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007131 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7132 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007134 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007135 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007136 return null;
7137 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007138
Jordan Liub49b04b2019-05-06 14:45:15 -07007139 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7140 // the process, where TelephonyManager was instantiated.
7141 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007142 final long identity = Binder.clearCallingIdentity();
7143 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007144 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 final TelephonyManager tele = TelephonyManager.from(context);
7146 final SubscriptionManager sub = SubscriptionManager.from(context);
7147
7148 // Figure out what subscribers are currently active
7149 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150
Jordan Liub49b04b2019-05-06 14:45:15 -07007151 // Only consider subs which match the current subId
7152 // This logic can be simplified. See b/131189269 for progress.
7153 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007154 activeSubscriberIds.add(tele.getSubscriberId(subId));
7155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156
7157 // First pass, find a number override for an active subscriber
7158 String mergeNumber = null;
7159 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7160 for (String key : prefs.keySet()) {
7161 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7162 final String subscriberId = (String) prefs.get(key);
7163 if (activeSubscriberIds.contains(subscriberId)) {
7164 final String iccId = key.substring(
7165 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7166 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7167 mergeNumber = (String) prefs.get(numberKey);
7168 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007169 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 + " for active subscriber " + subscriberId);
7171 }
7172 if (!TextUtils.isEmpty(mergeNumber)) {
7173 break;
7174 }
7175 }
7176 }
7177 }
7178
7179 // Shortcut when no active merged subscribers
7180 if (TextUtils.isEmpty(mergeNumber)) {
7181 return null;
7182 }
7183
7184 // Second pass, find all subscribers under that line override
7185 final ArraySet<String> result = new ArraySet<>();
7186 for (String key : prefs.keySet()) {
7187 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7188 final String number = (String) prefs.get(key);
7189 if (mergeNumber.equals(number)) {
7190 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7191 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7192 final String subscriberId = (String) prefs.get(subscriberKey);
7193 if (!TextUtils.isEmpty(subscriberId)) {
7194 result.add(subscriberId);
7195 }
7196 }
7197 }
7198 }
7199
7200 final String[] resultArray = result.toArray(new String[result.size()]);
7201 Arrays.sort(resultArray);
7202 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007203 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7205 }
7206 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007207 } finally {
7208 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007209 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007210 }
7211
7212 @Override
zoey chen38003472019-12-13 17:16:31 +08007213 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7214 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007215
7216 final long identity = Binder.clearCallingIdentity();
7217 try {
7218 final TelephonyManager telephonyManager = mApp.getSystemService(
7219 TelephonyManager.class);
7220 String subscriberId = telephonyManager.getSubscriberId(subId);
7221 if (subscriberId == null) {
7222 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007223 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007224 + subId);
7225 }
7226 return null;
7227 }
7228
7229 final SubscriptionInfo info = SubscriptionController.getInstance()
7230 .getSubscriptionInfo(subId);
7231 final ParcelUuid groupUuid = info.getGroupUuid();
7232 // If it doesn't belong to any group, return just subscriberId of itself.
7233 if (groupUuid == null) {
7234 return new String[]{subscriberId};
7235 }
7236
7237 // Get all subscriberIds from the group.
7238 final List<String> mergedSubscriberIds = new ArrayList<>();
7239 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007240 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007241 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007242 for (SubscriptionInfo subInfo : groupInfos) {
7243 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7244 if (subscriberId != null) {
7245 mergedSubscriberIds.add(subscriberId);
7246 }
7247 }
7248
7249 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7250 } finally {
7251 Binder.restoreCallingIdentity(identity);
7252
7253 }
7254 }
7255
7256 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007257 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007258 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007259 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260
7261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 final Phone phone = getPhone(subId);
7264 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
7267 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007268 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007269
7270 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007271 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007272 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7273 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007274 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7275 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007276
7277 final long identity = Binder.clearCallingIdentity();
7278 try {
7279 final Phone phone = getPhone(subId);
7280 if (phone == null) {
7281 return false;
7282 }
7283 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7284 cdmaNonRoamingList);
7285 } finally {
7286 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007287 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007288 }
7289
7290 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007291 @Deprecated
7292 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7293 enforceModifyPermission();
7294
7295 int returnValue = 0;
7296 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007297 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007298 if(result.exception == null) {
7299 if (result.result != null) {
7300 byte[] responseData = (byte[])(result.result);
7301 if(responseData.length > oemResp.length) {
7302 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7303 responseData.length + "bytes. Buffer Size is " +
7304 oemResp.length + "bytes.");
7305 }
7306 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7307 returnValue = responseData.length;
7308 }
7309 } else {
7310 CommandException ex = (CommandException) result.exception;
7311 returnValue = ex.getCommandError().ordinal();
7312 if(returnValue > 0) returnValue *= -1;
7313 }
7314 } catch (RuntimeException e) {
7315 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7316 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7317 if(returnValue > 0) returnValue *= -1;
7318 }
7319
7320 return returnValue;
7321 }
7322
7323 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007324 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007325 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007326 try {
7327 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007328 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007329 mApp, phone.getSubId(), "getRadioAccessFamily");
7330 } catch (SecurityException e) {
7331 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7332 throw e;
7333 }
chen xub97461a2018-10-26 14:17:57 -07007334 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007335 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007336 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007338 final long identity = Binder.clearCallingIdentity();
7339 try {
chen xub97461a2018-10-26 14:17:57 -07007340 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007341 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007342 mApp, phone.getSubId(), "getRadioAccessFamily");
7343 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 } finally {
7345 Binder.restoreCallingIdentity(identity);
7346 }
chen xub97461a2018-10-26 14:17:57 -07007347 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007348 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007349
7350 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007351 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007352 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007353 try {
7354 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7355 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007356 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007357 }
7358 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007359 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007360 }
7361 RoleManager rm = mApp.getSystemService(RoleManager.class);
7362 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7363 if (!dialerRoleHolders.contains(callingPackage)) {
7364 throw new SecurityException("App must be the dialer role holder to"
7365 + " upload a call composer pic");
7366 }
7367
7368 Executors.newSingleThreadExecutor().execute(() -> {
7369 ByteArrayOutputStream output = new ByteArrayOutputStream(
7370 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7371 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7372 boolean readUntilEnd = false;
7373 int totalBytesRead = 0;
7374 byte[] buffer = new byte[16 * 1024];
7375 while (true) {
7376 int numRead;
7377 try {
7378 numRead = input.read(buffer);
7379 } catch (IOException e) {
7380 try {
7381 fd.checkError();
7382 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7383 null);
7384 } catch (IOException e1) {
7385 // This means that the other side closed explicitly with an error. If this
7386 // happens, log and ignore.
7387 loge("Remote end of call composer picture pipe closed: " + e1);
7388 }
7389 break;
7390 }
7391 if (numRead == -1) {
7392 readUntilEnd = true;
7393 break;
7394 }
7395 totalBytesRead += numRead;
7396 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7397 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7398 try {
7399 input.close();
7400 } catch (IOException e) {
7401 // ignore
7402 }
7403 break;
7404 }
7405 output.write(buffer, 0, numRead);
7406 }
7407 // Generally, the remote end will close the file descriptors. The only case where we
7408 // close is above, where the picture size is too big.
7409
7410 try {
7411 fd.checkError();
7412 } catch (IOException e) {
7413 loge("Remote end for call composer closed with an error: " + e);
7414 return;
7415 }
7416
Hall Liuaa4211e2021-01-20 15:43:39 -08007417 if (!readUntilEnd) {
7418 loge("Did not finish reading entire image; aborting");
7419 return;
7420 }
Hall Liu82694d52020-12-11 18:22:04 -08007421
Hall Liuaa4211e2021-01-20 15:43:39 -08007422 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7423 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7424 new CallComposerPictureTransfer.Factory() {},
7425 imageData,
7426 (result) -> {
7427 if (result.first != null) {
7428 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7429 Bundle outputResult = new Bundle();
7430 outputResult.putParcelable(
7431 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7432 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7433 outputResult);
7434 } else {
7435 callback.send(result.second, null);
7436 }
7437 }
7438 );
Hall Liu82694d52020-12-11 18:22:04 -08007439 });
7440 }
7441
7442 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007443 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007444 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007445 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446
7447 final long identity = Binder.clearCallingIdentity();
7448 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007449 ImsManager.getInstance(defaultPhone.getContext(),
7450 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 } finally {
7452 Binder.restoreCallingIdentity(identity);
7453 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007454 }
7455
7456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007457 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007458 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7460 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007461 return false;
7462 }
Svet Ganovb320e182015-04-16 12:30:10 -07007463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 final long identity = Binder.clearCallingIdentity();
7465 try {
7466 // Check the user preference and the system-level IMS setting. Even if the user has
7467 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7468 // In the long run, we may instead need to check if there exists a connection service
7469 // which can support video calling.
7470 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007471 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 return imsManager.isVtEnabledByPlatform()
7473 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7474 && imsManager.isVtEnabledByUser();
7475 } finally {
7476 Binder.restoreCallingIdentity(identity);
7477 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007478 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007479
Andrew Leea1239f22015-03-02 17:44:07 -08007480 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007481 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7482 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007484 mApp, subId, callingPackage, callingFeatureId,
7485 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 return false;
7487 }
7488
7489 final long identity = Binder.clearCallingIdentity();
7490 try {
7491 CarrierConfigManager configManager =
7492 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007493 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
7497 }
Andrew Leea1239f22015-03-02 17:44:07 -08007498 }
7499
7500 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007501 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007503 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 return false;
7505 }
7506
7507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 CarrierConfigManager configManager =
7510 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007511 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
7515 }
Andrew Leea1239f22015-03-02 17:44:07 -08007516 }
7517
Andrew Lee9431b832015-03-09 18:46:45 -07007518 @Override
7519 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007520 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007521 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007522 }
7523
7524 @Override
7525 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 final long identity = Binder.clearCallingIdentity();
7527 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007528 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
Andrew Lee9431b832015-03-09 18:46:45 -07007532 }
7533
Hall Liuf6668912018-10-31 17:05:23 -07007534 /**
7535 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7536 * support for the feature and device firmware support.
7537 *
7538 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7539 */
7540 @Override
7541 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007543 final Phone phone = getPhone(subscriptionId);
7544 if (phone == null) {
7545 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7546 return false;
7547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7551 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007552 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 return isCarrierSupported && isDeviceSupported;
7554 } finally {
7555 Binder.restoreCallingIdentity(identity);
7556 }
Hall Liu98187582018-01-22 19:15:32 -08007557 }
7558
Hall Liuf6668912018-10-31 17:05:23 -07007559 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007560 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7561 * RTT setting, will return true if the device and carrier both support RTT.
7562 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007563 */
7564 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 final long identity = Binder.clearCallingIdentity();
7566 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007567 boolean isRttSupported = isRttSupported(subscriptionId);
7568 boolean isUserRttSettingOn = Settings.Secure.getInt(
7569 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7570 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7571 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7572 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 } finally {
7574 Binder.restoreCallingIdentity(identity);
7575 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007576 }
7577
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007578 @Deprecated
7579 @Override
7580 public String getDeviceId(String callingPackage) {
7581 return getDeviceIdWithFeature(callingPackage, null);
7582 }
7583
Sanket Padawe7310cc72015-01-14 09:53:20 -08007584 /**
7585 * Returns the unique device ID of phone, for example, the IMEI for
7586 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7587 *
7588 * <p>Requires Permission:
7589 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7590 */
7591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007592 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007593 try {
7594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7595 } catch (SecurityException se) {
7596 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7597 throw new SecurityException("Package " + callingPackage + " does not belong to "
7598 + Binder.getCallingUid());
7599 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007600 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007601 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007602 return null;
7603 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007604 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007605 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007606 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007607 return null;
7608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609
7610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 return phone.getDeviceId();
7613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007616 }
7617
Ping Sunc67b7c22016-03-02 19:16:45 +08007618 /**
7619 * {@hide}
7620 * Returns the IMS Registration Status on a particular subid
7621 *
7622 * @param subId
7623 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007624 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007625 Phone phone = getPhone(subId);
7626 if (phone != null) {
7627 return phone.isImsRegistered();
7628 } else {
7629 return false;
7630 }
7631 }
7632
Santos Cordon7a1885b2015-02-03 11:15:19 -08007633 @Override
7634 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007635 final long identity = Binder.clearCallingIdentity();
7636 try {
7637 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
7640 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007641 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007642
Tyler Gunnf70ed162019-04-03 15:28:53 -07007643 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007644 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007645 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007647 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007648 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7649 }
7650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
7655 }
7656 }
7657
7658 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007659 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007660 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007661 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007662 mApp,
7663 subscriptionId,
7664 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007665 final long identity = Binder.clearCallingIdentity();
7666 try {
7667 Phone phone = getPhone(subscriptionId);
7668 if (phone == null) {
7669 return null;
7670 }
7671 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
7674 }
7675 }
7676
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007677 /**
7678 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007679 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007680 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681 final long identity = Binder.clearCallingIdentity();
7682 try {
7683 Phone phone = getPhone(subId);
7684 if (phone != null) {
7685 return phone.isWifiCallingEnabled();
7686 } else {
7687 return false;
7688 }
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007691 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007692 }
7693
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007694 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007695 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007696 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007697 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 final long identity = Binder.clearCallingIdentity();
7699 try {
7700 Phone phone = getPhone(subId);
7701 if (phone != null) {
7702 return phone.isVideoEnabled();
7703 } else {
7704 return false;
7705 }
7706 } finally {
7707 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007708 }
7709 }
7710
7711 /**
7712 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7713 * defined in {@link ImsRegistrationImplBase}.
7714 */
7715 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 final long identity = Binder.clearCallingIdentity();
7717 try {
7718 Phone phone = getPhone(subId);
7719 if (phone != null) {
7720 return phone.getImsRegistrationTech();
7721 } else {
7722 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7723 }
7724 } finally {
7725 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007726 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007727 }
7728
Stuart Scott8eef64f2015-04-08 15:13:54 -07007729 @Override
7730 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007731 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007732 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7733 return;
7734 }
Kai Shif70f46f2021-03-03 13:59:46 -08007735 Phone defaultPhone = getDefaultPhone();
7736 if (defaultPhone != null) {
7737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7738 mApp, getDefaultPhone().getSubId(), "factoryReset");
7739 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007740 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741
Svet Ganovcc087f82015-05-12 20:35:54 -07007742 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007743 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7744 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007745 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007746 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007747 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007748 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007749 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007750 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007751 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007752 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007753 // There has been issues when Sms raw table somehow stores orphan
7754 // fragments. They lead to garbled message when new fragments come
7755 // in and combined with those stale ones. In case this happens again,
7756 // user can reset all network settings which will clean up this table.
7757 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007758 // Clean up IMS settings as well here.
7759 int slotId = getSlotIndex(subId);
7760 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7761 ImsManager.getInstance(mApp, slotId).factoryReset();
7762 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007763
Kai Shif70f46f2021-03-03 13:59:46 -08007764 if (defaultPhone == null) {
7765 return;
7766 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007767 // Erase modem config if erase modem on network setting is enabled.
7768 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7769 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7770 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007771 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007772 }
Kai Shif70f46f2021-03-03 13:59:46 -08007773
7774 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007775 } finally {
7776 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007777 }
7778 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007779
SongFerngWangfd89b102021-05-27 22:44:54 +08007780 @VisibleForTesting
7781 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7782 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7783 return;
7784 }
7785 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7786 RILConstants.PREFERRED_NETWORK_MODE);
7787 SubscriptionManager.setSubscriptionProperty(subId,
7788 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7789 "user=" + defaultNetworkType);
7790 phone.loadAllowedNetworksFromSubscriptionDatabase();
7791 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7792 defaultNetworkType, null);
7793 }
7794
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007795 private void cleanUpSmsRawTable(Context context) {
7796 ContentResolver resolver = context.getContentResolver();
7797 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7798 resolver.delete(uri, null, null);
7799 }
7800
Narayan Kamath1c496c22015-04-16 14:40:19 +01007801 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007802 public String getSimLocaleForSubscriber(int subId) {
7803 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7804 final Phone phone = getPhone(subId);
7805 if (phone == null) {
7806 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007807 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 final long identity = Binder.clearCallingIdentity();
7810 try {
chen xu5d3637b2019-01-21 23:31:38 -08007811 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007812 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007813 if (info == null) {
7814 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7815 return null;
7816 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 // Try and fetch the locale from the carrier properties or from the SIM language
7818 // preferences (EF-PL and EF-LI)...
7819 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007821 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7822 if (localeFromDefaultSim != null) {
7823 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7824 if (DBG) log("Using locale from subId: " + subId + " locale: "
7825 + localeFromDefaultSim);
7826 return localeFromDefaultSim.toLanguageTag();
7827 } else {
7828 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 }
7830 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007831
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007832 // The SIM language preferences only store a language (e.g. fr = French), not an
7833 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7834 // the SIM and carrier preferences does not include a country we add the country
7835 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007836 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007838 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007839 return mccLocale.toLanguageTag();
7840 }
7841
7842 if (DBG) log("No locale found - returning null");
7843 return null;
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
7846 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007847 }
7848
7849 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007850 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007851 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007852 }
7853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854 /**
7855 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7856 */
7857 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007858 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007859 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007860 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007861
Chenjie Yu1ba97252018-01-11 18:16:20 -08007862 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007863 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007864
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007865 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007866 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7867 * representing the state of the modem.
7868 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007869 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7870 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007871 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007872 */
7873 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007874 public void requestModemActivityInfo(ResultReceiver result) {
7875 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007876 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007877
7878 final long identity = Binder.clearCallingIdentity();
7879 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007880 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007881 } finally {
7882 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007883 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007884 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007885
Siddharth Rayb8114062018-06-17 15:02:38 -07007886 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7887 // less than total activity duration.
7888 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7889 if (info == null) {
7890 return false;
7891 }
7892 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007893 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7894 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7895
Siddharth Rayb8114062018-06-17 15:02:38 -07007896 return (info.isValid()
7897 && (info.getSleepTimeMillis() <= activityDurationMs)
7898 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007899 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007900 && (totalTxTimeMs <= activityDurationMs));
7901 }
7902
Jack Yu85bd38a2015-11-09 11:34:32 -08007903 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007904 * Returns the service state information on specified subscription.
7905 */
7906 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007907 public ServiceState getServiceStateForSubscriber(int subId,
7908 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7909 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007910 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007911 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007912 return null;
7913 }
7914
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007915 boolean hasFinePermission = false;
7916 boolean hasCoarsePermission = false;
7917 if (!renounceFineLocationAccess) {
7918 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7919 LocationAccessPolicy.checkLocationPermission(mApp,
7920 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7921 .setCallingPackage(callingPackage)
7922 .setCallingFeatureId(callingFeatureId)
7923 .setCallingPid(Binder.getCallingPid())
7924 .setCallingUid(Binder.getCallingUid())
7925 .setMethod("getServiceStateForSubscriber")
7926 .setLogAsInfo(true)
7927 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7928 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7929 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7930 .build());
7931 hasFinePermission =
7932 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7933 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007934
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007935 if (!renounceCoarseLocationAccess) {
7936 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7937 LocationAccessPolicy.checkLocationPermission(mApp,
7938 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7939 .setCallingPackage(callingPackage)
7940 .setCallingFeatureId(callingFeatureId)
7941 .setCallingPid(Binder.getCallingPid())
7942 .setCallingUid(Binder.getCallingUid())
7943 .setMethod("getServiceStateForSubscriber")
7944 .setLogAsInfo(true)
7945 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7946 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7947 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7948 .build());
7949 hasCoarsePermission =
7950 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7951 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007952
Jack Yu479f40e2020-10-27 21:29:25 -07007953 final Phone phone = getPhone(subId);
7954 if (phone == null) {
7955 return null;
7956 }
7957
Jordan Liu0f2bc442020-11-18 16:47:37 -08007958 final long identity = Binder.clearCallingIdentity();
7959
Jack Yu479f40e2020-10-27 21:29:25 -07007960 boolean isCallingPackageDataService = phone.getDataServicePackages()
7961 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007963 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7964 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7965 Rlog.d(LOG_TAG,
7966 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7967 return null;
7968 }
7969
Hall Liuf19c44f2018-11-27 14:38:17 -08007970 ServiceState ss = phone.getServiceState();
7971
7972 // Scrub out the location info in ServiceState depending on what level of access
7973 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007974 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007975 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7976 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 } finally {
7978 Binder.restoreCallingIdentity(identity);
7979 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007980 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007981
7982 /**
7983 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7984 *
7985 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7986 * voicemail ringtone.
7987 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7988 * PhoneAccount.
7989 */
7990 @Override
7991 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 final long identity = Binder.clearCallingIdentity();
7993 try {
7994 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7995 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007996 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007999 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8000 } finally {
8001 Binder.restoreCallingIdentity(identity);
8002 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008003 }
8004
8005 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008006 * Sets the per-account voicemail ringtone.
8007 *
8008 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8009 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8010 *
8011 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8012 * voicemail ringtone.
8013 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8014 * PhoneAccount.
8015 */
8016 @Override
8017 public void setVoicemailRingtoneUri(String callingPackage,
8018 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008019 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008020 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008021 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8022 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8024 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8025 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008027
8028 final long identity = Binder.clearCallingIdentity();
8029 try {
8030 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8031 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008032 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008033 }
8034 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008037 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008038 }
8039
8040 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008041 * Returns whether vibration is set for voicemail notification in Phone settings.
8042 *
8043 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8044 * voicemail vibration setting.
8045 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8046 */
8047 @Override
8048 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 final long identity = Binder.clearCallingIdentity();
8050 try {
8051 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8052 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008053 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
8059 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008060 }
8061
Youhan Wange64578a2016-05-02 15:32:42 -07008062 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008063 * Sets the per-account voicemail vibration.
8064 *
8065 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8066 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8067 *
8068 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8069 * voicemail vibration setting.
8070 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8071 * specific PhoneAccount.
8072 */
8073 @Override
8074 public void setVoicemailVibrationEnabled(String callingPackage,
8075 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008076 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008077 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008078 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8079 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8081 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8082 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008083 }
8084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 final long identity = Binder.clearCallingIdentity();
8086 try {
8087 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8088 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008089 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 }
8091 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008094 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008095 }
8096
8097 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008098 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8099 *
8100 * @throws SecurityException if the caller does not have the required permission
8101 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008102 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008103 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008104 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008105 }
8106
8107 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008108 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8109 * permission.
8110 *
8111 * @throws SecurityException if the caller does not have the required permission
8112 */
8113 private void enforceSendSmsPermission() {
8114 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8115 }
8116
8117 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008118 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008119 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008120 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008121 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008122 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123 final long identity = Binder.clearCallingIdentity();
8124 try {
8125 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008126 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 if (componentName == null) {
8128 throw new SecurityException(
8129 "Caller not current active visual voicemail package[null]");
8130 }
8131 String vvmPackage = componentName.getPackageName();
8132 if (!callingPackage.equals(vvmPackage)) {
8133 throw new SecurityException("Caller not current active visual voicemail package["
8134 + vvmPackage + "]");
8135 }
8136 } finally {
8137 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008138 }
8139 }
8140
8141 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008142 * Return the application ID for the app type.
8143 *
8144 * @param subId the subscription ID that this request applies to.
8145 * @param appType the uicc app type.
8146 * @return Application ID for specificied app type, or null if no uicc.
8147 */
8148 @Override
8149 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008150 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008151 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152
8153 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008154 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155 if (phone == null) {
8156 return null;
8157 }
8158 String aid = null;
8159 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008160 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 .getApplicationByType(appType).getAid();
8162 } catch (Exception e) {
8163 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8164 }
8165 return aid;
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008168 }
Youhan Wange64578a2016-05-02 15:32:42 -07008169 }
8170
Youhan Wang4001d252016-05-11 10:29:41 -07008171 /**
8172 * Return the Electronic Serial Number.
8173 *
8174 * @param subId the subscription ID that this request applies to.
8175 * @return ESN or null if error.
8176 */
8177 @Override
8178 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008179 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008180 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181
8182 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008183 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 if (phone == null) {
8185 return null;
8186 }
8187 String esn = null;
8188 try {
8189 esn = phone.getEsn();
8190 } catch (Exception e) {
8191 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8192 }
8193 return esn;
8194 } finally {
8195 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008196 }
Youhan Wang4001d252016-05-11 10:29:41 -07008197 }
8198
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008199 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008200 * Return the Preferred Roaming List Version.
8201 *
8202 * @param subId the subscription ID that this request applies to.
8203 * @return PRLVersion or null if error.
8204 */
8205 @Override
8206 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008207 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008208 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209
8210 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008211 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212 if (phone == null) {
8213 return null;
8214 }
8215 String cdmaPrlVersion = null;
8216 try {
8217 cdmaPrlVersion = phone.getCdmaPrlVersion();
8218 } catch (Exception e) {
8219 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8220 }
8221 return cdmaPrlVersion;
8222 } finally {
8223 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008224 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008225 }
8226
8227 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008228 * Get snapshot of Telephony histograms
8229 * @return List of Telephony histograms
8230 * @hide
8231 */
8232 @Override
8233 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8235 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236
8237 final long identity = Binder.clearCallingIdentity();
8238 try {
8239 return RIL.getTelephonyRILTimingHistograms();
8240 } finally {
8241 Binder.restoreCallingIdentity(identity);
8242 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008243 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008244
8245 /**
8246 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008247 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8248 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008249 * Require system privileges. In the future we may add this to carrier APIs.
8250 *
Michele Berionne482f8202018-11-27 18:57:59 -08008251 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008252 */
8253 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008254 @TelephonyManager.SetCarrierRestrictionResult
8255 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008256 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008257 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008258
Michele Berionne482f8202018-11-27 18:57:59 -08008259 if (carrierRestrictionRules == null) {
8260 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008261 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 final long identity = Binder.clearCallingIdentity();
8264 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008265 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008266 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267 } finally {
8268 Binder.restoreCallingIdentity(identity);
8269 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008270 }
8271
8272 /**
8273 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008274 * Get the allowed carrier list and the excluded carrier list, including the priority between
8275 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008276 * Require system privileges. In the future we may add this to carrier APIs.
8277 *
Michele Berionne482f8202018-11-27 18:57:59 -08008278 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008279 */
8280 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008281 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008282 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008283 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284
8285 final long identity = Binder.clearCallingIdentity();
8286 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008287 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8288 if (response instanceof CarrierRestrictionRules) {
8289 return (CarrierRestrictionRules) response;
8290 }
8291 // Response is an Exception of some kind,
8292 // which is signalled to the user as a NULL retval
8293 return null;
8294 } catch (Exception e) {
8295 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8296 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 } finally {
8298 Binder.restoreCallingIdentity(identity);
8299 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008300 }
8301
fionaxu59545b42016-05-25 15:53:37 -07008302 /**
fionaxu59545b42016-05-25 15:53:37 -07008303 * Action set from carrier signalling broadcast receivers to enable/disable radio
8304 * @param subId the subscription ID that this action applies to.
8305 * @param enabled control enable or disable radio.
8306 * {@hide}
8307 */
8308 @Override
8309 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8310 enforceModifyPermission();
8311 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312
8313 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008314 if (phone == null) {
8315 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8316 return;
8317 }
8318 try {
8319 phone.carrierActionSetRadioEnabled(enabled);
8320 } catch (Exception e) {
8321 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 } finally {
8323 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008324 }
8325 }
8326
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008327 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008328 * Enable or disable Voice over NR (VoNR)
8329 * @param subId the subscription ID that this action applies to.
8330 * @param enabled enable or disable VoNR.
8331 * @return operation result.
8332 */
8333 @Override
8334 public int setVoNrEnabled(int subId, boolean enabled) {
8335 enforceModifyPermission();
8336 final Phone phone = getPhone(subId);
8337
8338 final long identity = Binder.clearCallingIdentity();
8339 if (phone == null) {
8340 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8341 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8342 }
8343
8344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8345 try {
8346 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8347 workSource);
8348 if (DBG) log("setVoNrEnabled result: " + result);
8349 return result;
8350 } finally {
8351 Binder.restoreCallingIdentity(identity);
8352 }
8353 }
8354
8355 /**
8356 * Is voice over NR enabled
8357 * @return true if VoNR is enabled else false
8358 */
8359 @Override
8360 public boolean isVoNrEnabled(int subId) {
8361 enforceReadPrivilegedPermission("isVoNrEnabled");
8362 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8363 final long identity = Binder.clearCallingIdentity();
8364 try {
8365 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8366 null, subId, workSource);
8367 if (DBG) log("isVoNrEnabled: " + isEnabled);
8368 return isEnabled;
8369 } finally {
8370 Binder.restoreCallingIdentity(identity);
8371 }
8372 }
8373
8374 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008375 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8376 * network status based on which carrier apps could apply actions accordingly,
8377 * enable/disable default url handler for example.
8378 *
8379 * @param subId the subscription ID that this action applies to.
8380 * @param report control start/stop reporting the default network status.
8381 * {@hide}
8382 */
8383 @Override
8384 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8385 enforceModifyPermission();
8386 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008387
8388 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008389 if (phone == null) {
8390 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8391 return;
8392 }
8393 try {
8394 phone.carrierActionReportDefaultNetworkStatus(report);
8395 } catch (Exception e) {
8396 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008397 } finally {
8398 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008399 }
8400 }
8401
8402 /**
fionaxud9622282017-07-17 17:51:30 -07008403 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8404 * @param subId the subscription ID that this action applies to.
8405 * {@hide}
8406 */
8407 @Override
8408 public void carrierActionResetAll(int subId) {
8409 enforceModifyPermission();
8410 final Phone phone = getPhone(subId);
8411 if (phone == null) {
8412 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8413 return;
8414 }
8415 try {
8416 phone.carrierActionResetAll();
8417 } catch (Exception e) {
8418 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8419 }
8420 }
8421
8422 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008423 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8424 * bug report is being generated.
8425 */
8426 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008427 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008428 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8429 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008430 writer.println("Permission Denial: can't dump Phone from pid="
8431 + Binder.getCallingPid()
8432 + ", uid=" + Binder.getCallingUid()
8433 + "without permission "
8434 + android.Manifest.permission.DUMP);
8435 return;
8436 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008437 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008438 }
Jack Yueb89b242016-06-22 13:27:47 -07008439
Brad Ebingerdac2f002018-04-03 15:17:52 -07008440 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008441 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8442 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8443 @NonNull String[] args) {
8444 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8445 this, in.getFileDescriptor(), out.getFileDescriptor(),
8446 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008447 }
8448
Jack Yueb89b242016-06-22 13:27:47 -07008449 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008450 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008451 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008452 * @param reason the reason the data enable change is taking place
8453 * @param enabled True if enabling the data, otherwise disabling.
8454 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008455 */
8456 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008457 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008458 boolean enabled) {
8459 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8460 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8461 try {
8462 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008463 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008464 } catch (SecurityException se) {
8465 enforceModifyPermission();
8466 }
8467 } else {
8468 enforceModifyPermission();
8469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470
8471 final long identity = Binder.clearCallingIdentity();
8472 try {
8473 Phone phone = getPhone(subId);
8474 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008475 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8476 phone.carrierActionSetMeteredApnsEnabled(enabled);
8477 } else {
8478 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480 }
8481 } finally {
8482 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008483 }
8484 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008485
8486 /**
8487 * Get Client request stats
8488 * @return List of Client Request Stats
8489 * @hide
8490 */
8491 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008492 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8493 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008495 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008496 return null;
8497 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008498 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 if (phone != null) {
8503 return phone.getClientRequestStats();
8504 }
8505
8506 return null;
8507 } finally {
8508 Binder.restoreCallingIdentity(identity);
8509 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008510 }
8511
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008512 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008513 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008514 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008515 }
Jack Yueb4124c2017-02-16 15:32:43 -08008516
8517 /**
Grace Chen70990072017-03-24 17:21:30 -07008518 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008519 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008520 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008521 * @param state State of SIM (power down, power up, pass through)
8522 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8523 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8524 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008525 *
8526 **/
8527 @Override
Grace Chen70990072017-03-24 17:21:30 -07008528 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008529 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008530 Phone phone = PhoneFactory.getPhone(slotIndex);
8531
vagdeviaf9a5b92018-08-15 16:01:53 -07008532 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008534 final long identity = Binder.clearCallingIdentity();
8535 try {
8536 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008537 phone.setSimPowerState(state, null, workSource);
8538 }
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
8541 }
8542 }
8543
8544 /**
8545 * Set SIM card power state.
8546 *
8547 * @param slotIndex SIM slot id.
8548 * @param state State of SIM (power down, power up, pass through)
8549 * @param callback callback to trigger after success or failure
8550 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8551 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8552 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8553 *
8554 **/
8555 @Override
8556 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8557 IIntegerConsumer callback) {
8558 enforceModifyPermission();
8559 Phone phone = PhoneFactory.getPhone(slotIndex);
8560
8561 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8562
8563 final long identity = Binder.clearCallingIdentity();
8564 try {
8565 if (phone != null) {
8566 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8567 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008568 }
8569 } finally {
8570 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008571 }
8572 }
Shuo Qiandd210312017-04-12 22:11:33 +00008573
Tyler Gunn65d45c22017-06-05 11:22:26 -07008574 private boolean isUssdApiAllowed(int subId) {
8575 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008576 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008577 if (configManager == null) {
8578 return false;
8579 }
8580 PersistableBundle pb = configManager.getConfigForSubId(subId);
8581 if (pb == null) {
8582 return false;
8583 }
8584 return pb.getBoolean(
8585 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8586 }
8587
Shuo Qiandd210312017-04-12 22:11:33 +00008588 /**
8589 * Check if phone is in emergency callback mode
8590 * @return true if phone is in emergency callback mode
8591 * @param subId sub id
8592 */
goneil9c5f4872017-12-05 14:07:56 -08008593 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008594 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008595 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008596 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597
8598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 if (phone != null) {
8601 return phone.isInEcm();
8602 } else {
8603 return false;
8604 }
8605 } finally {
8606 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008607 }
8608 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008609
8610 /**
8611 * Get the current signal strength information for the given subscription.
8612 * Because this information is not updated when the device is in a low power state
8613 * it should not be relied-upon to be current.
8614 * @param subId Subscription index
8615 * @return the most recent cached signal strength info from the modem
8616 */
8617 @Override
8618 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619 final long identity = Binder.clearCallingIdentity();
8620 try {
8621 Phone p = getPhone(subId);
8622 if (p == null) {
8623 return null;
8624 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008626 return p.getSignalStrength();
8627 } finally {
8628 Binder.restoreCallingIdentity(identity);
8629 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008630 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008631
Pengquan Meng77b7f132018-08-22 14:49:57 -07008632 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008633 * Get the current modem radio state for the given slot.
8634 * @param slotIndex slot index.
8635 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008636 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008637 * @return the current radio power state from the modem
8638 */
8639 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008640 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008641 Phone phone = PhoneFactory.getPhone(slotIndex);
8642 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008643 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8644 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008645 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8646 }
8647
8648 final long identity = Binder.clearCallingIdentity();
8649 try {
8650 return phone.getRadioPowerState();
8651 } finally {
8652 Binder.restoreCallingIdentity(identity);
8653 }
8654 }
8655 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8656 }
8657
8658 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008659 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8660 *
8661 * <p>Requires one of the following permissions:
8662 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008663 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008664 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8665 * privileges.
8666 *
8667 * @param subId subscription id
8668 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8669 * {@code false}.
8670 */
8671 @Override
8672 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008673 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008674 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008675 try {
8676 mApp.enforceCallingOrSelfPermission(
8677 android.Manifest.permission.ACCESS_NETWORK_STATE,
8678 functionName);
8679 } catch (Exception e) {
8680 mApp.enforceCallingOrSelfPermission(
8681 permission.READ_BASIC_PHONE_STATE, functionName);
8682 }
Shuo Qian093013d2020-08-13 15:42:55 -07008683 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008684 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008685 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008686 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008687
Pengquan Menga1bb6272018-09-06 09:59:22 -07008688 boolean isEnabled = false;
8689 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008690 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008691 Phone phone = getPhone(subId);
8692 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008693 } finally {
8694 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008695 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008696 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008697 }
8698
8699
8700 /**
8701 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8702 *
8703 * <p> Requires permission:
8704 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8705 * privileges.
8706 *
8707 * @param subId subscription id
8708 * @param isEnabled {@code true} means enable, {@code false} means disable.
8709 */
8710 @Override
8711 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8713 mApp, subId, "setDataRoamingEnabled");
8714
Pengquan Menga1bb6272018-09-06 09:59:22 -07008715 final long identity = Binder.clearCallingIdentity();
8716 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008717 Phone phone = getPhone(subId);
8718 if (phone != null) {
8719 phone.setDataRoamingEnabled(isEnabled);
8720 }
8721 } finally {
8722 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008723 }
8724 }
8725
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008726 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008727 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008728 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008729 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008730 mApp, subId, "isManualNetworkSelectionAllowed");
8731
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008732 boolean isAllowed = true;
8733 final long identity = Binder.clearCallingIdentity();
8734 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008735 Phone phone = getPhone(subId);
8736 if (phone != null) {
8737 isAllowed = phone.isCspPlmnEnabled();
8738 }
8739 } finally {
8740 Binder.restoreCallingIdentity(identity);
8741 }
8742 return isAllowed;
8743 }
8744
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008745 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8746 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8747 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8748 // Update each UiccPort object based on privilege access
8749 UiccPort[] uiccPorts = card.getUiccPortList();
8750 for (UiccPort port : uiccPorts) {
8751 UiccProfile profile = port.getUiccProfile();
8752 if (profile == null ||
8753 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8754 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8755 return false;
8756 }
8757 }
8758 return true;
8759 }
8760
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008761 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008762 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008763 // Verify that tha callingPackage belongs to the calling UID
8764 mApp.getSystemService(AppOpsManager.class)
8765 .checkPackage(Binder.getCallingUid(), callingPackage);
8766
Jordan Liu1e142fc2019-04-22 15:10:43 -07008767 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008768 try {
8769 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008770 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008771 } catch (SecurityException e) {
8772 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8773 // has carrier privileges on an active UICC
8774 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8775 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008776 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008777 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008778 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008779
8780 final long identity = Binder.clearCallingIdentity();
8781 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008782 UiccController uiccController = UiccController.getInstance();
8783 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008784 if (hasReadPermission) {
8785 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008786 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008787
8788 // Remove private info if the caller doesn't have access
8789 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8790 for (UiccCardInfo cardInfo : cardInfos) {
8791 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8792 // is available
8793 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008794 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8795 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8796 if (card == null || card.getUiccPortList().length == 0) {
8797 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008798 filteredInfos.add(cardInfo.getUnprivileged());
8799 continue;
8800 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008801
8802 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008803 filteredInfos.add(cardInfo);
8804 } else {
8805 filteredInfos.add(cardInfo.getUnprivileged());
8806 }
8807 }
8808 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008809 } finally {
8810 Binder.restoreCallingIdentity(identity);
8811 }
8812 }
8813
8814 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008815 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008816 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008818 final long identity = Binder.clearCallingIdentity();
8819 try {
8820 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8821 if (slots == null) {
8822 Rlog.i(LOG_TAG, "slots is null.");
8823 return null;
8824 }
8825
8826 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8827 for (int i = 0; i < slots.length; i++) {
8828 UiccSlot slot = slots[i];
8829 if (slot == null) {
8830 continue;
8831 }
8832
Jordan Liu7be7e652019-05-06 18:55:02 +00008833 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008834 UiccCard card = slot.getUiccCard();
8835 if (card != null) {
8836 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008837 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008838 cardId = slot.getEid();
8839 if (TextUtils.isEmpty(cardId)) {
8840 cardId = slot.getIccId();
8841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008842 }
8843
Jordan Liu857451f2019-05-09 16:35:35 -07008844 if (cardId != null) {
8845 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8846 // if cardId is an EID, it's all digits so this is fine
8847 cardId = IccUtils.stripTrailingFs(cardId);
8848 }
8849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008850 int cardState = 0;
8851 switch (slot.getCardState()) {
8852 case CARDSTATE_ABSENT:
8853 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8854 break;
8855 case CARDSTATE_PRESENT:
8856 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8857 break;
8858 case CARDSTATE_ERROR:
8859 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8860 break;
8861 case CARDSTATE_RESTRICTED:
8862 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8863 break;
8864 default:
8865 break;
8866
8867 }
8868
8869 infos[i] = new UiccSlotInfo(
8870 slot.isActive(),
8871 slot.isEuicc(),
8872 cardId,
8873 cardState,
8874 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008875 slot.isExtendedApduSupported(),
8876 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008877 }
8878 return infos;
8879 } finally {
8880 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008881 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008882 }
8883
8884 @Override
8885 public boolean switchSlots(int[] physicalSlots) {
8886 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008887
8888 final long identity = Binder.clearCallingIdentity();
8889 try {
8890 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8891 } finally {
8892 Binder.restoreCallingIdentity(identity);
8893 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008894 }
Jack Yu4c988042018-02-27 15:30:01 -08008895
8896 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008897 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008898 final long identity = Binder.clearCallingIdentity();
8899 try {
8900 return UiccController.getInstance().getCardIdForDefaultEuicc();
8901 } finally {
8902 Binder.restoreCallingIdentity(identity);
8903 }
8904 }
8905
Pengquan Meng85728fb2018-03-12 16:31:21 -07008906 /**
goneil47ffb6e2018-04-06 15:40:58 -07008907 * A test API to reload the UICC profile.
8908 *
8909 * <p>Requires that the calling app has permission
8910 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8911 * @hide
8912 */
8913 @Override
8914 public void refreshUiccProfile(int subId) {
8915 enforceModifyPermission();
8916
8917 final long identity = Binder.clearCallingIdentity();
8918 try {
8919 Phone phone = getPhone(subId);
8920 if (phone == null) {
8921 return;
8922 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008923 UiccPort uiccPort = phone.getUiccPort();
8924 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008925 return;
8926 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008927 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008928 if (uiccProfile == null) {
8929 return;
8930 }
8931 uiccProfile.refresh();
8932 } finally {
8933 Binder.restoreCallingIdentity(identity);
8934 }
8935 }
8936
8937 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008938 * Returns false if the mobile data is disabled by default, otherwise return true.
8939 */
8940 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008941 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008942 }
8943
8944 /**
8945 * Returns true if the data roaming is enabled by default, i.e the system property
8946 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8947 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8948 */
8949 private boolean getDefaultDataRoamingEnabled(int subId) {
8950 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008951 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008952 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008953 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8954 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8955 return isDataRoamingEnabled;
8956 }
8957
8958 /**
8959 * Returns the default network type for the given {@code subId}, if the default network type is
8960 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8961 */
8962 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008963 List<Integer> list = TelephonyProperties.default_network();
8964 int phoneId = mSubscriptionController.getPhoneId(subId);
8965 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8966 return list.get(phoneId);
8967 }
8968 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008969 }
fionaxua13278b2018-03-21 00:08:13 -07008970
8971 @Override
8972 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008973 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975
8976 final long identity = Binder.clearCallingIdentity();
8977 try {
8978 final Phone phone = getPhone(subId);
8979 if (phone == null) {
8980 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8981 return;
8982 }
chen xueaba88a2019-03-15 13:15:10 -07008983 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8984 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008985 if (carrierPrivilegeRules == null) {
8986 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8987 } else {
8988 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008990 } finally {
8991 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008992 }
fionaxua13278b2018-03-21 00:08:13 -07008993 }
8994
8995 @Override
8996 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008997 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008998
8999 final long identity = Binder.clearCallingIdentity();
9000 try {
9001 final Phone phone = getPhone(subId);
9002 if (phone == null) {
9003 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9004 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9005 }
9006 return phone.getCarrierIdListVersion();
9007 } finally {
9008 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009009 }
fionaxua13278b2018-03-21 00:08:13 -07009010 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009011
9012 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009013 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9014 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009016 mApp, subId, callingPackage, callingFeatureId,
9017 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009018 return -1;
9019 }
9020
9021 final long identity = Binder.clearCallingIdentity();
9022 try {
9023 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9024 } finally {
9025 Binder.restoreCallingIdentity(identity);
9026 }
9027 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009028
9029 @Override
9030 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009031 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009032 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009033 mApp, subId, "getCdmaRoamingMode");
9034
9035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9038 } finally {
9039 Binder.restoreCallingIdentity(identity);
9040 }
9041 }
9042
9043 @Override
9044 public boolean setCdmaRoamingMode(int subId, int mode) {
9045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9046 mApp, subId, "setCdmaRoamingMode");
9047
9048 final long identity = Binder.clearCallingIdentity();
9049 try {
9050 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9051 } finally {
9052 Binder.restoreCallingIdentity(identity);
9053 }
9054 }
9055
9056 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009057 public int getCdmaSubscriptionMode(int subId) {
9058 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009059 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009060 mApp, subId, "getCdmaSubscriptionMode");
9061
9062 final long identity = Binder.clearCallingIdentity();
9063 try {
9064 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9065 } finally {
9066 Binder.restoreCallingIdentity(identity);
9067 }
9068 }
9069
9070 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009071 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9073 mApp, subId, "setCdmaSubscriptionMode");
9074
9075 final long identity = Binder.clearCallingIdentity();
9076 try {
9077 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9078 } finally {
9079 Binder.restoreCallingIdentity(identity);
9080 }
9081 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009082
sqianc5eccab2018-10-19 18:46:41 -07009083 @Override
sqian8c685422019-02-22 15:55:18 -08009084 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009085 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009087 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9088 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009089 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9090 }
9091 final long identity = Binder.clearCallingIdentity();
9092 try {
sqian854d44b2018-12-12 16:48:18 -08009093 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9094 for (Phone phone: PhoneFactory.getPhones()) {
9095 if (phone.getEmergencyNumberTracker() != null
9096 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9097 emergencyNumberListInternal.put(
9098 phone.getSubId(),
9099 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9100 }
sqian11b7a0e2018-12-05 18:48:28 -08009101 }
sqian854d44b2018-12-12 16:48:18 -08009102 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009103 } finally {
9104 Binder.restoreCallingIdentity(identity);
9105 }
sqianc5eccab2018-10-19 18:46:41 -07009106 }
9107
9108 @Override
sqian8c685422019-02-22 15:55:18 -08009109 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009110 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009111 if (!exactMatch) {
9112 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009113 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009114 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009115 }
9116 final long identity = Binder.clearCallingIdentity();
9117 try {
sqian854d44b2018-12-12 16:48:18 -08009118 for (Phone phone: PhoneFactory.getPhones()) {
9119 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009120 && phone.getEmergencyNumberTracker()
9121 .isEmergencyNumber(number, exactMatch)) {
9122 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009123 }
sqian11b7a0e2018-12-05 18:48:28 -08009124 }
9125 return false;
9126 } finally {
9127 Binder.restoreCallingIdentity(identity);
9128 }
9129 }
9130
sqianf4ca7ed2019-01-15 18:32:07 -08009131 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009132 * Start emergency callback mode for GsmCdmaPhone for testing.
9133 */
9134 @Override
9135 public void startEmergencyCallbackMode() {
9136 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9137 "startEmergencyCallbackMode");
9138 enforceModifyPermission();
9139 final long identity = Binder.clearCallingIdentity();
9140 try {
9141 for (Phone phone : PhoneFactory.getPhones()) {
9142 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9143 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9144 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9145 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9146 gsmCdmaPhone.obtainMessage(
9147 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9148 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9149 }
9150 }
9151 } finally {
9152 Binder.restoreCallingIdentity(identity);
9153 }
9154 }
9155
9156 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009157 * Update emergency number list for test mode.
9158 */
9159 @Override
9160 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9161 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9162 "updateEmergencyNumberListTestMode");
9163
9164 final long identity = Binder.clearCallingIdentity();
9165 try {
9166 for (Phone phone: PhoneFactory.getPhones()) {
9167 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9168 if (tracker != null) {
9169 tracker.executeEmergencyNumberTestModeCommand(action, num);
9170 }
9171 }
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
9175 }
9176
9177 /**
9178 * Get the full emergency number list for test mode.
9179 */
9180 @Override
9181 public List<String> getEmergencyNumberListTestMode() {
9182 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9183 "getEmergencyNumberListTestMode");
9184
9185 final long identity = Binder.clearCallingIdentity();
9186 try {
9187 Set<String> emergencyNumbers = new HashSet<>();
9188 for (Phone phone: PhoneFactory.getPhones()) {
9189 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9190 if (tracker != null) {
9191 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9192 emergencyNumbers.add(num.getNumber());
9193 }
9194 }
9195 }
9196 return new ArrayList<>(emergencyNumbers);
9197 } finally {
9198 Binder.restoreCallingIdentity(identity);
9199 }
9200 }
9201
chen xud6b45bd2018-10-30 22:27:10 -07009202 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009203 public int getEmergencyNumberDbVersion(int subId) {
9204 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9205
9206 final long identity = Binder.clearCallingIdentity();
9207 try {
9208 final Phone phone = getPhone(subId);
9209 if (phone == null) {
9210 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9211 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9212 }
9213 return phone.getEmergencyNumberDbVersion();
9214 } finally {
9215 Binder.restoreCallingIdentity(identity);
9216 }
9217 }
9218
9219 @Override
9220 public void notifyOtaEmergencyNumberDbInstalled() {
9221 enforceModifyPermission();
9222
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
9225 for (Phone phone: PhoneFactory.getPhones()) {
9226 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9227 if (tracker != null) {
9228 tracker.updateOtaEmergencyNumberDatabase();
9229 }
9230 }
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 }
9235
9236 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009237 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009238 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) {
Shuo Qianc373f112020-03-05 17:55:34 -08009245 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9246 }
9247 }
9248 } finally {
9249 Binder.restoreCallingIdentity(identity);
9250 }
9251 }
9252
9253 @Override
9254 public void resetOtaEmergencyNumberDbFilePath() {
9255 enforceActiveEmergencySessionPermission();
9256
9257 final long identity = Binder.clearCallingIdentity();
9258 try {
9259 for (Phone phone: PhoneFactory.getPhones()) {
9260 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9261 if (tracker != null) {
9262 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009263 }
9264 }
9265 } finally {
9266 Binder.restoreCallingIdentity(identity);
9267 }
9268 }
9269
9270 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009271 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9272 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9273 Phone phone = getPhone(subId);
9274 if (phone == null) {
9275 return null;
9276 }
9277 final long identity = Binder.clearCallingIdentity();
9278 try {
9279 UiccProfile profile = UiccController.getInstance()
9280 .getUiccProfileForPhone(phone.getPhoneId());
9281 if (profile != null) {
9282 return profile.getCertsFromCarrierPrivilegeAccessRules();
9283 }
9284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 return null;
9288 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009289
9290 /**
9291 * Enable or disable a modem stack.
9292 */
9293 @Override
9294 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9295 enforceModifyPermission();
9296
9297 final long identity = Binder.clearCallingIdentity();
9298 try {
9299 Phone phone = PhoneFactory.getPhone(slotIndex);
9300 if (phone == null) {
9301 return false;
9302 } else {
9303 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9304 }
9305 } finally {
9306 Binder.restoreCallingIdentity(identity);
9307 }
9308 }
Michelecea4cf22018-12-21 15:00:11 -08009309
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009310 /**
9311 * Whether a modem stack is enabled or not.
9312 */
9313 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009314 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9315 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009316 Phone phone = PhoneFactory.getPhone(slotIndex);
9317 if (phone == null) return false;
9318
9319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009320 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9321 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009322 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9323 }
9324
9325 final long identity = Binder.clearCallingIdentity();
9326 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009327 try {
9328 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9329 } catch (NoSuchElementException ex) {
9330 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9331 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009332 } finally {
9333 Binder.restoreCallingIdentity(identity);
9334 }
9335 }
9336
Michelecea4cf22018-12-21 15:00:11 -08009337 @Override
Michele0ea7d782019-03-19 14:58:42 -07009338 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009339 enforceModifyPermission();
9340
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
9343 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009344 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009345 .commit();
9346 } finally {
9347 Binder.restoreCallingIdentity(identity);
9348 }
9349 }
9350
9351 @Override
Michele0ea7d782019-03-19 14:58:42 -07009352 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009353 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009354 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009355 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9356 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009357 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009358 }
Michelecea4cf22018-12-21 15:00:11 -08009359
9360 final long identity = Binder.clearCallingIdentity();
9361 try {
Michele0ea7d782019-03-19 14:58:42 -07009362 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009363 } finally {
9364 Binder.restoreCallingIdentity(identity);
9365 }
9366 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009367
Michele0ea7d782019-03-19 14:58:42 -07009368 @TelephonyManager.IsMultiSimSupportedResult
9369 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009370 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9371 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9372 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009373 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9374 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009375 }
9376 // Check if the hardware supports multisim functionality. If usage of multisim is not
9377 // supported by the modem, indicate that it is restricted.
9378 PhoneCapability staticCapability =
9379 mPhoneConfigurationManager.getStaticPhoneCapability();
9380 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009381 loge("isMultiSimSupportedInternal: no static configuration available");
9382 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009383 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009384 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009385 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9386 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009387 }
9388 // Check if support of multiple SIMs is restricted by carrier
9389 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009390 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009391 }
9392
Michele0ea7d782019-03-19 14:58:42 -07009393 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009394 }
9395
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009396 /**
9397 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009398 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9399 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9400 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009401 * @param numOfSims number of active sims we want to switch to
9402 */
9403 @Override
9404 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009405 if (numOfSims == 1) {
9406 enforceModifyPermission();
9407 } else {
9408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9409 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9410 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009411 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009412
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009413 try {
Michele30b57b22019-03-01 12:01:14 -08009414 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009415 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009416 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9417 return;
9418 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009419 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9420 } finally {
9421 Binder.restoreCallingIdentity(identity);
9422 }
9423 }
9424
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009425 @Override
9426 public boolean isApplicationOnUicc(int subId, int appType) {
9427 enforceReadPrivilegedPermission("isApplicationOnUicc");
9428 Phone phone = getPhone(subId);
9429 if (phone == null) {
9430 return false;
9431 }
9432 final long identity = Binder.clearCallingIdentity();
9433 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009434 UiccPort uiccPort = phone.getUiccPort();
9435 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009436 return false;
9437 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009438 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009439 if (uiccProfile == null) {
9440 return false;
9441 }
9442 if (TelephonyManager.APPTYPE_SIM <= appType
9443 && appType <= TelephonyManager.APPTYPE_ISIM) {
9444 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9445 }
9446 return false;
9447 } finally {
9448 Binder.restoreCallingIdentity(identity);
9449 }
9450 }
9451
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009452 /**
chen xub4baa772019-04-03 10:23:41 -07009453 * Get whether making changes to modem configurations will trigger reboot.
9454 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009455 */
9456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009457 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9458 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009460 mApp, subId, callingPackage, callingFeatureId,
9461 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009462 return false;
9463 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009464 final long identity = Binder.clearCallingIdentity();
9465 try {
9466 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9467 } finally {
9468 Binder.restoreCallingIdentity(identity);
9469 }
9470 }
9471
Nathan Harold29f5f052019-02-15 13:41:57 -08009472 private void updateModemStateMetrics() {
9473 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9474 // TODO: check the state for each modem if the api is ready.
9475 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9476 }
9477
Pengquan Meng3889a572019-01-23 11:16:29 -08009478 @Override
9479 public int[] getSlotsMapping() {
9480 enforceReadPrivilegedPermission("getSlotsMapping");
9481
9482 final long identity = Binder.clearCallingIdentity();
9483 try {
9484 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9485 // All logical slots should have a mapping to a physical slot.
9486 int[] logicalSlotsMapping = new int[phoneCount];
9487 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9488 for (int i = 0; i < slotInfos.length; i++) {
9489 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9490 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9491 }
9492 }
9493 return logicalSlotsMapping;
9494 } finally {
9495 Binder.restoreCallingIdentity(identity);
9496 }
9497 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009498
9499 /**
9500 * Get the IRadio HAL Version
9501 */
9502 @Override
9503 public int getRadioHalVersion() {
9504 Phone phone = getDefaultPhone();
9505 if (phone == null) return -1;
9506 HalVersion hv = phone.getHalVersion();
9507 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9508 return hv.major * 100 + hv.minor;
9509 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009510
9511 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009512 * Get the current calling package name.
9513 * @return the current calling package name
9514 */
9515 @Override
9516 public String getCurrentPackageName() {
9517 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9518 }
9519
9520 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009521 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9522 * corresponding network requests on a subId.
9523 *
9524 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009525 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009526 * 2) APN is un-metered for this subscription, or
9527 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009528 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009529 *
9530 * @return whether data is allowed for a apn type.
9531 *
9532 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009533 */
9534 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009535 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009536 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9537 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009538
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 false;
9544
Jack Yu41407ee2019-05-13 16:54:09 -07009545 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009546 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9547 } finally {
9548 Binder.restoreCallingIdentity(identity);
9549 }
9550 }
9551
9552 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009553 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009554 enforceReadPrivilegedPermission("isApnMetered");
9555
9556 // Now that all security checks passes, perform the operation as ourselves.
9557 final long identity = Binder.clearCallingIdentity();
9558 try {
9559 Phone phone = getPhone(subId);
9560 if (phone == null) return true; // By default return true.
9561
Jack Yu41407ee2019-05-13 16:54:09 -07009562 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009563 } finally {
9564 Binder.restoreCallingIdentity(identity);
9565 }
9566 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009567
9568 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009569 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9570 int subscriptionId, IBooleanConsumer resultCallback) {
9571 enforceModifyPermission();
9572 long token = Binder.clearCallingIdentity();
9573 try {
9574 Phone phone = getPhone(subscriptionId);
9575 if (phone == null) {
9576 try {
9577 if (resultCallback != null) {
9578 resultCallback.accept(false);
9579 }
9580 } catch (RemoteException e) {
9581 // ignore
9582 }
9583 return;
9584 }
9585 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9586 Pair.create(specifiers, (x) -> {
9587 try {
9588 if (resultCallback != null) {
9589 resultCallback.accept(x);
9590 }
9591 } catch (RemoteException e) {
9592 // ignore
9593 }
9594 });
9595 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9596 } finally {
9597 Binder.restoreCallingIdentity(token);
9598 }
9599 }
9600
9601 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009602 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9603 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009604 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009605 mApp, subId, "getSystemSelectionChannels");
9606 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9607 final long identity = Binder.clearCallingIdentity();
9608 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009609 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9610 if (result instanceof IllegalStateException) {
9611 throw (IllegalStateException) result;
9612 }
9613 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009614 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9615 return specifiers;
9616 } finally {
9617 Binder.restoreCallingIdentity(identity);
9618 }
9619 }
9620
9621 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009622 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009623 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009624 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9625 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9626 if (iccRecords == null) {
9627 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9628 return false;
9629 }
9630 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9631 }
9632
9633 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009634 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9635 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009636 if (callingPackage == null) {
9637 callingPackage = getCurrentPackageName();
9638 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009639 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9640 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009641 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9642 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009643 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9644 }
9645 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9646 Intent intent = new Intent();
9647 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9648 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9649 // Bring up choose default SMS subscription dialog right now
9650 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9651 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9652 mApp.startActivity(intent);
9653 }
chen xud5ca2d52019-05-28 15:20:57 -07009654
9655 @Override
9656 public String getMmsUAProfUrl(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 carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9661 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9662 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9663 return carrierUAProfUrl;
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_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009667 } finally {
9668 Binder.restoreCallingIdentity(identity);
9669 }
9670 }
9671
9672 @Override
9673 public String getMmsUserAgent(int subId) {
9674 //TODO investigate if this API should require proper permission check in R b/133791609
9675 final long identity = Binder.clearCallingIdentity();
9676 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009677 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9678 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9679 if (!TextUtils.isEmpty(carrierUserAgent)) {
9680 return carrierUserAgent;
9681 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009682 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9683 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009684 } finally {
9685 Binder.restoreCallingIdentity(identity);
9686 }
9687 }
Jack Yub07d4972019-05-28 16:12:25 -07009688
9689 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009690 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9691 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009692
Jack Yub07d4972019-05-28 16:12:25 -07009693 final long identity = Binder.clearCallingIdentity();
9694 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009695 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009696 if (phone == null) return false;
9697
Hall Liua62f5da2020-09-25 10:42:19 -07009698 switch (policy) {
9699 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9700 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9701 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9702 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9703 default:
9704 throw new IllegalArgumentException(policy + " is not a valid policy");
9705 }
Jack Yub07d4972019-05-28 16:12:25 -07009706 } finally {
9707 Binder.restoreCallingIdentity(identity);
9708 }
9709 }
9710
9711 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009712 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009713 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009714 enforceModifyPermission();
9715
changbettyd5c246e2019-12-24 15:40:37 +08009716 final long identity = Binder.clearCallingIdentity();
9717 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009718 Phone phone = getPhone(subscriptionId);
9719 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009720
Hall Liua62f5da2020-09-25 10:42:19 -07009721 switch (policy) {
9722 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9723 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9724 break;
9725 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9726 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9727 break;
9728 default:
9729 throw new IllegalArgumentException(policy + " is not a valid policy");
9730 }
changbettyd5c246e2019-12-24 15:40:37 +08009731 } finally {
9732 Binder.restoreCallingIdentity(identity);
9733 }
9734 }
9735
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009736 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009737 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009738 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9739 * otherwise.
9740 */
9741 @Override
9742 public void setCepEnabled(boolean isCepEnabled) {
9743 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9744
9745 final long identity = Binder.clearCallingIdentity();
9746 try {
9747 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9748 for (Phone phone : PhoneFactory.getPhones()) {
9749 Phone defaultPhone = phone.getImsPhone();
9750 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9751 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9752 ImsPhoneCallTracker imsPhoneCallTracker =
9753 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9754 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9755 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9756 + imsPhone.getMsisdn());
9757 }
9758 }
9759 } finally {
9760 Binder.restoreCallingIdentity(identity);
9761 }
9762 }
allenwtsu46dcc572020-01-08 18:24:03 +08009763
9764 /**
9765 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9766 *
9767 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9768 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9769 * before being read.
9770 */
9771 @Override
9772 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9773 isCompressed) {
9774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9775 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009776 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9777 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9778 }
9779 if (!isImsAvailableOnDevice()) {
9780 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9781 "IMS not available on device.");
9782 }
9783
9784 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009785 try {
Hui Wang761a6682020-10-31 05:12:53 +00009786 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9787 } finally {
9788 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009789 }
9790 }
zoey chene02881a2019-12-30 16:11:23 +08009791
9792 @Override
9793 public boolean isIccLockEnabled(int subId) {
9794 enforceReadPrivilegedPermission("isIccLockEnabled");
9795
9796 // Now that all security checks passes, perform the operation as ourselves.
9797 final long identity = Binder.clearCallingIdentity();
9798 try {
9799 Phone phone = getPhone(subId);
9800 if (phone != null && phone.getIccCard() != null) {
9801 return phone.getIccCard().getIccLockEnabled();
9802 } else {
9803 return false;
9804 }
9805 } finally {
9806 Binder.restoreCallingIdentity(identity);
9807 }
9808 }
9809
9810 /**
9811 * Set the ICC pin lock enabled or disabled.
9812 *
9813 * @return an integer representing the status of IccLock enabled or disabled in the following
9814 * three cases:
9815 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9816 * successfully.
9817 * - Positive number and zero for remaining password attempts.
9818 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9819 *
9820 */
9821 @Override
9822 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9823 enforceModifyPermission();
9824
9825 Phone phone = getPhone(subId);
9826 if (phone == null) {
9827 return 0;
9828 }
9829 // Now that all security checks passes, perform the operation as ourselves.
9830 final long identity = Binder.clearCallingIdentity();
9831 try {
9832 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9833 new Pair<Boolean, String>(enabled, password), phone, null);
9834 return attemptsRemaining;
9835
9836 } catch (Exception e) {
9837 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9838 } finally {
9839 Binder.restoreCallingIdentity(identity);
9840 }
9841 return 0;
9842 }
9843
9844 /**
9845 * Change the ICC password used in ICC pin lock.
9846 *
9847 * @return an integer representing the status of IccLock changed in the following three cases:
9848 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9849 * - Positive number and zero for remaining password attempts.
9850 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9851 *
9852 */
9853 @Override
9854 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9855 enforceModifyPermission();
9856
9857 Phone phone = getPhone(subId);
9858 if (phone == null) {
9859 return 0;
9860 }
9861 // Now that all security checks passes, perform the operation as ourselves.
9862 final long identity = Binder.clearCallingIdentity();
9863 try {
9864 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9865 new Pair<String, String>(oldPassword, newPassword), phone, null);
9866 return attemptsRemaining;
9867
9868 } catch (Exception e) {
9869 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9870 } finally {
9871 Binder.restoreCallingIdentity(identity);
9872 }
9873 return 0;
9874 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009875
9876 /**
9877 * Request for receiving user activity notification
9878 */
9879 @Override
9880 public void requestUserActivityNotification() {
9881 if (!mNotifyUserActivity.get()
9882 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9883 mNotifyUserActivity.set(true);
9884 }
9885 }
9886
9887 /**
9888 * Called when userActivity is signalled in the power manager.
9889 * This is safe to call from any thread, with any window manager locks held or not.
9890 */
9891 @Override
9892 public void userActivity() {
9893 // ***************************************
9894 // * Inherited from PhoneWindowManager *
9895 // ***************************************
9896 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9897 // WITH ITS LOCKS HELD.
9898 //
9899 // This code must be VERY careful about the locks
9900 // it acquires.
9901 // In fact, the current code acquires way too many,
9902 // and probably has lurking deadlocks.
9903
9904 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9905 throw new SecurityException("Only the OS may call notifyUserActivity()");
9906 }
9907
9908 if (mNotifyUserActivity.getAndSet(false)) {
9909 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9910 USER_ACTIVITY_NOTIFICATION_DELAY);
9911 }
9912 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009913
9914 @Override
9915 public boolean canConnectTo5GInDsdsMode() {
9916 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9917 }
Jack Yud10cdd42020-09-28 20:28:01 -07009918
9919 @Override
9920 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9921 String callingFeatureId) {
9922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9923 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9924 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9925 }
9926
9927 Phone phone = getPhone(subId);
9928 if (phone == null) {
9929 throw new RuntimeException("phone is not available");
9930 }
9931 // Now that all security checks passes, perform the operation as ourselves.
9932 final long identity = Binder.clearCallingIdentity();
9933 try {
9934 return phone.getEquivalentHomePlmns();
9935 } finally {
9936 Binder.restoreCallingIdentity(identity);
9937 }
9938 }
Daniel Bright59e67312020-11-13 11:49:37 -08009939
9940 @Override
9941 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009942 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9943 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009944 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009945 if (radioInterfaceCapabilities == null) {
9946 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009947 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009948 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009949 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009950
Hui Wang641e81c2020-10-12 12:14:23 -07009951 @Override
9952 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9953 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009954 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9955 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9956 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9957 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9958 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009959 if (DBG) {
9960 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9961 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9962 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9963 }
9964
9965 if (!SubscriptionManager.isValidSubscriptionId(subId)
9966 || appType < TelephonyManager.APPTYPE_UNKNOWN
9967 || appType > TelephonyManager.APPTYPE_ISIM
9968 || nafUrl == null || securityProtocol == null || callback == null) {
9969 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9970 if (callback != null) {
9971 try {
9972 callback.onAuthenticationFailure(
9973 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9974 } catch (RemoteException exception) {
9975 log("Fail to notify onAuthenticationFailure due to " + exception);
9976 }
9977 return;
9978 }
9979 }
9980
9981 final long token = Binder.clearCallingIdentity();
9982 try {
9983 getGbaManager(subId).bootstrapAuthenticationRequest(
9984 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9985 forceBootStrapping, callback));
9986 } finally {
9987 Binder.restoreCallingIdentity(token);
9988 }
9989 }
9990
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009991 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009992 * Attempts to set the radio power state for all phones for thermal reason.
9993 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009994 * requested radio power state will actually be set. See {@link
9995 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9996 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009997 * @param enable {@code true} if trying to turn radio on.
9998 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9999 * false}.
10000 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010001 private boolean setRadioPowerForThermal(boolean enable) {
10002 boolean isPhoneAvailable = false;
10003 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10004 Phone phone = PhoneFactory.getPhone(i);
10005 if (phone != null) {
10006 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10007 isPhoneAvailable = true;
10008 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010009 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010010
10011 // return true if successfully informed the phone object about the thermal radio power
10012 // request.
10013 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010014 }
10015
10016 private int handleDataThrottlingRequest(int subId,
10017 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010018 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10019 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10020 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10021 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10022 throw new IllegalArgumentException("modem does not support data throttling");
10023 }
10024
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010025 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10026 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010027 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010028 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10029 }
10030
10031 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10032
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010033 if (isDataThrottlingSupported) {
10034 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010035 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010036 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10037 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10038 } else if (thermalMitigationResult
10039 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010040 log("Modem likely does not support data throttling on secondary carrier. Data " +
10041 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10042 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010043 }
10044 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010045 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010046
10047 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010048 }
10049
Jack Nudelman644b91a2021-03-12 14:09:48 -080010050 private static List<String> getThermalMitigationAllowlist(Context context) {
10051 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10052 for (String pckg : context.getResources()
10053 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10054 sThermalMitigationAllowlistedPackages.add(pckg);
10055 }
10056 }
10057
10058 return sThermalMitigationAllowlistedPackages;
10059 }
10060
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010061 private boolean isAnyPhoneInEmergencyState() {
10062 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10063 if (tm.isInEmergencyCall()) {
10064 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10065 return true;
10066 }
10067 for (Phone phone : PhoneFactory.getPhones()) {
10068 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10069 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10070 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10071 + phone.isInEcm());
10072 return true;
10073 }
10074 }
10075
10076 return false;
10077 }
10078
Jack Nudelman644b91a2021-03-12 14:09:48 -080010079 /**
10080 * Used by shell commands to add an authorized package name for thermal mitigation.
10081 * @param packageName name of package to be allowlisted
10082 * @param context
10083 */
10084 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10085 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10086 sThermalMitigationAllowlistedPackages.add(packageName);
10087 }
10088
10089 /**
10090 * Used by shell commands to remove an authorized package name for thermal mitigation.
10091 * @param packageName name of package to remove from allowlist
10092 * @param context
10093 */
10094 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10095 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10096 sThermalMitigationAllowlistedPackages.remove(packageName);
10097 }
10098
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010099 /**
10100 * Thermal mitigation request to control functionalities at modem.
10101 *
10102 * @param subId the id of the subscription.
10103 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010104 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010105 *
10106 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10107 */
10108 @Override
10109 @ThermalMitigationResult
10110 public int sendThermalMitigationRequest(
10111 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010112 ThermalMitigationRequest thermalMitigationRequest,
10113 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010114 enforceModifyPermission();
10115
Jack Nudelman644b91a2021-03-12 14:09:48 -080010116 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10117 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10118 .contains(callingPackage)) {
10119 throw new SecurityException("Calling package must be configured in the device config. "
10120 + "calling package: " + callingPackage);
10121 }
10122
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010123 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10124 final long identity = Binder.clearCallingIdentity();
10125
10126 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10127 try {
10128 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10129 switch (thermalMitigationAction) {
10130 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10131 thermalMitigationResult =
10132 handleDataThrottlingRequest(subId,
10133 thermalMitigationRequest.getDataThrottlingRequest());
10134 break;
10135 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10136 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10137 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10138 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10139 }
10140
10141 // Ensure that radio is on. If not able to power on due to phone being
10142 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010143 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010144 thermalMitigationResult =
10145 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10146 break;
10147 }
10148
10149 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10150 false);
10151 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10152 break;
10153 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10154 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10155 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10156 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10157 }
10158
10159 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10160 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010161 Phone phone = getPhone(subId);
10162 if (phone == null) {
10163 thermalMitigationResult =
10164 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10165 break;
10166 }
10167
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010168 TelephonyConnectionService service =
10169 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010170 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010171 Log.e(LOG_TAG, "An emergency call is pending");
10172 thermalMitigationResult =
10173 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10174 break;
10175 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010176 thermalMitigationResult =
10177 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10178 break;
10179 }
10180 } else {
10181 thermalMitigationResult =
10182 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10183 break;
10184 }
10185
10186 // Turn radio off. If not able to power off due to phone being unavailable,
10187 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010188 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010189 thermalMitigationResult =
10190 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10191 break;
10192 }
10193 thermalMitigationResult =
10194 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10195 break;
10196 default:
10197 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10198 + "not exist. Requested action: " + thermalMitigationAction);
10199 }
10200 } catch (IllegalArgumentException e) {
10201 throw e;
10202 } catch (Exception e) {
10203 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10204 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10205 } finally {
10206 Binder.restoreCallingIdentity(identity);
10207 }
10208
10209 if (DBG) {
10210 log("thermalMitigationRequest returning with thermalMitigationResult: "
10211 + thermalMitigationResult);
10212 }
10213
10214 return thermalMitigationResult;
10215 }
Hui Wang641e81c2020-10-12 12:14:23 -070010216
10217 /**
10218 * Set the GbaService Package Name that Telephony will bind to.
10219 *
10220 * @param subId The sim that the GbaService is associated with.
10221 * @param packageName The name of the package to be replaced with.
10222 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10223 */
10224 @Override
10225 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10226 enforceModifyPermission();
10227
10228 final long identity = Binder.clearCallingIdentity();
10229 try {
10230 return getGbaManager(subId).overrideServicePackage(packageName);
10231 } finally {
10232 Binder.restoreCallingIdentity(identity);
10233 }
10234 }
10235
10236 /**
10237 * Return the package name of the currently bound GbaService.
10238 *
10239 * @param subId The sim that the GbaService is associated with.
10240 * @return the package name of the GbaService configuration, null if GBA is not supported.
10241 */
10242 @Override
10243 public String getBoundGbaService(int subId) {
10244 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10245
10246 final long identity = Binder.clearCallingIdentity();
10247 try {
10248 return getGbaManager(subId).getServicePackage();
10249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
10253
10254 /**
10255 * Set the release time for telephony to unbind GbaService.
10256 *
10257 * @param subId The sim that the GbaService is associated with.
10258 * @param interval The release time to unbind GbaService by millisecond.
10259 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10260 */
10261 @Override
10262 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10263 enforceModifyPermission();
10264
10265 final long identity = Binder.clearCallingIdentity();
10266 try {
10267 return getGbaManager(subId).overrideReleaseTime(interval);
10268 } finally {
10269 Binder.restoreCallingIdentity(identity);
10270 }
10271 }
10272
10273 /**
10274 * Return the release time for telephony to unbind GbaService.
10275 *
10276 * @param subId The sim that the GbaService is associated with.
10277 * @return The release time to unbind GbaService by millisecond.
10278 */
10279 @Override
10280 public int getGbaReleaseTime(int subId) {
10281 enforceReadPrivilegedPermission("getGbaReleaseTime");
10282
10283 final long identity = Binder.clearCallingIdentity();
10284 try {
10285 return getGbaManager(subId).getReleaseTime();
10286 } finally {
10287 Binder.restoreCallingIdentity(identity);
10288 }
10289 }
10290
10291 private GbaManager getGbaManager(int subId) {
10292 GbaManager instance = GbaManager.getInstance(subId);
10293 if (instance == null) {
10294 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10295 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10296 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10297 }
10298 return instance;
10299 }
Hui Wang761a6682020-10-31 05:12:53 +000010300
10301 /**
10302 * indicate whether the device and the carrier can support
10303 * RCS VoLTE single registration.
10304 */
10305 @Override
10306 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010307 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10308 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10309 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10310 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010311
10312 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10313 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10314 }
10315
10316 final long identity = Binder.clearCallingIdentity();
10317 try {
10318 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10319 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010320 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10321 if (isCapable != null) {
10322 return isCapable;
10323 }
Hui Wang761a6682020-10-31 05:12:53 +000010324 }
Hui Wang67af90e2021-06-04 16:57:15 -070010325 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10326 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010327 } finally {
10328 Binder.restoreCallingIdentity(identity);
10329 }
10330 }
10331
10332 /**
10333 * Register RCS provisioning callback.
10334 */
10335 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010336 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010337 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010338 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010339 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010340 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10341 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010342
10343 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10344 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10345 }
10346 if (!isImsAvailableOnDevice()) {
10347 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10348 "IMS not available on device.");
10349 }
10350
10351 final long identity = Binder.clearCallingIdentity();
10352 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010353 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010354 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010355 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10356 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010357 }
Hui Wang761a6682020-10-31 05:12:53 +000010358 } finally {
10359 Binder.restoreCallingIdentity(identity);
10360 }
10361 }
10362
10363 /**
10364 * Unregister RCS provisioning callback.
10365 */
10366 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010367 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010368 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010369 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010370 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010371 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10372 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010373
10374 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10375 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10376 }
10377 if (!isImsAvailableOnDevice()) {
10378 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10379 "IMS not available on device.");
10380 }
10381
10382 final long identity = Binder.clearCallingIdentity();
10383 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010384 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010385 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010386 } finally {
10387 Binder.restoreCallingIdentity(identity);
10388 }
10389 }
10390
10391 /**
10392 * trigger RCS reconfiguration.
10393 */
10394 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010395 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10396 "triggerRcsReconfiguration",
10397 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010398
10399 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10400 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10401 }
10402 if (!isImsAvailableOnDevice()) {
10403 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10404 "IMS not available on device.");
10405 }
10406
10407 final long identity = Binder.clearCallingIdentity();
10408 try {
10409 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10410 } finally {
10411 Binder.restoreCallingIdentity(identity);
10412 }
10413 }
10414
10415 /**
10416 * Provide the client configuration parameters of the RCS application.
10417 */
10418 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010419 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10420 "setRcsClientConfiguration",
10421 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010422
10423 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10424 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10425 }
10426 if (!isImsAvailableOnDevice()) {
10427 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10428 "IMS not available on device.");
10429 }
10430
10431 final long identity = Binder.clearCallingIdentity();
10432
10433 try {
10434 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10435 if (configBinder == null) {
10436 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010437 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10438 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010439 } else {
10440 configBinder.setRcsClientConfiguration(rcc);
10441 }
10442 } catch (RemoteException e) {
10443 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010444 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10445 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010446 } finally {
10447 Binder.restoreCallingIdentity(identity);
10448 }
10449 }
10450
10451 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010452 * Enables or disables the test mode for RCS VoLTE single registration.
10453 */
10454 @Override
10455 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10456 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10457 "setRcsSingleRegistrationTestModeEnabled");
10458
10459 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10460 }
10461
10462 /**
10463 * Gets the test mode for RCS VoLTE single registration.
10464 */
10465 @Override
10466 public boolean getRcsSingleRegistrationTestModeEnabled() {
10467 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10468 "getRcsSingleRegistrationTestModeEnabled");
10469
10470 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10471 }
10472
10473 /**
Hui Wang761a6682020-10-31 05:12:53 +000010474 * Overrides the config of RCS VoLTE single registration enabled for the device.
10475 */
10476 @Override
10477 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10478 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10479 "setDeviceSingleRegistrationEnabledOverride");
10480 enforceModifyPermission();
10481
10482 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10483 : Boolean.parseBoolean(enabledStr);
10484 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010485 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010486 }
10487
10488 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010489 * Sends a device to device communication message. Only usable via shell.
10490 * @param message message to send.
10491 * @param value message value.
10492 */
10493 @Override
10494 public void sendDeviceToDeviceMessage(int message, int value) {
10495 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010496 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010497 enforceModifyPermission();
10498
10499 final long identity = Binder.clearCallingIdentity();
10500 try {
10501 TelephonyConnectionService service =
10502 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10503 if (service == null) {
10504 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10505 return;
10506 }
10507 service.sendTestDeviceToDeviceMessage(message, value);
10508 } finally {
10509 Binder.restoreCallingIdentity(identity);
10510 }
10511 }
10512
Tyler Gunnbabbda02021-02-10 11:05:02 -080010513 /**
10514 * Sets the specified device to device transport active.
10515 * @param transport The transport to set active.
10516 */
10517 @Override
10518 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10519 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10520 "setActiveDeviceToDeviceTransport");
10521 enforceModifyPermission();
10522
10523 final long identity = Binder.clearCallingIdentity();
10524 try {
10525 TelephonyConnectionService service =
10526 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10527 if (service == null) {
10528 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10529 return;
10530 }
10531 service.setActiveDeviceToDeviceTransport(transport);
10532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
Tyler Gunn92479152021-01-20 16:30:10 -080010536
Tyler Gunnd4575212021-05-03 14:46:49 -070010537 @Override
10538 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10539 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10540 "setDeviceToDeviceForceEnabled");
10541
10542 final long identity = Binder.clearCallingIdentity();
10543 try {
10544 Arrays.stream(PhoneFactory.getPhones()).forEach(
10545 p -> {
10546 Phone thePhone = p.getImsPhone();
10547 if (thePhone != null && thePhone instanceof ImsPhone) {
10548 ImsPhone imsPhone = (ImsPhone) thePhone;
10549 CallTracker tracker = imsPhone.getCallTracker();
10550 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10551 ImsPhoneCallTracker imsPhoneCallTracker =
10552 (ImsPhoneCallTracker) tracker;
10553 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10554 }
10555 }
10556 }
10557 );
10558 } finally {
10559 Binder.restoreCallingIdentity(identity);
10560 }
10561 }
10562
Tyler Gunn92479152021-01-20 16:30:10 -080010563 /**
Hui Wang761a6682020-10-31 05:12:53 +000010564 * Gets the config of RCS VoLTE single registration enabled for the device.
10565 */
10566 @Override
10567 public boolean getDeviceSingleRegistrationEnabled() {
10568 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10569 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10570 }
10571
10572 /**
10573 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10574 */
10575 @Override
10576 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10577 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10578 "setCarrierSingleRegistrationEnabledOverride");
10579 enforceModifyPermission();
10580
10581 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10582 : Boolean.parseBoolean(enabledStr);
10583 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10584 subId, enabled);
10585 }
10586
10587 /**
10588 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10589 */
10590 @Override
10591 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10592 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10593 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10594 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010595
10596 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010597 * Overrides the ims feature validation result
10598 */
10599 @Override
10600 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10601 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10602 "setImsFeatureValidationOverride");
10603
10604 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10605 : Boolean.parseBoolean(enabledStr);
10606 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10607 subId, enabled);
10608 }
10609
10610 /**
10611 * Gets the ims feature validation override value
10612 */
10613 @Override
10614 public boolean getImsFeatureValidationOverride(int subId) {
10615 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10616 "getImsFeatureValidationOverride");
10617 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10618 }
10619
10620 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010621 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10622 * their mobile plan.
10623 */
10624 @Override
10625 public String getMobileProvisioningUrl() {
10626 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10627 final long identity = Binder.clearCallingIdentity();
10628 try {
10629 return getDefaultPhone().getMobileProvisioningUrl();
10630 } finally {
10631 Binder.restoreCallingIdentity(identity);
10632 }
10633 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010634
James.cf Linbcdf8b32021-01-14 16:44:13 +080010635 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010636 * Get the EAB contact from the EAB database.
10637 */
10638 @Override
10639 public String getContactFromEab(String contact) {
10640 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10641 enforceModifyPermission();
10642 final long identity = Binder.clearCallingIdentity();
10643 try {
10644 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10645 } finally {
10646 Binder.restoreCallingIdentity(identity);
10647 }
10648 }
10649
10650 /**
Calvin Pana1434322021-07-01 19:27:01 +080010651 * Get the EAB capability from the EAB database.
10652 */
10653 @Override
10654 public String getCapabilityFromEab(String contact) {
10655 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10656 enforceModifyPermission();
10657 final long identity = Binder.clearCallingIdentity();
10658 try {
10659 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10660 } finally {
10661 Binder.restoreCallingIdentity(identity);
10662 }
10663 }
10664
10665 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010666 * Remove the EAB contacts from the EAB database.
10667 */
10668 @Override
10669 public int removeContactFromEab(int subId, String contacts) {
10670 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10671 enforceModifyPermission();
10672 final long identity = Binder.clearCallingIdentity();
10673 try {
10674 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10675 } finally {
10676 Binder.restoreCallingIdentity(identity);
10677 }
10678 }
10679
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010680 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010681 public boolean getDeviceUceEnabled() {
10682 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10683 final long identity = Binder.clearCallingIdentity();
10684 try {
10685 return mApp.getDeviceUceEnabled();
10686 } finally {
10687 Binder.restoreCallingIdentity(identity);
10688 }
10689 }
10690
10691 @Override
10692 public void setDeviceUceEnabled(boolean isEnabled) {
10693 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10694 final long identity = Binder.clearCallingIdentity();
10695 try {
10696 mApp.setDeviceUceEnabled(isEnabled);
10697 } finally {
10698 Binder.restoreCallingIdentity(identity);
10699 }
10700 }
10701
Brad Ebinger14d467f2021-02-12 06:18:28 +000010702 /**
10703 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10704 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10705 */
10706 // Used for SHELL command only right now.
10707 @Override
10708 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10709 List<String> featureTags) {
10710 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10711 "addUceRegistrationOverrideShell");
10712 final long identity = Binder.clearCallingIdentity();
10713 try {
10714 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10715 new ArraySet<>(featureTags));
10716 } catch (ImsException e) {
10717 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10718 } finally {
10719 Binder.restoreCallingIdentity(identity);
10720 }
10721 }
10722
10723 /**
10724 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10725 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10726 */
10727 // Used for SHELL command only right now.
10728 @Override
10729 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10730 List<String> featureTags) {
10731 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10732 "removeUceRegistrationOverrideShell");
10733 final long identity = Binder.clearCallingIdentity();
10734 try {
10735 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10736 new ArraySet<>(featureTags));
10737 } catch (ImsException e) {
10738 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10739 } finally {
10740 Binder.restoreCallingIdentity(identity);
10741 }
10742 }
10743
10744 /**
10745 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10746 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10747 */
10748 // Used for SHELL command only right now.
10749 @Override
10750 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10751 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10752 "clearUceRegistrationOverrideShell");
10753 final long identity = Binder.clearCallingIdentity();
10754 try {
10755 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10756 } catch (ImsException e) {
10757 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10758 } finally {
10759 Binder.restoreCallingIdentity(identity);
10760 }
10761 }
10762
10763 /**
10764 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10765 */
10766 // Used for SHELL command only right now.
10767 @Override
10768 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10770 "getLatestRcsContactUceCapabilityShell");
10771 final long identity = Binder.clearCallingIdentity();
10772 try {
10773 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10774 } catch (ImsException e) {
10775 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10776 } finally {
10777 Binder.restoreCallingIdentity(identity);
10778 }
10779 }
10780
10781 /**
10782 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10783 * device does not have an active PUBLISH.
10784 */
10785 // Used for SHELL command only right now.
10786 @Override
10787 public String getLastUcePidfXmlShell(int subId) {
10788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10789 final long identity = Binder.clearCallingIdentity();
10790 try {
10791 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10792 } catch (ImsException e) {
10793 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
10798
James.cf Line8713a42021-04-29 16:04:26 +080010799 /**
10800 * Remove UCE requests cannot be sent to the network status.
10801 */
10802 // Used for SHELL command only right now.
10803 @Override
10804 public boolean removeUceRequestDisallowedStatus(int subId) {
10805 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10806 final long identity = Binder.clearCallingIdentity();
10807 try {
10808 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10809 } catch (ImsException e) {
10810 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10811 } finally {
10812 Binder.restoreCallingIdentity(identity);
10813 }
10814 }
10815
James.cf Lin0fc71b02021-05-25 01:37:38 +080010816 /**
10817 * Remove UCE requests cannot be sent to the network status.
10818 */
10819 // Used for SHELL command only.
10820 @Override
10821 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10822 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10823 final long identity = Binder.clearCallingIdentity();
10824 try {
10825 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10826 } catch (ImsException e) {
10827 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010832
James.cf Lin4b784aa2021-01-31 03:25:15 +080010833 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010834 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10835 String callingPackage) {
10836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10837 mApp, subId, "setSignalStrengthUpdateRequest");
10838
10839 final int callingUid = Binder.getCallingUid();
10840 // Verify that tha callingPackage belongs to the calling UID
10841 mApp.getSystemService(AppOpsManager.class)
10842 .checkPackage(callingUid, callingPackage);
10843
Rambo Wang3607f502021-02-01 21:51:40 -080010844 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010845
10846 final long identity = Binder.clearCallingIdentity();
10847 try {
10848 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10849 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10850
10851 if (result instanceof IllegalStateException) {
10852 throw (IllegalStateException) result;
10853 }
10854 } finally {
10855 Binder.restoreCallingIdentity(identity);
10856 }
10857 }
10858
10859 @Override
10860 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10861 String callingPackage) {
10862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10863 mApp, subId, "clearSignalStrengthUpdateRequest");
10864
10865 final int callingUid = Binder.getCallingUid();
10866 // Verify that tha callingPackage belongs to the calling UID
10867 mApp.getSystemService(AppOpsManager.class)
10868 .checkPackage(callingUid, callingPackage);
10869
10870 final long identity = Binder.clearCallingIdentity();
10871 try {
10872 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10873 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10874
10875 if (result instanceof IllegalStateException) {
10876 throw (IllegalStateException) result;
10877 }
10878 } finally {
10879 Binder.restoreCallingIdentity(identity);
10880 }
10881 }
10882
Rambo Wang3607f502021-02-01 21:51:40 -080010883 private static void validateSignalStrengthUpdateRequest(Context context,
10884 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010885 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10886 // phone/system process do not have further restriction on request
10887 return;
10888 }
10889
10890 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010891 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010892 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010893 context.enforceCallingOrSelfPermission(
10894 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10895 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010896 }
10897
10898 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10899 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10900 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10901 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10902 || info.isEnabled()) {
10903 throw new IllegalArgumentException(
10904 "Only system can set hide fields in SignalThresholdInfo");
10905 }
10906
10907 // Thresholds length for each RAN need in range. This has been validated in
10908 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10909 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10910 final int[] thresholds = info.getThresholds();
10911 Objects.requireNonNull(thresholds);
10912 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10913 || thresholds.length
10914 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10915 throw new IllegalArgumentException(
10916 "thresholds length is out of range: " + thresholds.length);
10917 }
10918 }
10919 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010920
10921 /**
10922 * Gets the current phone capability.
10923 *
10924 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10925 * @return the PhoneCapability which describes the data connection capability of modem.
10926 * It's used to evaluate possible phone config change, for example from single
10927 * SIM device to multi-SIM device.
10928 */
10929 @Override
10930 public PhoneCapability getPhoneCapability() {
10931 enforceReadPrivilegedPermission("getPhoneCapability");
10932 final long identity = Binder.clearCallingIdentity();
10933 try {
10934 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10935 } finally {
10936 Binder.restoreCallingIdentity(identity);
10937 }
10938 }
Michele Berionne5e411512020-11-13 02:36:59 +000010939
10940 /**
10941 * Prepare TelephonyManager for an unattended reboot. The reboot is
10942 * required to be done shortly after the API is invoked.
10943 */
10944 @Override
10945 @TelephonyManager.PrepareUnattendedRebootResult
10946 public int prepareForUnattendedReboot() {
10947 enforceRebootPermission();
10948
10949 final long identity = Binder.clearCallingIdentity();
10950 try {
10951 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10952 } finally {
10953 Binder.restoreCallingIdentity(identity);
10954 }
10955 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010956
10957 /**
10958 * Request to get the current slicing configuration including URSP rules and
10959 * NSSAIs (configured, allowed and rejected).
10960 *
10961 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10962 */
10963 @Override
10964 public void getSlicingConfig(ResultReceiver callback) {
10965 enforceReadPrivilegedPermission("getSlicingConfig");
10966
10967 final long identity = Binder.clearCallingIdentity();
10968 try {
10969 Phone phone = getDefaultPhone();
10970 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10971 } finally {
10972 Binder.restoreCallingIdentity(identity);
10973 }
10974 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000010975
10976 /**
10977 * Register an IMS connection state callback
10978 */
10979 @Override
10980 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
10981 String callingPackage) {
10982 if (feature == ImsFeature.FEATURE_MMTEL) {
10983 // ImsMmTelManager
10984 // The following also checks READ_PRIVILEGED_PHONE_STATE.
10985 TelephonyPermissions
10986 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
10987 mApp, subId, "registerImsStateCallback");
10988 } else if (feature == ImsFeature.FEATURE_RCS) {
10989 // ImsRcsManager or SipDelegateManager
10990 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10991 Binder.getCallingUid(), "registerImsStateCallback",
10992 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
10993 Manifest.permission.READ_PRECISE_PHONE_STATE,
10994 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
10995 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
10996 }
10997
10998 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
10999 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11000 "IMS not available on device.");
11001 }
11002
11003 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11004 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11005 }
11006
11007 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11008 if (controller == null) {
11009 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11010 "IMS not available on device.");
11011 }
11012
11013 if (callingPackage == null) {
11014 callingPackage = getCurrentPackageName();
11015 }
11016
11017 final long token = Binder.clearCallingIdentity();
11018 try {
11019 int slotId = getSlotIndexOrException(subId);
11020 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11021 } catch (ImsException e) {
11022 throw new ServiceSpecificException(e.getCode());
11023 } finally {
11024 Binder.restoreCallingIdentity(token);
11025 }
11026 }
11027
11028 /**
11029 * Unregister an IMS connection state callback
11030 */
11031 @Override
11032 public void unregisterImsStateCallback(IImsStateCallback cb) {
11033 final long token = Binder.clearCallingIdentity();
11034 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11035 if (controller == null) {
11036 return;
11037 }
11038 try {
11039 controller.unregisterImsStateCallback(cb);
11040 } finally {
11041 Binder.restoreCallingIdentity(token);
11042 }
11043 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011044
11045 /**
11046 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11047 *
11048 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11049 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11050 * SecurityException.
11051 * If there is current registered network this value will be same as the registered cell
11052 * identity. If the device goes out of service the previous cell identity is cached and
11053 * will be returned. If the cache age of the Cell identity is more than 24 hours
11054 * it will be cleared and null will be returned.
11055 *
11056 */
11057 @Override
11058 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11059 String callingFeatureId) {
11060 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11061 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11062 LocationAccessPolicy.checkLocationPermission(mApp,
11063 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11064 .setCallingPackage(callingPackage)
11065 .setCallingFeatureId(callingFeatureId)
11066 .setCallingPid(Binder.getCallingPid())
11067 .setCallingUid(Binder.getCallingUid())
11068 .setMethod("getLastKnownCellIdentity")
11069 .setLogAsInfo(true)
11070 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11071 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11072 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11073 .build());
11074
11075 boolean hasFinePermission =
11076 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11077 if (!hasFinePermission
11078 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11079 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11080 + "and BIND_CONNECTION_SERVICE permission.");
11081 }
11082
11083 final long identity = Binder.clearCallingIdentity();
11084 try {
11085 Phone phone = getPhone(subId);
11086 if (phone == null) return null;
11087 ServiceStateTracker sst = phone.getServiceStateTracker();
11088 if (sst == null) return null;
11089 return sst.getLastKnownCellIdentity();
11090 } finally {
11091 Binder.restoreCallingIdentity(identity);
11092 }
11093 }
jimsun38340bf2021-10-26 15:01:23 +080011094
11095 /**
11096 * Sets the modem service class Name that Telephony will bind to.
11097 *
11098 * @param serviceName The class name of the modem service.
11099 * @return true if the operation is succeed, otherwise false.
11100 */
11101 public boolean setModemService(String serviceName) {
11102 Log.d(LOG_TAG, "setModemService - " + serviceName);
11103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11105 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11106 "setModemService");
11107 return mPhoneConfigurationManager.setModemService(serviceName);
11108 }
11109
11110 /**
11111 * Return the class name of the currently bounded modem service.
11112 *
11113 * @return the class name of the modem service.
11114 */
11115 public String getModemService() {
11116 String result;
11117 Log.d(LOG_TAG, "getModemService");
11118 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11119 TelephonyPermissions
11120 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11121 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11122 "getModemService");
11123 result = mPhoneConfigurationManager.getModemService();
11124 Log.d(LOG_TAG, "result = " + result);
11125 return result;
11126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011127}