blob: 2aedd5978227e219e3542c567163728197fd301e [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) {
2923 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2924 } else {
2925 return PhoneConstantConversions.convertDataState(
2926 PhoneConstants.DataState.DISCONNECTED);
2927 }
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002934 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002935 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2936 }
2937
2938 @Override
2939 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 final long identity = Binder.clearCallingIdentity();
2941 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002942 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 if (phone != null) {
2944 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2945 } else {
2946 return TelephonyManager.DATA_ACTIVITY_NONE;
2947 }
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002951 }
2952
2953 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002954 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002956 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002957
2958 LocationAccessPolicy.LocationPermissionResult locationResult =
2959 LocationAccessPolicy.checkLocationPermission(mApp,
2960 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2961 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002962 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002963 .setCallingPid(Binder.getCallingPid())
2964 .setCallingUid(Binder.getCallingUid())
2965 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002966 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002967 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2968 .build());
2969 switch (locationResult) {
2970 case DENIED_HARD:
2971 throw new SecurityException("Not allowed to access cell location");
2972 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002973 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2974 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 }
2976
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002977 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002981 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002982 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Svetoslav64fad262015-04-14 14:35:21 -07002986 }
2987
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002988 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002989 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002990 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2991 // registered cell info, so return a NULL country instead.
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002994 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2995 // Get default phone in this case.
2996 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2997 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002998 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003000 if (phone == null) return "";
3001 ServiceStateTracker sst = phone.getServiceStateTracker();
3002 if (sst == null) return "";
3003 LocaleTracker lt = sst.getLocaleTracker();
3004 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003005 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003009 }
3010
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003011 /**
3012 * This method was removed due to potential issues caused by performing partial
3013 * updates of service state, and lack of a credible use case.
3014 *
3015 * This has the ability to break the telephony implementation by disabling notification of
3016 * changes in device connectivity. DO NOT USE THIS!
3017 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003018 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 public void enableLocationUpdates() {
3020 mApp.enforceCallingOrSelfPermission(
3021 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003022 }
3023
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003024 /**
3025 * This method was removed due to potential issues caused by performing partial
3026 * updates of service state, and lack of a credible use case.
3027 *
3028 * This has the ability to break the telephony implementation by disabling notification of
3029 * changes in device connectivity. DO NOT USE THIS!
3030 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 @Override
3032 public void disableLocationUpdates() {
3033 mApp.enforceCallingOrSelfPermission(
3034 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003035 }
3036
3037 @Override
3038 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003039 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3040 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003041 try {
3042 mApp.getSystemService(AppOpsManager.class)
3043 .checkPackage(Binder.getCallingUid(), callingPackage);
3044 } catch (SecurityException e) {
3045 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3046 throw e;
3047 }
3048
Nathan Haroldf096d982020-11-18 17:18:06 -08003049 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003050 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3051 throw new SecurityException(
3052 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3053 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003054
Jordan Liu1617b712019-07-10 15:06:26 -07003055 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3057 return null;
3058 }
Svetoslav64fad262015-04-14 14:35:21 -07003059
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003060 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003062 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003063 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064
Nathan Haroldf180aac2018-06-01 18:43:55 -07003065 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3066 for (CellInfo ci : info) {
3067 if (ci instanceof CellInfoGsm) {
3068 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3069 } else if (ci instanceof CellInfoWcdma) {
3070 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3071 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003073 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 }
3075
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003076 private List<CellInfo> getCachedCellInfo() {
3077 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3078 for (Phone phone : PhoneFactory.getPhones()) {
3079 List<CellInfo> info = phone.getAllCellInfo();
3080 if (info != null) cellInfos.addAll(info);
3081 }
3082 return cellInfos;
3083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084
3085 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003086 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003087 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003088 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003089
3090 LocationAccessPolicy.LocationPermissionResult locationResult =
3091 LocationAccessPolicy.checkLocationPermission(mApp,
3092 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3093 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003094 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003095 .setCallingPid(Binder.getCallingPid())
3096 .setCallingUid(Binder.getCallingUid())
3097 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003098 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003099 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3100 .build());
3101 switch (locationResult) {
3102 case DENIED_HARD:
3103 throw new SecurityException("Not allowed to access cell info");
3104 case DENIED_SOFT:
3105 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003106 }
3107
Nathan Haroldf096d982020-11-18 17:18:06 -08003108 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003109 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3110 return getCachedCellInfo();
3111 }
3112
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003113 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003114 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3118 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003119 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003120 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121 if (info != null) cellInfos.addAll(info);
3122 }
3123 return cellInfos;
3124 } finally {
3125 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 }
3127 }
3128
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003129 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003130 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3131 String callingFeatureId) {
3132 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3133 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003134 }
3135
3136 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003137 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3138 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003139 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003140 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003141 }
3142
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003143 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3144 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003145 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003146 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003147
3148 LocationAccessPolicy.LocationPermissionResult locationResult =
3149 LocationAccessPolicy.checkLocationPermission(mApp,
3150 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3151 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003152 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003153 .setCallingPid(Binder.getCallingPid())
3154 .setCallingUid(Binder.getCallingUid())
3155 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003156 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3157 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003158 .build());
3159 switch (locationResult) {
3160 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003161 if (TelephonyPermissions
3162 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003163 // Safetynet logging for b/154934934
3164 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3165 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003166 throw new SecurityException("Not allowed to access cell info");
3167 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003168 if (TelephonyPermissions
3169 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003170 // Safetynet logging for b/154934934
3171 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3172 }
Nathan Harold5320c422019-05-09 10:26:08 -07003173 try {
3174 cb.onCellInfo(new ArrayList<CellInfo>());
3175 } catch (RemoteException re) {
3176 // Drop without consequences
3177 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003178 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003179 }
3180
Nathan Harolda939a962019-05-09 10:13:47 -07003181
3182 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003183 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3184
3185 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3186 }
3187
3188 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003190 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003191 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192
3193 final long identity = Binder.clearCallingIdentity();
3194 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003195 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 }
3200
Shishir Agrawala9f32182016-04-12 12:00:16 -07003201 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003202 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003203 Phone phone = PhoneFactory.getPhone(slotIndex);
3204 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003205 return null;
3206 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003207 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003208 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003209 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003210 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003211 return null;
3212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213
3214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 return phone.getImei();
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003220 }
3221
3222 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003223 public String getTypeAllocationCodeForSlot(int slotIndex) {
3224 Phone phone = PhoneFactory.getPhone(slotIndex);
3225 String tac = null;
3226 if (phone != null) {
3227 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003228 try {
3229 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3230 } catch (IndexOutOfBoundsException e) {
3231 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3232 return null;
3233 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003234 }
3235 return tac;
3236 }
3237
3238 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003239 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003240 try {
3241 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3242 } catch (SecurityException se) {
3243 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3244 throw new SecurityException("Package " + callingPackage + " does not belong to "
3245 + Binder.getCallingUid());
3246 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003247 Phone phone = PhoneFactory.getPhone(slotIndex);
3248 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003249 return null;
3250 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003251
Jeff Davidson913390f2018-02-23 17:11:49 -08003252 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003253 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003254 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003255 return null;
3256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257
3258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 return phone.getMeid();
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
3263 }
Jack Yu2af8d712017-03-15 17:14:14 -07003264 }
3265
3266 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003267 public String getManufacturerCodeForSlot(int slotIndex) {
3268 Phone phone = PhoneFactory.getPhone(slotIndex);
3269 String manufacturerCode = null;
3270 if (phone != null) {
3271 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003272 try {
3273 manufacturerCode =
3274 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3275 } catch (IndexOutOfBoundsException e) {
3276 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3277 return null;
3278 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003279 }
3280 return manufacturerCode;
3281 }
3282
3283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003284 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3285 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003286 Phone phone = PhoneFactory.getPhone(slotIndex);
3287 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003288 return null;
3289 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003290 int subId = phone.getSubId();
3291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003292 mApp, subId, callingPackage, callingFeatureId,
3293 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003294 return null;
3295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296
3297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 return phone.getDeviceSvn();
3300 } finally {
3301 Binder.restoreCallingIdentity(identity);
3302 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003303 }
3304
fionaxu43304da2017-11-27 22:51:16 -08003305 @Override
3306 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 final Phone phone = getPhone(subId);
3310 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3311 } finally {
3312 Binder.restoreCallingIdentity(identity);
3313 }
fionaxu43304da2017-11-27 22:51:16 -08003314 }
3315
3316 @Override
3317 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 final Phone phone = getPhone(subId);
3321 return phone == null ? null : phone.getCarrierName();
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
fionaxu43304da2017-11-27 22:51:16 -08003325 }
3326
calvinpanffe225e2018-11-01 19:43:06 +08003327 @Override
chen xu0026ca62019-03-06 15:28:50 -08003328 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 final Phone phone = getPhone(subId);
3332 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003333 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
3337 }
3338
3339 @Override
chen xu0026ca62019-03-06 15:28:50 -08003340 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003344 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003345 } finally {
3346 Binder.restoreCallingIdentity(identity);
3347 }
3348 }
3349
chen xu651eec72018-11-11 19:03:44 -08003350 @Override
chen xu864e11c2018-12-06 22:10:03 -08003351 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3352 if (!isSubscriptionMccMnc) {
3353 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3354 }
chen xu651eec72018-11-11 19:03:44 -08003355 final Phone phone = PhoneFactory.getPhone(slotIndex);
3356 if (phone == null) {
3357 return TelephonyManager.UNKNOWN_CARRIER_ID;
3358 }
3359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
3365 }
3366
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003367 //
3368 // Internal helper methods.
3369 //
3370
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003371 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003372 * Make sure the caller is the calling package itself
3373 *
3374 * @throws SecurityException if the caller is not the calling package
3375 */
3376 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3377 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003378 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3379 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003380 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003381 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003382 } catch (PackageManager.NameNotFoundException e) {
3383 // packageUid is -1
3384 }
3385 if (packageUid != callingUid) {
3386 throw new SecurityException(message + ": Package " + callingPackage
3387 + " does not belong to " + callingUid);
3388 }
3389 }
3390
3391 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3393 *
3394 * @throws SecurityException if the caller does not have the required permission
3395 */
3396 private void enforceModifyPermission() {
3397 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3398 }
3399
Shuo Qian3b6ee772019-11-13 17:43:31 -08003400 private void enforceActiveEmergencySessionPermission() {
3401 mApp.enforceCallingOrSelfPermission(
3402 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3403 }
3404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003405 /**
3406 * Make sure the caller has the CALL_PHONE permission.
3407 *
3408 * @throws SecurityException if the caller does not have the required permission
3409 */
3410 private void enforceCallPermission() {
3411 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3412 }
3413
paulhu5a773602019-08-23 19:17:33 +08003414 private void enforceSettingsPermission() {
3415 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003416 }
3417
Michele Berionne5e411512020-11-13 02:36:59 +00003418 private void enforceRebootPermission() {
3419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3420 }
3421
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003422 private String createTelUrl(String number) {
3423 if (TextUtils.isEmpty(number)) {
3424 return null;
3425 }
3426
Jake Hambye994d462014-02-03 13:10:13 -08003427 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003428 }
3429
Ihab Awadf9e92732013-12-05 18:02:52 -08003430 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3432 }
3433
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003434 private static void logv(String msg) {
3435 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3436 }
3437
Ihab Awadf9e92732013-12-05 18:02:52 -08003438 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003439 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3440 }
3441
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003442 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003443 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003444 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003445 }
3446
Sanket Padawe356d7632015-06-22 14:03:32 -07003447 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003448 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 final Phone phone = PhoneFactory.getPhone(slotIndex);
3452 if (phone == null) {
3453 return PhoneConstants.PHONE_TYPE_NONE;
3454 } else {
3455 return phone.getPhoneType();
3456 }
3457 } finally {
3458 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003460 }
3461
3462 /**
3463 * Returns the CDMA ERI icon index to display
3464 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003465 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003466 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3467 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3468 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003469 }
3470
Sanket Padawe356d7632015-06-22 14:03:32 -07003471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003472 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3473 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003475 mApp, subId, callingPackage, callingFeatureId,
3476 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003477 return -1;
3478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 final Phone phone = getPhone(subId);
3483 if (phone != null) {
3484 return phone.getCdmaEriIconIndex();
3485 } else {
3486 return -1;
3487 }
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 }
3492
3493 /**
3494 * Returns the CDMA ERI icon mode,
3495 * 0 - ON
3496 * 1 - FLASHING
3497 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003498 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003499 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3500 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3501 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003502 }
3503
Sanket Padawe356d7632015-06-22 14:03:32 -07003504 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003505 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3506 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003508 mApp, subId, callingPackage, callingFeatureId,
3509 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003510 return -1;
3511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512
3513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 final Phone phone = getPhone(subId);
3516 if (phone != null) {
3517 return phone.getCdmaEriIconMode();
3518 } else {
3519 return -1;
3520 }
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 }
3525
3526 /**
3527 * Returns the CDMA ERI text,
3528 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003529 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003530 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3531 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3532 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003533 }
3534
Sanket Padawe356d7632015-06-22 14:03:32 -07003535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003536 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3537 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003539 mApp, subId, callingPackage, callingFeatureId,
3540 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 return null;
3542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 final Phone phone = getPhone(subId);
3547 if (phone != null) {
3548 return phone.getCdmaEriText();
3549 } else {
3550 return null;
3551 }
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003555 }
3556
3557 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003558 * Returns the CDMA MDN.
3559 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003560 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003561 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3563 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564
3565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003568 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569 return phone.getLine1Number();
3570 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003571 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572 return null;
3573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003576 }
3577 }
3578
3579 /**
3580 * Returns the CDMA MIN.
3581 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003582 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003583 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3585 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586
3587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 final Phone phone = getPhone(subId);
3590 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3591 return phone.getCdmaMin();
3592 } else {
3593 return null;
3594 }
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003597 }
3598 }
3599
Hall Liud892bec2018-11-30 14:51:45 -08003600 @Override
3601 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3602 INumberVerificationCallback callback, String callingPackage) {
3603 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3604 != PERMISSION_GRANTED) {
3605 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3606 }
3607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3608
3609 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3610 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003611 throw new SecurityException("Calling package must be configured in the device config: "
3612 + "calling package: " + callingPackage
3613 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003614 }
3615
3616 if (range == null) {
3617 throw new NullPointerException("Range must be non-null");
3618 }
3619
3620 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003621 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003622
3623 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3624 }
3625
Junda Liuca05d5d2014-08-14 22:36:34 -07003626 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003627 * Returns true if CDMA provisioning needs to run.
3628 */
3629 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630 final long identity = Binder.clearCallingIdentity();
3631 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003632 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633 } finally {
3634 Binder.restoreCallingIdentity(identity);
3635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003636 }
3637
3638 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003639 * Sets the voice mail number of a given subId.
3640 */
3641 @Override
3642 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003643 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3644 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645
3646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3649 new Pair<String, String>(alphaTag, number), new Integer(subId));
3650 return success;
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
3653 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003654 }
3655
Ta-wei Yen87c49842016-05-13 21:19:52 -07003656 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003657 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003659 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3660 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003661 if (!TextUtils.equals(callingPackage, systemDialer)) {
3662 throw new SecurityException("caller must be system dialer");
3663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3668 if (phoneAccountHandle == null) {
3669 return null;
3670 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003671 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672 } finally {
3673 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003674 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003675 }
3676
3677 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003678 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3679 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003682 mApp, subId, callingPackage, callingFeatureId,
3683 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003684 return null;
3685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003687 final long identity = Binder.clearCallingIdentity();
3688 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003689 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003693 }
3694
3695 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003696 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3697 VisualVoicemailSmsFilterSettings settings) {
3698 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003703 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003707 }
3708
3709 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003710 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003716 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003717 } finally {
3718 Binder.restoreCallingIdentity(identity);
3719 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003720 }
3721
3722 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003723 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3724 String callingPackage, int subId) {
3725 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726
3727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003730 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003734 }
3735
3736 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003737 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739
3740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003743 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003747 }
3748
3749 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003750 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3751 String callingAttributionTag, int subId, String number, int port, String text,
3752 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003754 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003755 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003756 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003757 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3758 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003759 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003760
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003761 /**
fionaxu0152e512016-11-14 13:36:14 -08003762 * Sets the voice activation state of a given subId.
3763 */
3764 @Override
3765 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3767 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768
3769 final long identity = Binder.clearCallingIdentity();
3770 try {
3771 final Phone phone = getPhone(subId);
3772 if (phone != null) {
3773 phone.setVoiceActivationState(activationState);
3774 } else {
3775 loge("setVoiceActivationState fails with invalid subId: " + subId);
3776 }
3777 } finally {
3778 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003779 }
3780 }
3781
3782 /**
3783 * Sets the data activation state of a given subId.
3784 */
3785 @Override
3786 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3788 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003789
3790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 final Phone phone = getPhone(subId);
3793 if (phone != null) {
3794 phone.setDataActivationState(activationState);
3795 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003796 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 }
3798 } finally {
3799 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003800 }
3801 }
3802
3803 /**
3804 * Returns the voice activation state of a given subId.
3805 */
3806 @Override
3807 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003808 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809
fionaxu0152e512016-11-14 13:36:14 -08003810 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 if (phone != null) {
3814 return phone.getVoiceActivationState();
3815 } else {
3816 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3817 }
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003820 }
3821 }
3822
3823 /**
3824 * Returns the data activation state of a given subId.
3825 */
3826 @Override
3827 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829
fionaxu0152e512016-11-14 13:36:14 -08003830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 if (phone != null) {
3834 return phone.getDataActivationState();
3835 } else {
3836 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3837 }
3838 } finally {
3839 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003840 }
3841 }
3842
3843 /**
Wink Saville36469e72014-06-11 15:17:00 -07003844 * Returns the unread count of voicemails for a subId
3845 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003846 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003847 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3848 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003850 mApp, subId, callingPackage, callingFeatureId,
3851 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003852 return 0;
3853 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 final Phone phone = getPhone(subId);
3857 if (phone != null) {
3858 return phone.getVoiceMessageCount();
3859 } else {
3860 return 0;
3861 }
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003865 }
3866
3867 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003868 * returns true, if the device is in a state where both voice and data
3869 * are supported simultaneously. This can change based on location or network condition.
3870 */
3871 @Override
3872 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003873 final long identity = Binder.clearCallingIdentity();
3874 try {
3875 final Phone phone = getPhone(subId);
3876 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
3879 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003880 }
3881
3882 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003883 * Send the dialer code if called from the current default dialer or the caller has
3884 * carrier privilege.
3885 * @param inputCode The dialer code to send
3886 */
3887 @Override
3888 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003889 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003890 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003891 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3892 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003893 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003894 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003895 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897
3898 final long identity = Binder.clearCallingIdentity();
3899 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003900 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003901 } finally {
3902 Binder.restoreCallingIdentity(identity);
3903 }
fionaxu235cc5e2017-03-06 22:25:57 -08003904 }
3905
Pengquan Menga1bb6272018-09-06 09:59:22 -07003906 @Override
3907 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003908 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003909 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003910 mApp, subId, "getNetworkSelectionMode");
3911 final long identity = Binder.clearCallingIdentity();
3912 try {
3913 if (!isActiveSubscription(subId)) {
3914 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3915 }
3916 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003919 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003920 }
3921
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003923 public boolean isInEmergencySmsMode() {
3924 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3925 final long identity = Binder.clearCallingIdentity();
3926 try {
3927 for (Phone phone : PhoneFactory.getPhones()) {
3928 if (phone.isInEmergencySmsMode()) {
3929 return true;
3930 }
3931 }
3932 } finally {
3933 Binder.restoreCallingIdentity(identity);
3934 }
3935 return false;
3936 }
3937
shilu366312e2019-12-17 09:28:10 -08003938 /**
3939 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3940 * @param subId The subscription to use to check the configuration.
3941 * @param c The callback that will be used to send the result.
3942 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003943 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003944 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3945 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003946 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003947 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003948
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003949 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3950 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3951 "IMS not available on device.");
3952 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003953 final long token = Binder.clearCallingIdentity();
3954 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003955 int slotId = getSlotIndexOrException(subId);
3956 verifyImsMmTelConfiguredOrThrow(slotId);
3957 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003958 } catch (ImsException e) {
3959 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003960 } finally {
3961 Binder.restoreCallingIdentity(token);
3962 }
3963 }
3964
shilu366312e2019-12-17 09:28:10 -08003965 /**
3966 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3967 * @param subId The subscription to use to check the configuration.
3968 * @param c The callback that will be used to send the result.
3969 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003971 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003972 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003973 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003974 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3975 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3976 }
Meng Wangafbc5852019-09-19 17:37:13 -07003977 final long token = Binder.clearCallingIdentity();
3978 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003979 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3980 .removeRegistrationCallbackForSubscription(c, subId);
3981 } catch (ImsException e) {
3982 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3983 + "is inactive, ignoring unregister.");
3984 // If the subscription is no longer active, just return, since the callback
3985 // will already have been removed internally.
3986 } finally {
3987 Binder.restoreCallingIdentity(token);
3988 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 }
3990
Brad Ebingera34a6c22019-10-22 17:36:18 -07003991 /**
3992 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3993 */
3994 @Override
3995 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3996 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3997 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3998 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3999 "IMS not available on device.");
4000 }
4001 final long token = Binder.clearCallingIdentity();
4002 try {
4003 Phone phone = getPhone(subId);
4004 if (phone == null) {
4005 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4006 + subId + "'");
4007 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4008 }
4009 phone.getImsRegistrationState(regState -> {
4010 try {
4011 consumer.accept((regState == null)
4012 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4013 } catch (RemoteException e) {
4014 // Ignore if the remote process is no longer available to call back.
4015 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4016 }
4017 });
4018 } finally {
4019 Binder.restoreCallingIdentity(token);
4020 }
4021 }
4022
4023 /**
4024 * Get the transport type for the IMS service registration state.
4025 */
4026 @Override
4027 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004028 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004029 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004030 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4031 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4032 "IMS not available on device.");
4033 }
4034 final long token = Binder.clearCallingIdentity();
4035 try {
4036 Phone phone = getPhone(subId);
4037 if (phone == null) {
4038 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4039 + subId + "'");
4040 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4041 }
4042 phone.getImsRegistrationTech(regTech -> {
4043 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4044 int regTechConverted = (regTech == null)
4045 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4046 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4047 regTechConverted);
4048 try {
4049 consumer.accept(regTechConverted);
4050 } catch (RemoteException e) {
4051 // Ignore if the remote process is no longer available to call back.
4052 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4053 }
4054 });
4055 } finally {
4056 Binder.restoreCallingIdentity(token);
4057 }
4058 }
4059
shilu366312e2019-12-17 09:28:10 -08004060 /**
4061 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4062 * @param subId The subscription to use to check the configuration.
4063 * @param c The callback that will be used to send the result.
4064 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004066 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4067 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004068 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004069 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004070 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4071 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4072 "IMS not available on device.");
4073 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 final long token = Binder.clearCallingIdentity();
4075 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004076 int slotId = getSlotIndexOrException(subId);
4077 verifyImsMmTelConfiguredOrThrow(slotId);
4078 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004079 } catch (ImsException e) {
4080 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 } finally {
4082 Binder.restoreCallingIdentity(token);
4083 }
4084 }
4085
shilu366312e2019-12-17 09:28:10 -08004086 /**
4087 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4088 * @param subId The subscription to use to check the configuration.
4089 * @param c The callback that will be used to send the result.
4090 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004092 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004093 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004094 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004095 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4096 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4097 }
Meng Wangafbc5852019-09-19 17:37:13 -07004098
4099 final long token = Binder.clearCallingIdentity();
4100 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004101 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004102 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004103 } catch (ImsException e) {
4104 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4105 + "is inactive, ignoring unregister.");
4106 // If the subscription is no longer active, just return, since the callback
4107 // will already have been removed internally.
4108 } finally {
4109 Binder.restoreCallingIdentity(token);
4110 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 }
4112
4113 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004114 public boolean isCapable(int subId, int capability, int regTech) {
4115 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 final long token = Binder.clearCallingIdentity();
4117 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004118 int slotId = getSlotIndexOrException(subId);
4119 verifyImsMmTelConfiguredOrThrow(slotId);
4120 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004121 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4123 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004125 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4126 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 } finally {
4128 Binder.restoreCallingIdentity(token);
4129 }
4130 }
4131
4132 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004133 public boolean isAvailable(int subId, int capability, int regTech) {
4134 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 final long token = Binder.clearCallingIdentity();
4136 try {
4137 Phone phone = getPhone(subId);
4138 if (phone == null) return false;
4139 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004140 } catch (com.android.ims.ImsException e) {
4141 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4142 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 } finally {
4144 Binder.restoreCallingIdentity(token);
4145 }
4146 }
4147
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004148 /**
4149 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4150 * subscription.
4151 * @param subId The subscription to use to check the configuration.
4152 * @param callback The callback that will be used to send the result.
4153 * @param capability The MmTelFeature capability that will be used to send the result.
4154 * @param transportType The transport type of the MmTelFeature capability.
4155 */
4156 @Override
4157 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4158 int transportType) {
4159 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4160 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4161 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4162 "IMS not available on device.");
4163 }
4164 final long token = Binder.clearCallingIdentity();
4165 try {
4166 int slotId = getSlotIndex(subId);
4167 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4168 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4169 + subId + "'");
4170 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4171 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004172 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004173 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4174 transportType, aBoolean -> {
4175 try {
4176 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4177 } catch (RemoteException e) {
4178 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4179 + "running. Ignore");
4180 }
4181 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004182 } catch (ImsException e) {
4183 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004184 } finally {
4185 Binder.restoreCallingIdentity(token);
4186 }
4187 }
4188
shilu366312e2019-12-17 09:28:10 -08004189 /**
4190 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4191 * @param subId The subscription to use to check the configuration.
4192 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 @Override
4194 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004195 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004196 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004197
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 final long token = Binder.clearCallingIdentity();
4199 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004200 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004201 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004202 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (ImsException e) {
4204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 } finally {
4206 Binder.restoreCallingIdentity(token);
4207 }
4208 }
4209
4210 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004211 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004213 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 final long identity = Binder.clearCallingIdentity();
4215 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004216 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004217 // This setting doesn't require an active ImsService connection, so do not verify. The
4218 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004219 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004220 } catch (ImsException e) {
4221 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 } finally {
4223 Binder.restoreCallingIdentity(identity);
4224 }
4225 }
4226
shilu366312e2019-12-17 09:28:10 -08004227 /**
4228 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4229 * @param subId The subscription to use to check the configuration.
4230 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004232 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004233 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004234 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 final long identity = Binder.clearCallingIdentity();
4236 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004237 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004238 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004239 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004240 } catch (ImsException e) {
4241 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
4245 }
4246
4247 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004248 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004250 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 final long identity = Binder.clearCallingIdentity();
4252 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004253 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004254 // This setting doesn't require an active ImsService connection, so do not verify. The
4255 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004256 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004257 } catch (ImsException e) {
4258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
4262 }
4263
shilu366312e2019-12-17 09:28:10 -08004264 /**
4265 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4266 * @param subId The subscription to use to check the configuration.
4267 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 @Override
4269 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004270 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004271 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 final long identity = Binder.clearCallingIdentity();
4273 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004274 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004275 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004276 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004277 } catch (ImsException e) {
4278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
4282 }
4283
4284 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004285 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004287 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 final long identity = Binder.clearCallingIdentity();
4289 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004290 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004291 // This setting doesn't require an active ImsService connection, so do not verify. The
4292 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004293 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004294 } catch (ImsException e) {
4295 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
4299 }
4300
shilu366312e2019-12-17 09:28:10 -08004301 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004302 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4303 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4304 * @param subId The subscription to use to check the configuration.
4305 */
4306 @Override
4307 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004308 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004309 mApp, subId, "isCrossSimCallingEnabledByUser");
4310 final long identity = Binder.clearCallingIdentity();
4311 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004312 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004313 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004314 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004315 } catch (ImsException e) {
4316 throw new ServiceSpecificException(e.getCode());
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
4320 }
4321
4322 /**
4323 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4324 * Requires MODIFY_PHONE_STATE permission.
4325 * @param subId The subscription to use to check the configuration.
4326 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4327 * false otherwise
4328 */
4329 @Override
4330 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4332 "setCrossSimCallingEnabled");
4333 final long identity = Binder.clearCallingIdentity();
4334 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004336 // This setting doesn't require an active ImsService connection, so do not verify. The
4337 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004339 } catch (ImsException e) {
4340 throw new ServiceSpecificException(e.getCode());
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
4344 }
4345
4346 /**
shilu366312e2019-12-17 09:28:10 -08004347 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4348 * @param subId The subscription to use to check the configuration.
4349 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004350 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004351
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004353 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004354 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 final long identity = Binder.clearCallingIdentity();
4356 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004358 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004359 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004360 } catch (ImsException e) {
4361 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004362 } finally {
4363 Binder.restoreCallingIdentity(identity);
4364 }
4365 }
4366
4367 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004368 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004370 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 final long identity = Binder.clearCallingIdentity();
4372 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004373 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004374 // This setting doesn't require an active ImsService connection, so do not verify. The
4375 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004377 } catch (ImsException e) {
4378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
4382 }
4383
4384 @Override
4385 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4387 "setVoWiFiNonPersistent");
4388 final long identity = Binder.clearCallingIdentity();
4389 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004390 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004391 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004392 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004393 } catch (ImsException e) {
4394 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
4398 }
4399
shilu366312e2019-12-17 09:28:10 -08004400 /**
4401 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4402 * @param subId The subscription to use to check the configuration.
4403 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004404 @Override
4405 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004406 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004407 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004408 final long identity = Binder.clearCallingIdentity();
4409 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004410 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004411 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004413 } catch (ImsException e) {
4414 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
4418 }
4419
4420 @Override
4421 public void setVoWiFiModeSetting(int subId, int mode) {
4422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4423 "setVoWiFiModeSetting");
4424 final long identity = Binder.clearCallingIdentity();
4425 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004426 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004427 // This setting doesn't require an active ImsService connection, so do not verify. The
4428 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004429 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004430 } catch (ImsException e) {
4431 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
4435 }
4436
4437 @Override
4438 public int getVoWiFiRoamingModeSetting(int subId) {
4439 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4440 final long identity = Binder.clearCallingIdentity();
4441 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004443 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004444 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004445 } catch (ImsException e) {
4446 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
4450 }
4451
4452 @Override
4453 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4455 "setVoWiFiRoamingModeSetting");
4456 final long identity = Binder.clearCallingIdentity();
4457 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004459 // This setting doesn't require an active ImsService connection, so do not verify. The
4460 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004462 } catch (ImsException e) {
4463 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
4467 }
4468
4469 @Override
4470 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4472 "setRttCapabilityEnabled");
4473 final long identity = Binder.clearCallingIdentity();
4474 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004475 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004476 // This setting doesn't require an active ImsService connection, so do not verify. The
4477 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004479 } catch (ImsException e) {
4480 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
4484 }
4485
shilu366312e2019-12-17 09:28:10 -08004486 /**
4487 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4488 * @param subId The subscription to use to check the configuration.
4489 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 @Override
4491 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004492 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004493 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004496 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004497 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004499 } catch (ImsException e) {
4500 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504 }
4505
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004506 @Override
4507 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4508 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4509 final long identity = Binder.clearCallingIdentity();
4510 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004511 if (!isImsAvailableOnDevice()) {
4512 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4513 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004514 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 int slotId = getSlotIndexOrException(subId);
4516 verifyImsMmTelConfiguredOrThrow(slotId);
4517 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004518 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004519 } catch (ImsException e) {
4520 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
4524 }
4525
4526 @Override
4527 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4528 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4529 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004530 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4531 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4532 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004533 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004534 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004535 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004536 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004537 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4538 + "is inactive, ignoring unregister.");
4539 // If the subscription is no longer active, just return, since the callback will already
4540 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004541 } finally {
4542 Binder.restoreCallingIdentity(identity);
4543 }
4544 }
4545
allenwtsu99c623b2020-01-03 18:24:23 +08004546
4547 private void checkModifyPhoneStatePermission(int subId, String message) {
4548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4549 message);
4550 }
4551
4552 private boolean isImsProvisioningRequired(int subId, int capability,
4553 boolean isMmtelCapability) {
4554 Phone phone = getPhone(subId);
4555 if (phone == null) {
4556 loge("phone instance null for subid " + subId);
4557 return false;
4558 }
4559 if (isMmtelCapability) {
4560 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4561 return false;
4562 }
4563 } else {
4564 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4565 return false;
4566 }
4567 }
4568 return true;
4569 }
4570
4571 @Override
4572 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4573 boolean isProvisioned) {
4574 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4575
4576 final long identity = Binder.clearCallingIdentity();
4577 try {
4578 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4579 if (!isImsProvisioningRequired(subId, capability, false)) {
4580 return;
4581 }
4582
4583 // this capability requires provisioning, route to the correct API.
4584 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4585 switch (capability) {
4586 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4587 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4588 ims.setEabProvisioned(isProvisioned);
4589 break;
4590 default: {
4591 throw new IllegalArgumentException("Tried to set provisioning for "
4592 + "rcs capability '" + capability + "', which does not require "
4593 + "provisioning.");
4594 }
4595 }
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
4598 }
4599
4600 }
4601
4602
4603 @Override
4604 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4605 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4609 if (!isImsProvisioningRequired(subId, capability, false)) {
4610 return true;
4611 }
4612
4613 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4614 switch (capability) {
4615 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4616 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4617 return ims.isEabProvisionedOnDevice();
4618
4619 default: {
4620 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4621 + "capability '" + capability + "', which does not require "
4622 + "provisioning.");
4623 }
4624 }
4625
4626 } finally {
4627 Binder.restoreCallingIdentity(identity);
4628 }
4629 }
4630
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004631 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004632 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4633 boolean isProvisioned) {
4634 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004635 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4636 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4637 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004638 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4639 }
allenwtsu99c623b2020-01-03 18:24:23 +08004640 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004641 final long identity = Binder.clearCallingIdentity();
4642 try {
4643 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004644 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004645 return;
4646 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004647 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4648 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4649 loge("setImsProvisioningStatusForCapability: called for technology that does "
4650 + "not support provisioning - " + tech);
4651 return;
4652 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004653
4654 // this capability requires provisioning, route to the correct API.
4655 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4656 switch (capability) {
4657 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4658 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4659 ims.setVolteProvisioned(isProvisioned);
4660 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4661 ims.setWfcProvisioned(isProvisioned);
4662 }
4663 break;
4664 }
4665 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4666 // There is currently no difference in VT provisioning type.
4667 ims.setVtProvisioned(isProvisioned);
4668 break;
4669 }
4670 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4671 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4672 // change the capability of the feature instead if needed.
4673 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4674 == isProvisioned) {
4675 // No change in provisioning.
4676 return;
4677 }
4678 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4679 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004680 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004681 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004682 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4683 + ", Exception" + e.getMessage());
4684 }
4685 break;
4686 }
4687 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004688 throw new IllegalArgumentException("Tried to set provisioning for "
4689 + "MmTel capability '" + capability + "', which does not require "
4690 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004691 }
4692 }
4693
4694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
4697 }
4698
4699 @Override
4700 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4701 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004702 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4703 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4704 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4706 }
4707 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4708 final long identity = Binder.clearCallingIdentity();
4709 try {
4710 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004711 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004712 return true;
4713 }
4714
Brad Ebinger0d79c572021-04-17 15:20:49 -07004715 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4716 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4717 loge("getImsProvisioningStatusForCapability: called for technology that does "
4718 + "not support provisioning - " + tech);
4719 return true;
4720 }
4721
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004722 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4723 switch (capability) {
4724 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4725 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4726 return ims.isVolteProvisionedOnDevice();
4727 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4728 return ims.isWfcProvisionedOnDevice();
4729 }
4730 // This should never happen, since we are checking tech above to make sure it
4731 // is either LTE or IWLAN.
4732 throw new IllegalArgumentException("Invalid radio technology for voice "
4733 + "capability.");
4734 }
4735 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4736 // There is currently no difference in VT provisioning type.
4737 return ims.isVtProvisionedOnDevice();
4738 }
4739 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4740 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4741 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4742 }
4743 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004744 throw new IllegalArgumentException(
4745 "Tried to get provisioning for MmTel capability '" + capability
4746 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004747 }
4748 }
4749
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
4753 }
4754
4755 @Override
4756 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4757 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4758 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4759 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4760 }
4761 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4762 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4763 return (provisionedBits & capability) > 0;
4764 }
4765
4766 @Override
4767 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4768 boolean isProvisioned) {
4769 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4770 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4771 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4772 }
4773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4774 "setProvisioningStatusForCapability");
4775 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4776 // If the current provisioning status for capability already matches isProvisioned,
4777 // do nothing.
4778 if (((provisionedBits & capability) > 0) == isProvisioned) {
4779 return;
4780 }
4781 if (isProvisioned) {
4782 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4783 } else {
4784 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4785 }
4786 }
4787
4788 /**
4789 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4790 * technology. The bitfield should mirror the bitfield defined by
4791 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4792 */
4793 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4794 String key = getMmTelProvisioningKey(subId, tech);
4795 // Default is no capabilities are provisioned.
4796 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4797 }
4798
4799 /**
4800 * Sets the MmTel capability provisioning bitfield (defined by
4801 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4802 * technology specified.
4803 *
4804 * Note: This is a synchronous command and should not be called on UI thread.
4805 */
4806 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4807 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4808 String key = getMmTelProvisioningKey(subId, tech);
4809 editor.putInt(key, newField);
4810 editor.commit();
4811 }
4812
4813 private static String getMmTelProvisioningKey(int subId, int tech) {
4814 // resulting key is provision_ims_mmtel_{subId}_{tech}
4815 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4816 }
4817
4818 /**
4819 * Query CarrierConfig to see if the specified capability requires provisioning for the
4820 * carrier associated with the subscription id.
4821 */
4822 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4823 int capability) {
4824 CarrierConfigManager configManager = new CarrierConfigManager(context);
4825 PersistableBundle c = configManager.getConfigForSubId(subId);
4826 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004827 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004828 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4829 false);
4830 boolean requireVoiceVtProvisioning = c.getBoolean(
4831 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4832
4833 // First check to make sure that the capability requires provisioning.
4834 switch (capability) {
4835 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4836 // intentional fallthrough
4837 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4838 if (requireVoiceVtProvisioning) {
4839 // Voice and Video requires provisioning
4840 return true;
4841 }
4842 break;
4843 }
4844 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4845 if (requireUtProvisioning) {
4846 // UT requires provisioning
4847 return true;
4848 }
4849 break;
4850 }
4851 }
4852 return false;
4853 }
4854
allenwtsu99c623b2020-01-03 18:24:23 +08004855 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4856 int capability) {
4857 CarrierConfigManager configManager = new CarrierConfigManager(context);
4858 PersistableBundle c = configManager.getConfigForSubId(subId);
4859
4860 boolean requireRcsProvisioning = c.getBoolean(
4861 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4862
4863 // First check to make sure that the capability requires provisioning.
4864 switch (capability) {
4865 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4866 // intentional fallthrough
4867 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4868 if (requireRcsProvisioning) {
4869 // OPTION or PRESENCE requires provisioning
4870 return true;
4871 }
4872 break;
4873 }
4874 }
4875 return false;
4876 }
4877
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004878 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004879 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004880 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4881 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4882 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004883 enforceReadPrivilegedPermission("getImsProvisioningInt");
4884 final long identity = Binder.clearCallingIdentity();
4885 try {
4886 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004887 int slotId = getSlotIndex(subId);
4888 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4889 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4890 + subId + "' for key:" + key);
4891 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4892 }
calvinpanb5a34062021-02-08 19:59:36 +08004893 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004894 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004895 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4896 + subId + "' for key:" + key);
4897 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004898 } finally {
4899 Binder.restoreCallingIdentity(identity);
4900 }
4901 }
4902
4903 @Override
4904 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004905 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4906 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4907 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004908 enforceReadPrivilegedPermission("getImsProvisioningString");
4909 final long identity = Binder.clearCallingIdentity();
4910 try {
4911 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912 int slotId = getSlotIndex(subId);
4913 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4914 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4915 + subId + "' for key:" + key);
4916 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4917 }
calvinpanb5a34062021-02-08 19:59:36 +08004918 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004919 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004920 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4921 + subId + "' for key:" + key);
4922 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004923 } finally {
4924 Binder.restoreCallingIdentity(identity);
4925 }
4926 }
4927
4928 @Override
4929 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004930 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4931 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4932 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4934 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004935 final long identity = Binder.clearCallingIdentity();
4936 try {
4937 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004938 int slotId = getSlotIndex(subId);
4939 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4940 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4941 + subId + "' for key:" + key);
4942 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4943 }
calvinpanb5a34062021-02-08 19:59:36 +08004944 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4945 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004946 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004947 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004948 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
4952 }
4953
4954 @Override
4955 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004956 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4957 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4958 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4960 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004961 final long identity = Binder.clearCallingIdentity();
4962 try {
4963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004964 int slotId = getSlotIndex(subId);
4965 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4966 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4967 + subId + "' for key:" + key);
4968 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4969 }
calvinpanb5a34062021-02-08 19:59:36 +08004970 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4971 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004973 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
4978 }
4979
Brad Ebinger919631e2021-06-02 17:46:35 -07004980 /**
4981 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4982 * for the given slot ID or no ImsResolver instance has been created.
4983 * @param slotId The slot ID that the IMS service is created for.
4984 * @throws ImsException If there is no ImsService configured for this slot.
4985 */
4986 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4987 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4988 ImsFeature.FEATURE_MMTEL)) {
4989 throw new ImsException("This subscription does not support MMTEL over IMS",
4990 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4991 }
4992 }
4993
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004994 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004995 int slotId = SubscriptionManager.getSlotIndex(subId);
4996 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004997 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4998 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004999 }
5000 return slotId;
5001 }
5002
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005003 private int getSlotIndex(int subId) {
5004 int slotId = SubscriptionManager.getSlotIndex(subId);
5005 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5006 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5007 }
5008 return slotId;
5009 }
5010
Wink Saville36469e72014-06-11 15:17:00 -07005011 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005012 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005013 */
5014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005015 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5016 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005017 try {
5018 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5019 } catch (SecurityException se) {
5020 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5021 throw new SecurityException("Package " + callingPackage + " does not belong to "
5022 + Binder.getCallingUid());
5023 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005024 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005025 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005026 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005027 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005028 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005029 mApp, subId, callingPackage, callingFeatureId,
5030 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005031 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5032 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 final long identity = Binder.clearCallingIdentity();
5035 try {
5036 final Phone phone = getPhone(subId);
5037 if (phone != null) {
5038 return phone.getServiceState().getDataNetworkType();
5039 } else {
5040 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5041 }
5042 } finally {
5043 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005045 }
5046
5047 /**
5048 * Returns the data network type
5049 */
5050 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005051 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005052 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5053 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005054 }
5055
5056 /**
5057 * Returns the data network type for a subId
5058 */
5059 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005060 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5061 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005062 String functionName = "getDataNetworkTypeForSubscriber";
5063 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5064 mApp, functionName)) {
5065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5066 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5067 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5068 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005069 }
5070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 final Phone phone = getPhone(subId);
5074 if (phone != null) {
5075 return phone.getServiceState().getDataNetworkType();
5076 } else {
5077 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5078 }
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005082 }
5083
5084 /**
Wink Saville36469e72014-06-11 15:17:00 -07005085 * Returns the Voice network type for a subId
5086 */
5087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005088 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5089 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005090 String functionName = "getVoiceNetworkTypeForSubscriber";
5091 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5092 mApp, functionName)) {
5093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5094 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5095 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5096 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005097 }
5098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005099 final long identity = Binder.clearCallingIdentity();
5100 try {
5101 final Phone phone = getPhone(subId);
5102 if (phone != null) {
5103 return phone.getServiceState().getVoiceNetworkType();
5104 } else {
5105 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5106 }
5107 } finally {
5108 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005110 }
5111
5112 /**
5113 * @return true if a ICC card is present
5114 */
5115 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005116 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005117 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5118 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005119 }
5120
5121 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005122 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005123 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005124 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005125 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005126 final long identity = Binder.clearCallingIdentity();
5127 try {
5128 final Phone phone = PhoneFactory.getPhone(slotIndex);
5129 if (phone != null) {
5130 return phone.getIccCard().hasIccCard();
5131 } else {
5132 return false;
5133 }
5134 } finally {
5135 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005137 }
5138
5139 /**
5140 * Return if the current radio is LTE on CDMA. This
5141 * is a tri-state return value as for a period of time
5142 * the mode may be unknown.
5143 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005144 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005145 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005146 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005147 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005148 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005149 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5150 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5151 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005152 }
5153
Sanket Padawe356d7632015-06-22 14:03:32 -07005154 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005155 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5156 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005157 try {
5158 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5159 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005160 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5161 }
5162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 final long identity = Binder.clearCallingIdentity();
5164 try {
5165 final Phone phone = getPhone(subId);
5166 if (phone == null) {
5167 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5168 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005169 return TelephonyProperties.lte_on_cdma_device()
5170 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 }
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005174 }
Wink Saville36469e72014-06-11 15:17:00 -07005175 }
5176
Wink Saville36469e72014-06-11 15:17:00 -07005177 /**
5178 * {@hide}
5179 * Returns Default subId, 0 in the case of single standby.
5180 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005181 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005182 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005183 }
5184
Shishir Agrawala9f32182016-04-12 12:00:16 -07005185 private int getSlotForDefaultSubscription() {
5186 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5187 }
5188
Wink Savilleb564aae2014-10-23 10:18:09 -07005189 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005190 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005191 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005192
Pengquan Menge92a50d2018-09-21 15:54:48 -07005193 private boolean isActiveSubscription(int subId) {
5194 return mSubscriptionController.isActiveSubId(subId);
5195 }
5196
Ihab Awadf2177b72013-11-25 13:33:23 -08005197 /**
5198 * @see android.telephony.TelephonyManager.WifiCallingChoices
5199 */
5200 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 final long identity = Binder.clearCallingIdentity();
5202 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005203 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5205 getWhenToMakeWifiCallsDefaultPreference());
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
5208 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005209 }
5210
5211 /**
5212 * @see android.telephony.TelephonyManager.WifiCallingChoices
5213 */
5214 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 final long identity = Binder.clearCallingIdentity();
5216 try {
5217 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005218 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5220 } finally {
5221 Binder.restoreCallingIdentity(identity);
5222 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005223 }
5224
Sailesh Nepald1e68152013-12-12 19:08:02 -08005225 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005226 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005227 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005228 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005229
Jordan Liu4c733742019-02-28 12:03:40 -08005230 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5231 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5232 if (phoneId == -1) {
5233 throw new IllegalArgumentException("Given slot index: " + slotIndex
5234 + " does not correspond to an active phone");
5235 }
5236 return PhoneFactory.getPhone(phoneId);
5237 }
5238
Shishir Agrawal566b7612013-10-28 14:41:00 -07005239 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005240 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5241 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5243 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005245 if (DBG) {
5246 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5247 }
5248 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5249 p2);
5250 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005251
Jordan Liu4c733742019-02-28 12:03:40 -08005252
5253 @Override
5254 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5255 int slotIndex, String callingPackage, String aid, int p2) {
5256 enforceModifyPermission();
5257 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5258 if (DBG) {
5259 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5260 }
5261 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5262 callingPackage, aid, p2);
5263 }
5264
5265 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5266 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267 final long identity = Binder.clearCallingIdentity();
5268 try {
5269 if (TextUtils.equals(ISDR_AID, aid)) {
5270 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005271 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5272 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 if (bestComponent == null
5274 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5275 loge("The calling package is not allowed to access ISD-R.");
5276 throw new SecurityException(
5277 "The calling package is not allowed to access ISD-R.");
5278 }
Derek Tan740e1672017-06-27 14:56:27 -07005279 }
Derek Tan740e1672017-06-27 14:56:27 -07005280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005282 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5283 null /* workSource */);
5284 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 return response;
5286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005289 }
5290
5291 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005292 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5294 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005295 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5296 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5297 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005298
Jordan Liu4c733742019-02-28 12:03:40 -08005299 @Override
5300 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5301 enforceModifyPermission();
5302 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5303 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5304 channel);
5305 }
5306
5307 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308 final long identity = Binder.clearCallingIdentity();
5309 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310 if (channel < 0) {
5311 return false;
5312 }
Jordan Liu4c733742019-02-28 12:03:40 -08005313 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5314 null /* workSource */);
5315 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 return success;
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005319 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005320 }
5321
5322 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005323 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005324 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5326 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005327 if (DBG) {
5328 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5329 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5330 + p3 + " data=" + data);
5331 }
5332 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5333 command, p1, p2, p3, data);
5334 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005335
Jordan Liu4c733742019-02-28 12:03:40 -08005336 @Override
5337 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5338 int command, int p1, int p2, int p3, String data) {
5339 enforceModifyPermission();
5340 if (DBG) {
5341 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5342 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5343 + p3 + " data=" + data);
5344 }
5345 return iccTransmitApduLogicalChannelWithPermission(
5346 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5347 data);
5348 }
5349
5350 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5351 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 final long identity = Binder.clearCallingIdentity();
5353 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005354 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 return "";
5356 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005359 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5360 null /* workSource */);
5361 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 // Append the returned status code to the end of the response payload.
5364 String s = Integer.toHexString(
5365 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5366 if (response.payload != null) {
5367 s = IccUtils.bytesToHexString(response.payload) + s;
5368 }
5369 return s;
5370 } finally {
5371 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005373 }
Jake Hambye994d462014-02-03 13:10:13 -08005374
Evan Charltonc66da362014-05-16 14:06:40 -07005375 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005376 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5377 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5379 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005381 if (DBG) {
5382 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5383 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5384 }
5385 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5386 cla, command, p1, p2, p3, data);
5387 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005388
Jordan Liu4c733742019-02-28 12:03:40 -08005389 @Override
5390 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5391 int command, int p1, int p2, int p3, String data) {
5392 enforceModifyPermission();
5393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5394 if (DBG) {
5395 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5396 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5397 + " data=" + data);
5398 }
5399
5400 return iccTransmitApduBasicChannelWithPermission(
5401 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5402 p2, p3, data);
5403 }
5404
5405 // open APDU basic channel assuming the caller has sufficient permissions
5406 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5407 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 final long identity = Binder.clearCallingIdentity();
5409 try {
5410 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5411 && TextUtils.equals(ISDR_AID, data)) {
5412 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005413 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5414 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 if (bestComponent == null
5416 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5417 loge("The calling package is not allowed to select ISD-R.");
5418 throw new SecurityException(
5419 "The calling package is not allowed to select ISD-R.");
5420 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005421 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005424 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5425 null /* workSource */);
5426 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 // Append the returned status code to the end of the response payload.
5429 String s = Integer.toHexString(
5430 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5431 if (response.payload != null) {
5432 s = IccUtils.bytesToHexString(response.payload) + s;
5433 }
5434 return s;
5435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005437 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005438 }
5439
5440 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005441 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005442 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5444 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 final long identity = Binder.clearCallingIdentity();
5447 try {
5448 if (DBG) {
5449 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5450 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5451 }
5452
5453 IccIoResult response =
5454 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5455 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5456 subId);
5457
5458 if (DBG) {
5459 log("Exchange SIM_IO [R]" + response);
5460 }
5461
5462 byte[] result = null;
5463 int length = 2;
5464 if (response.payload != null) {
5465 length = 2 + response.payload.length;
5466 result = new byte[length];
5467 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5468 } else {
5469 result = new byte[length];
5470 }
5471
5472 result[length - 1] = (byte) response.sw2;
5473 result[length - 2] = (byte) response.sw1;
5474 return result;
5475 } finally {
5476 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005477 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005478 }
5479
Nathan Haroldb3014052017-01-25 15:57:32 -08005480 /**
5481 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5482 * on a particular subscription
5483 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005484 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5485 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005487 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005488 return null;
5489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490
5491 final long identity = Binder.clearCallingIdentity();
5492 try {
5493 if (appType != TelephonyManager.APPTYPE_USIM
5494 && appType != TelephonyManager.APPTYPE_SIM) {
5495 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5496 return null;
5497 }
5498 Object response = sendRequest(
5499 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5500 if (response instanceof String[]) {
5501 return (String[]) response;
5502 }
yincheng zhao2737e882019-09-06 17:06:54 -07005503 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005505 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 } finally {
5507 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005508 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005509 }
5510
yincheng zhao2737e882019-09-06 17:06:54 -07005511 /**
5512 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5513 * subscription.
5514 *
5515 * @param subId the id of the subscription.
5516 * @param appType the uicc app type, must be USIM or SIM.
5517 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5518 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005519 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005520 * @return number of fplmns that is successfully written to the SIM.
5521 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005522 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5523 String callingFeatureId) {
5524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5525 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005526 if (DBG) logv("no permissions for setForbiddenplmns");
5527 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5528 }
5529 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5530 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5531 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5532 }
5533 if (fplmns == null) {
5534 throw new IllegalArgumentException("Fplmn List provided is null");
5535 }
5536 for (String fplmn : fplmns) {
5537 if (!CellIdentity.isValidPlmn(fplmn)) {
5538 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5539 }
5540 }
5541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 Object response = sendRequest(
5544 CMD_SET_FORBIDDEN_PLMNS,
5545 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5546 subId);
5547 return (int) response;
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
5551 }
5552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005553 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005554 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5556 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 final long identity = Binder.clearCallingIdentity();
5559 try {
5560 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5561 if (response.payload == null) {
5562 return "";
5563 }
Evan Charltonc66da362014-05-16 14:06:40 -07005564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 // Append the returned status code to the end of the response payload.
5566 String s = Integer.toHexString(
5567 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5568 s = IccUtils.bytesToHexString(response.payload) + s;
5569 return s;
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
Evan Charltonc66da362014-05-16 14:06:40 -07005573 }
5574
Jake Hambye994d462014-02-03 13:10:13 -08005575 /**
5576 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5577 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5578 *
5579 * @param itemID the ID of the item to read
5580 * @return the NV item as a String, or null on error.
5581 */
5582 @Override
5583 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005584 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5586 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587
5588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005591 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5593 return value;
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
Jake Hambye994d462014-02-03 13:10:13 -08005597 }
5598
5599 /**
5600 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5601 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5602 *
5603 * @param itemID the ID of the item to read
5604 * @param itemValue the value to write, as a String
5605 * @return true on success; false on any failure
5606 */
5607 @Override
5608 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005609 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5611 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612
5613 final long identity = Binder.clearCallingIdentity();
5614 try {
5615 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5616 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005617 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5619 return success;
5620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
Jake Hambye994d462014-02-03 13:10:13 -08005623 }
5624
5625 /**
5626 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5627 * Used for device configuration by some CDMA operators.
5628 *
5629 * @param preferredRoamingList byte array containing the new PRL
5630 * @return true on success; false on any failure
5631 */
5632 @Override
5633 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636
5637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5640 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5641 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5642 return success;
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Jake Hambye994d462014-02-03 13:10:13 -08005646 }
5647
5648 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005649 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005650 * Used for device configuration by some CDMA operators.
5651 *
chen xu6dac5ab2018-10-26 17:39:23 -07005652 * @param slotIndex - device slot.
5653 *
Jake Hambye994d462014-02-03 13:10:13 -08005654 * @return true on success; false on any failure
5655 */
5656 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005657 public boolean resetModemConfig(int slotIndex) {
5658 Phone phone = PhoneFactory.getPhone(slotIndex);
5659 if (phone != null) {
5660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5661 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
chen xu6dac5ab2018-10-26 17:39:23 -07005663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5666 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5667 return success;
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 }
chen xu6dac5ab2018-10-26 17:39:23 -07005672 return false;
5673 }
5674
5675 /**
5676 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5677 *
5678 * @param slotIndex - device slot.
5679 *
5680 * @return true on success; false on any failure
5681 */
5682 @Override
5683 public boolean rebootModem(int slotIndex) {
5684 Phone phone = PhoneFactory.getPhone(slotIndex);
5685 if (phone != null) {
5686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5687 mApp, phone.getSubId(), "rebootModem");
5688
5689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5692 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5693 return success;
5694 } finally {
5695 Binder.restoreCallingIdentity(identity);
5696 }
5697 }
5698 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005699 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005700
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005701 public String[] getPcscfAddress(String apnType, String callingPackage,
5702 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005703 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5705 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005706 return new String[0];
5707 }
5708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 final long identity = Binder.clearCallingIdentity();
5710 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005711 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 } finally {
5713 Binder.restoreCallingIdentity(identity);
5714 }
Wink Saville36469e72014-06-11 15:17:00 -07005715 }
5716
Brad Ebinger51f743a2017-01-23 13:50:20 -08005717 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005718 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5719 * {@link #disableIms(int)}.
5720 * @param slotIndex device slot.
5721 */
5722 public void resetIms(int slotIndex) {
5723 enforceModifyPermission();
5724
5725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 if (mImsResolver == null) {
5728 // may happen if the does not support IMS.
5729 return;
5730 }
5731 mImsResolver.disableIms(slotIndex);
5732 mImsResolver.enableIms(slotIndex);
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
5736 }
5737
5738 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005739 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5740 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005741 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005742 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744
5745 final long identity = Binder.clearCallingIdentity();
5746 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005747 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005748 // may happen if the device does not support IMS.
5749 return;
5750 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005751 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005755 }
5756
5757 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005758 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5759 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005760 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005761 public void disableIms(int slotId) {
5762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005767 // may happen if the device does not support IMS.
5768 return;
5769 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005774 }
5775
5776 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005777 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5778 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005779 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005780 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005781 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005782 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783
5784 final long identity = Binder.clearCallingIdentity();
5785 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005786 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5788 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005789 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005790 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 } finally {
5792 Binder.restoreCallingIdentity(identity);
5793 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005794 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005795 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005796 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5797 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005798 @Override
5799 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005800 enforceModifyPermission();
5801
5802 final long identity = Binder.clearCallingIdentity();
5803 try {
5804 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005805 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
5809 }
5810
5811 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005812 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005813 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005814 */
5815 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005820 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005821 // may happen if the device does not support IMS.
5822 return null;
5823 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005824 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 } finally {
5826 Binder.restoreCallingIdentity(identity);
5827 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005828 }
5829
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005830 /**
5831 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005832 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005833 */
5834 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5835 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836
5837 final long identity = Binder.clearCallingIdentity();
5838 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005840 // may happen if the device does not support IMS.
5841 return null;
5842 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005843 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005847 }
5848
Brad Ebinger884c07b2018-02-15 16:17:40 -08005849 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005850 * Sets the ImsService Package Name that Telephony will bind to.
5851 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 * @param slotIndex the slot ID that the ImsService should bind for.
5853 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005854 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005855 * @param featureTypes An integer array of feature types associated with a packageName.
5856 * @param packageName The name of the package that the current configuration will be replaced
5857 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005858 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005859 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005860 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5861 int[] featureTypes, String packageName) {
5862 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5865 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 final long identity = Binder.clearCallingIdentity();
5869 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005871 // may happen if the device does not support IMS.
5872 return false;
5873 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005874 Map<Integer, String> featureConfig = new HashMap<>();
5875 for (int featureType : featureTypes) {
5876 featureConfig.put(featureType, packageName);
5877 }
5878 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5879 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005883 }
5884
5885 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005886 * Clears any carrier ImsService overrides for the slot index specified that were previously
5887 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5888 *
5889 * This should only be used for testing.
5890 *
5891 * @param slotIndex the slot ID that the ImsService should bind for.
5892 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5893 */
5894 @Override
5895 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5896 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5897 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5898 "clearCarrierImsServiceOverride");
5899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5900 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5901 "clearCarrierImsServiceOverride");
5902
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
5905 if (mImsResolver == null) {
5906 // may happen if the device does not support IMS.
5907 return false;
5908 }
5909 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
5913 }
5914
5915 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005916 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005917 *
5918 * @param slotId The slot that the ImsService is associated with.
5919 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5920 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005921 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005922 * @return the package name of the ImsService configuration.
5923 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5925 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005926 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005928 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005929 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5930 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 final long identity = Binder.clearCallingIdentity();
5933 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005934 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005935 // may happen if the device does not support IMS.
5936 return "";
5937 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005938 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005939 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5940 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005944 }
5945
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005946 /**
5947 * Get the MmTelFeature state associated with the requested subscription id.
5948 * @param subId The subscription that the MmTelFeature is associated with.
5949 * @param callback A callback with an integer containing the
5950 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5951 */
5952 @Override
5953 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5954 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5955 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5956 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5957 "IMS not available on device.");
5958 }
5959 final long token = Binder.clearCallingIdentity();
5960 try {
5961 int slotId = getSlotIndex(subId);
5962 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5963 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5964 + subId + "'");
5965 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5966 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005967 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005968 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5969 try {
5970 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5971 } catch (RemoteException e) {
5972 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5973 + "Ignore");
5974 }
5975 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005976 } catch (ImsException e) {
5977 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005978 } finally {
5979 Binder.restoreCallingIdentity(token);
5980 }
5981 }
5982
Daniel Brightbb5840b2021-01-12 15:48:18 -08005983 /**
5984 * Sets the ims registration state on all valid {@link Phone}s.
5985 */
5986 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005987 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988
5989 final long identity = Binder.clearCallingIdentity();
5990 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005991 // NOTE: Before S, this method only set the default phone.
5992 for (final Phone phone : PhoneFactory.getPhones()) {
5993 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5994 phone.setImsRegistrationState(registered);
5995 }
5996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
Wink Saville36469e72014-06-11 15:17:00 -07006000 }
6001
6002 /**
Stuart Scott54788802015-03-30 13:18:01 -07006003 * Set the network selection mode to automatic.
6004 *
6005 */
6006 @Override
6007 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6009 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
6011 final long identity = Binder.clearCallingIdentity();
6012 try {
shilufc958392020-01-20 11:36:01 -08006013 if (!isActiveSubscription(subId)) {
6014 return;
6015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006017 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6018 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Stuart Scott54788802015-03-30 13:18:01 -07006022 }
6023
Jack Yud10cdd42020-09-28 20:28:01 -07006024 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006025 * Ask the radio to connect to the input network and change selection mode to manual.
6026 *
6027 * @param subId the id of the subscription.
6028 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6029 * the operator to attach to.
6030 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6031 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6032 * normal network selection next time.
6033 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006034 */
6035 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006036 public boolean setNetworkSelectionModeManual(
6037 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6039 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006040
6041 if (!isActiveSubscription(subId)) {
6042 return false;
6043 }
6044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 final long identity = Binder.clearCallingIdentity();
6046 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006047 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006049 if (DBG) {
6050 log("setNetworkSelectionModeManual: subId: " + subId
6051 + " operator: " + operatorInfo);
6052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6054 } finally {
6055 Binder.restoreCallingIdentity(identity);
6056 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006057 }
shilu84f6e8b2019-12-19 13:58:01 -08006058 /**
6059 * Get the manual network selection
6060 *
6061 * @param subId the id of the subscription.
6062 *
6063 * @return the previously saved user selected PLMN
6064 */
6065 @Override
6066 public String getManualNetworkSelectionPlmn(int subId) {
6067 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006068 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006069 mApp, subId, "getManualNetworkSelectionPlmn");
6070
6071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006074 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006075 }
6076
6077 final Phone phone = getPhone(subId);
6078 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006079 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006080 }
6081 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6082 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6083 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
6087 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006088
6089 /**
6090 * Scans for available networks.
6091 */
6092 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006093 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6094 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6096 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006097 LocationAccessPolicy.LocationPermissionResult locationResult =
6098 LocationAccessPolicy.checkLocationPermission(mApp,
6099 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6100 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006101 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006102 .setCallingPid(Binder.getCallingPid())
6103 .setCallingUid(Binder.getCallingUid())
6104 .setMethod("getCellNetworkScanResults")
6105 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006106 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6107 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006108 .build());
6109 switch (locationResult) {
6110 case DENIED_HARD:
6111 throw new SecurityException("Not allowed to access scan results -- location");
6112 case DENIED_SOFT:
6113 return null;
6114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115
Pengquan Menga1bb6272018-09-06 09:59:22 -07006116 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 try {
6118 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006119 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006124 }
6125
6126 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006127 * Get the call forwarding info, given the call forwarding reason.
6128 */
6129 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006130 public void getCallForwarding(int subId, int callForwardingReason,
6131 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006132 enforceReadPrivilegedPermission("getCallForwarding");
6133 long identity = Binder.clearCallingIdentity();
6134 try {
6135 if (DBG) {
6136 log("getCallForwarding: subId " + subId
6137 + " callForwardingReason" + callForwardingReason);
6138 }
Hall Liu27d24262020-09-18 19:04:59 -07006139
6140 Phone phone = getPhone(subId);
6141 if (phone == null) {
6142 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006143 callback.onError(
6144 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006145 } catch (RemoteException e) {
6146 // ignore
6147 }
6148 return;
6149 }
6150
6151 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6152 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6153 @Override
6154 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6155 try {
6156 callback.onCallForwardingInfoAvailable(info);
6157 } catch (RemoteException e) {
6158 // ignore
6159 }
6160 }
6161
6162 @Override
6163 public void onError(int error) {
6164 try {
6165 callback.onError(error);
6166 } catch (RemoteException e) {
6167 // ignore
6168 }
6169 }
6170 });
6171 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
6175 }
6176
6177 /**
6178 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6179 * reason, the number to forward, and the timeout before the forwarding is attempted.
6180 */
6181 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006182 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6183 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006184 enforceModifyPermission();
6185 long identity = Binder.clearCallingIdentity();
6186 try {
6187 if (DBG) {
6188 log("setCallForwarding: subId " + subId
6189 + " callForwardingInfo" + callForwardingInfo);
6190 }
Hall Liu27d24262020-09-18 19:04:59 -07006191
6192 Phone phone = getPhone(subId);
6193 if (phone == null) {
6194 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006195 callback.accept(
6196 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006197 } catch (RemoteException e) {
6198 // ignore
6199 }
6200 return;
6201 }
6202
6203 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6204 FunctionalUtils.ignoreRemoteException(callback::accept));
6205
6206 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
6210 }
6211
6212 /**
Hall Liu27d24262020-09-18 19:04:59 -07006213 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006214 */
6215 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006216 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006217 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006218 long identity = Binder.clearCallingIdentity();
6219 try {
Hall Liu27d24262020-09-18 19:04:59 -07006220 Phone phone = getPhone(subId);
6221 if (phone == null) {
6222 try {
6223 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6224 } catch (RemoteException e) {
6225 // ignore
6226 }
6227 return;
6228 }
SongFerngWang0e767992021-03-31 22:08:45 +08006229 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6230 PersistableBundle c = configManager.getConfigForSubId(subId);
6231 boolean requireUssd = c.getBoolean(
6232 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006233
Shuo Qian4a594052020-01-23 11:59:30 -08006234 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006235 if (requireUssd) {
6236 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6237 getSubscriptionCarrierId(subId));
6238 String newUssdCommand = "";
6239 try {
6240 newUssdCommand = carrierXmlParser.getFeature(
6241 CarrierXmlParser.FEATURE_CALL_WAITING)
6242 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6243 } catch (NullPointerException e) {
6244 loge("Failed to generate USSD number" + e);
6245 }
6246 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6247 mMainThreadHandler, callback, carrierXmlParser,
6248 CarrierXmlParser.SsEntry.SSAction.QUERY);
6249 final String ussdCommand = newUssdCommand;
6250 Executors.newSingleThreadExecutor().execute(() -> {
6251 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6252 });
6253 } else {
6254 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6255 callback::accept);
6256 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6257 }
Shuo Qian4a594052020-01-23 11:59:30 -08006258 } finally {
6259 Binder.restoreCallingIdentity(identity);
6260 }
6261 }
6262
6263 /**
Hall Liu27d24262020-09-18 19:04:59 -07006264 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006265 */
6266 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006267 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006268 enforceModifyPermission();
6269 long identity = Binder.clearCallingIdentity();
6270 try {
Hall Liu27d24262020-09-18 19:04:59 -07006271 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6272
6273 Phone phone = getPhone(subId);
6274 if (phone == null) {
6275 try {
6276 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6277 } catch (RemoteException e) {
6278 // ignore
6279 }
6280 return;
6281 }
6282
SongFerngWang0e767992021-03-31 22:08:45 +08006283 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6284 PersistableBundle c = configManager.getConfigForSubId(subId);
6285 boolean requireUssd = c.getBoolean(
6286 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006287
SongFerngWang0e767992021-03-31 22:08:45 +08006288 if (DBG) log("getCallWaitingStatus: subId " + subId);
6289 if (requireUssd) {
6290 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6291 getSubscriptionCarrierId(subId));
6292 CarrierXmlParser.SsEntry.SSAction ssAction =
6293 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6294 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6295 String newUssdCommand = "";
6296 try {
6297 newUssdCommand = carrierXmlParser.getFeature(
6298 CarrierXmlParser.FEATURE_CALL_WAITING)
6299 .makeCommand(ssAction, null);
6300 } catch (NullPointerException e) {
6301 loge("Failed to generate USSD number" + e);
6302 }
6303 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6304 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6305 final String ussdCommand = newUssdCommand;
6306 Executors.newSingleThreadExecutor().execute(() -> {
6307 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6308 });
6309 } else {
6310 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6311 FunctionalUtils.ignoreRemoteException(callback::accept));
6312
6313 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6314 }
Shuo Qian4a594052020-01-23 11:59:30 -08006315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
6318 }
6319
6320 /**
yinxub1bed742017-04-17 11:45:04 -07006321 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006322 *
yinxub1bed742017-04-17 11:45:04 -07006323 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006324 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6325 * location related information which will be sent if the caller already possess
6326 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006327 * @param request contains the radio access networks with bands/channels to scan
6328 * @param messenger callback messenger for scan results or errors
6329 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006330 * @return the id of the requested scan which can be used to stop the scan.
6331 */
6332 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006333 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6334 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006335 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6337 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006338 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006339 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6340 if (!renounceFineLocationAccess) {
6341 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6342 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6343 .setCallingPackage(callingPackage)
6344 .setCallingFeatureId(callingFeatureId)
6345 .setCallingPid(Binder.getCallingPid())
6346 .setCallingUid(Binder.getCallingUid())
6347 .setMethod("requestNetworkScan")
6348 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6349 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6350 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6351 .build());
6352 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006354 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6355 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006356 if (e != null) {
6357 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6358 throw e;
6359 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006360 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006361 return TelephonyScanManager.INVALID_SCAN_ID;
6362 }
6363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 }
Hall Liu912dfd32019-04-25 14:02:26 -07006365 int callingUid = Binder.getCallingUid();
6366 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006367 final long identity = Binder.clearCallingIdentity();
6368 try {
6369 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006370 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006371 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
yinxu504e1392017-04-12 16:03:22 -07006375 }
6376
Hall Liub2ac8ef2019-02-28 15:56:23 -08006377 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006378 NetworkScanRequest request, int subId, String callingPackage) {
6379 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006380 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6381 boolean hasNetworkScanPermission =
6382 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6383 == PERMISSION_GRANTED;
6384
6385 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6386 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6387 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006388 }
6389
6390 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6391 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006392 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6393 return new SecurityException("Specific channels must not be"
6394 + " scanned without location access.");
6395 }
6396 }
6397 }
6398
Hall Liub2ac8ef2019-02-28 15:56:23 -08006399 return null;
6400 }
6401
yinxu504e1392017-04-12 16:03:22 -07006402 /**
6403 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006404 *
6405 * @param subId id of the subscription
6406 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006407 */
6408 @Override
6409 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6411 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412
Hall Liu912dfd32019-04-25 14:02:26 -07006413 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 final long identity = Binder.clearCallingIdentity();
6415 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006416 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
yinxu504e1392017-04-12 16:03:22 -07006420 }
6421
6422 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006423 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006424 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006425 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006426 */
6427 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006428 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006429 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006430 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006431 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432
6433 final long identity = Binder.clearCallingIdentity();
6434 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006435 if (DBG) log("getAllowedNetworkTypesBitmask");
6436 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6437 int networkTypesBitmask = (result != null ? result[0] : -1);
6438 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6439 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006443 }
6444
6445 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006446 * Get the allowed network types for certain reason.
6447 *
6448 * @param subId the id of the subscription.
6449 * @param reason the reason the allowed network type change is taking place
6450 * @return the allowed network types.
6451 */
6452 @Override
6453 public long getAllowedNetworkTypesForReason(int subId,
6454 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006455 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006456 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006457 final long identity = Binder.clearCallingIdentity();
6458 try {
6459 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
6463 }
6464
6465 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006466 * Enable/Disable E-UTRA-NR Dual Connectivity
6467 * @param subId subscription id of the sim card
6468 * @param nrDualConnectivityState expected NR dual connectivity state
6469 * This can be passed following states
6470 * <ol>
6471 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6472 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6473 * <li>Disable NR dual connectivity and force secondary cell to be released
6474 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6475 * </ol>
6476 * @return operation result.
6477 */
6478 @Override
6479 public int setNrDualConnectivityState(int subId,
6480 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6482 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006483 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006484 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6485 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6486 }
6487
Sooraj Sasindran37444802020-08-11 10:40:43 -07006488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6489 final long identity = Binder.clearCallingIdentity();
6490 try {
6491 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6492 nrDualConnectivityState, subId,
6493 workSource);
6494 if (DBG) log("enableNRDualConnectivity result: " + result);
6495 return result;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
6499 }
6500
6501 /**
6502 * Is E-UTRA-NR Dual Connectivity enabled
6503 * @return true if dual connectivity is enabled else false
6504 */
6505 @Override
6506 public boolean isNrDualConnectivityEnabled(int subId) {
6507 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006508 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006509 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006510 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006511 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6512 return false;
6513 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006514 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6518 null, subId, workSource);
6519 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6520 return isEnabled;
6521 } finally {
6522 Binder.restoreCallingIdentity(identity);
6523 }
6524 }
6525
6526 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006527 * Set the allowed network types of the device and
6528 * provide the reason triggering the allowed network change.
6529 *
6530 * @param subId the id of the subscription.
6531 * @param reason the reason the allowed network type change is taking place
6532 * @param allowedNetworkTypes the allowed network types.
6533 * @return true on success; false on any failure.
6534 */
6535 @Override
6536 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006537 @TelephonyManager.AllowedNetworkTypesReason int reason,
6538 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6540 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006542 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6543 return false;
6544 }
6545 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6546 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 return false;
6548 }
6549
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006550 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6551 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6552
6553
6554 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6555 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6556 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006558
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006559 final long identity = Binder.clearCallingIdentity();
6560 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006561 Boolean success = (Boolean) sendRequest(
6562 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6563 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6564
6565 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6566 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006567 } finally {
6568 Binder.restoreCallingIdentity(identity);
6569 }
6570 }
6571
6572 /**
Miaoa84611c2019-03-15 09:21:10 +08006573 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006574 *
Miaoa84611c2019-03-15 09:21:10 +08006575 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006576 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006577 * @hide
6578 */
6579 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006580 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006583 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 try {
Miaoa84611c2019-03-15 09:21:10 +08006585 if (phone != null) {
6586 return phone.hasMatchedTetherApnSetting();
6587 } else {
6588 return false;
6589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 } finally {
6591 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006592 }
Junda Liu475951f2014-11-07 16:45:03 -08006593 }
6594
6595 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006596 * Get the user enabled state of Mobile Data.
6597 *
6598 * TODO: remove and use isUserDataEnabled.
6599 * This can't be removed now because some vendor codes
6600 * calls through ITelephony directly while they should
6601 * use TelephonyManager.
6602 *
6603 * @return true on enabled
6604 */
6605 @Override
6606 public boolean getDataEnabled(int subId) {
6607 return isUserDataEnabled(subId);
6608 }
6609
6610 /**
6611 * Get whether mobile data is enabled per user setting.
6612 *
6613 * There are other factors deciding whether mobile data is actually enabled, but they are
6614 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006615 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006616 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6617 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006618 *
6619 * @return {@code true} if data is enabled else {@code false}
6620 */
6621 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006622 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006623 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006624 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006625 try {
6626 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6627 functionName);
6628 } catch (Exception e) {
6629 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6630 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006631 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006633 mApp, subId, functionName);
6634
Robert Greenwalt646120a2014-05-23 11:54:03 -07006635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 int phoneId = mSubscriptionController.getPhoneId(subId);
6640 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6641 Phone phone = PhoneFactory.getPhone(phoneId);
6642 if (phone != null) {
6643 boolean retVal = phone.isUserDataEnabled();
6644 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6645 return retVal;
6646 } else {
6647 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6648 return false;
6649 }
6650 } finally {
6651 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006652 }
6653 }
6654
6655 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006656 * Checks if the device is capable of mobile data by considering whether whether the
6657 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6658 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006659 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006660 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006661 */
6662 @Override
6663 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006664 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 try {
6666 try {
6667 mApp.enforceCallingOrSelfPermission(
6668 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006669 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006670 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006671 try {
6672 mApp.enforceCallingOrSelfPermission(
6673 android.Manifest.permission.READ_PHONE_STATE,
6674 functionName);
6675 } catch (Exception e2) {
6676 mApp.enforceCallingOrSelfPermission(
6677 permission.READ_BASIC_PHONE_STATE, functionName);
6678 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006679 }
6680 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006681 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683
6684 final long identity = Binder.clearCallingIdentity();
6685 try {
6686 int phoneId = mSubscriptionController.getPhoneId(subId);
6687 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6688 Phone phone = PhoneFactory.getPhone(phoneId);
6689 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006690 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006691 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6692 return retVal;
6693 } else {
6694 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6695 return false;
6696 }
6697 } finally {
6698 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006699 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006700 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006701
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006702 /**
6703 * Check if data is enabled for a specific reason
6704 * @param subId Subscription index
6705 * @param reason the reason the data enable change is taking place
6706 * @return {@code true} if the overall data is enabled; {@code false} if not.
6707 */
6708 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006709 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006710 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006711 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006712 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006713 try {
6714 mApp.enforceCallingOrSelfPermission(
6715 android.Manifest.permission.ACCESS_NETWORK_STATE,
6716 functionName);
6717 } catch (Exception e) {
6718 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6719 functionName);
6720 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006721 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006722 try {
6723 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006724 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006725 } catch (Exception e2) {
6726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006727 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006728 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006729 }
6730
6731
6732 final long identity = Binder.clearCallingIdentity();
6733 try {
6734 int phoneId = mSubscriptionController.getPhoneId(subId);
6735 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006736 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006737 + " reason=" + reason);
6738 }
6739 Phone phone = PhoneFactory.getPhone(phoneId);
6740 if (phone != null) {
6741 boolean retVal;
6742 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6743 retVal = phone.isUserDataEnabled();
6744 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006745 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006746 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006747 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006748 return retVal;
6749 } else {
6750 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006751 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006752 + subId + " retVal=false");
6753 }
6754 return false;
6755 }
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
6758 }
6759 }
6760
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006761 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006762 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006763 if (uid == Process.PHONE_UID) {
6764 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6765 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6767 }
6768
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006769 //load access rules from carrier configs, and check those as well: b/139133814
6770 SubscriptionController subController = SubscriptionController.getInstance();
6771 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6772 || subController == null) return privilegeFromSim;
6773
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006774 PackageManager pkgMgr = phone.getContext().getPackageManager();
6775 String[] packages = pkgMgr.getPackagesForUid(uid);
6776
6777 final long identity = Binder.clearCallingIdentity();
6778 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006779 int subId = phone.getSubId();
6780 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6781 // A test override is in place for the privileges for this subId, so don't try to
6782 // read the subscription privileges.
6783 return privilegeFromSim;
6784 }
6785 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006786 SubscriptionManager subManager = (SubscriptionManager)
6787 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6788 for (String pkg : packages) {
6789 if (subManager.canManageSubscription(subInfo, pkg)) {
6790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6791 }
6792 }
6793 return privilegeFromSim;
6794 } finally {
6795 Binder.restoreCallingIdentity(identity);
6796 }
6797 }
6798
6799 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6800 String pkgName) {
6801 //load access rules from carrier configs, and check those as well: b/139133814
6802 SubscriptionController subController = SubscriptionController.getInstance();
6803 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6804 || subController == null) return privilegeFromSim;
6805
6806 final long identity = Binder.clearCallingIdentity();
6807 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006808 int subId = phone.getSubId();
6809 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6810 // A test override is in place for the privileges for this subId, so don't try to
6811 // read the subscription privileges.
6812 return privilegeFromSim;
6813 }
6814 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006815 SubscriptionManager subManager = (SubscriptionManager)
6816 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6817 return subManager.canManageSubscription(subInfo, pkgName)
6818 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
6821 }
6822 }
6823
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006824 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006825 public int getCarrierPrivilegeStatus(int subId) {
6826 final Phone phone = getPhone(subId);
6827 if (phone == null) {
6828 loge("getCarrierPrivilegeStatus: Invalid subId");
6829 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6830 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006831 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6832 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006833 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006834 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6835 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006836
6837 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006838 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006839 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006840 }
Junda Liu29340342014-07-10 15:23:27 -07006841
6842 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006843 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006844 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006845 final Phone phone = getPhone(subId);
6846 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006847 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006848 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6849 }
6850 UiccProfile profile =
6851 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6852 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006853 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6855 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006856 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006857 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006858 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006859 }
6860
6861 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006862 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006863 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006864 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006865 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006866 }
6867
6868 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006869 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6870 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006871 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006872 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6873 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006874 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006875 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006876 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006877 }
6878
6879 @Override
6880 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006881 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006882 if (TextUtils.isEmpty(pkgName))
6883 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006884 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6885 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006886 UiccPort port = UiccController.getInstance().getUiccPort(i);
6887 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006888 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006889 continue;
6890 }
6891
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006892 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006893 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006894 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006895 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6896 break;
6897 }
6898 }
6899
6900 return result;
Junda Liu29340342014-07-10 15:23:27 -07006901 }
Derek Tan89e89d42014-07-08 17:00:10 -07006902
6903 @Override
Junda Liue64de782015-04-16 17:19:16 -07006904 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006905 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006906 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6907 loge("phoneId " + phoneId + " is not valid.");
6908 return null;
6909 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006910 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6911 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006912 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006913 return null ;
6914 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006915 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006916 }
6917
Amith Yamasani6e118872016-02-19 12:53:51 -08006918 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006919 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006920 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006921 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006922 List<String> privilegedPackages = new ArrayList<>();
6923 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006924 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006925 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006926 if (port != null) {
6927 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006928 if (packages == null) {
6929 // Only check packages in user 0 for now
6930 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006931 PackageManager.MATCH_DISABLED_COMPONENTS
6932 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006933 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006934 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006935 }
6936 for (int p = packages.size() - 1; p >= 0; p--) {
6937 PackageInfo pkgInfo = packages.get(p);
6938 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006939 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006940 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006941 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006942 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006943 privilegedPackages.add(pkgInfo.packageName);
6944 }
6945 }
6946 }
6947 }
6948 return privilegedPackages;
6949 }
6950
chen xuf7e9fe82019-05-09 19:31:02 -07006951 @Override
6952 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006953 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6954
6955 final long identity = Binder.clearCallingIdentity();
6956
chen xuf7e9fe82019-05-09 19:31:02 -07006957 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006958 try {
6959 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6960 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6961 }
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006964 }
6965 return privilegedPackages;
6966 }
6967
Wink Savilleb564aae2014-10-23 10:18:09 -07006968 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006969 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006970 UiccPort port = phone == null ? null : phone.getUiccPort();
6971 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006972 return null;
6973 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006974 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006975 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006976 return null;
6977 }
6978 return iccId;
6979 }
6980
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006981 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006982 public void setCallComposerStatus(int subId, int status) {
6983 enforceModifyPermission();
6984
6985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 Phone phone = getPhone(subId);
6988 if (phone != null) {
6989 Phone defaultPhone = phone.getImsPhone();
6990 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6991 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6992 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006993 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6994 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006995 }
6996 }
Shuo Qian284ae752020-12-22 19:10:14 -08006997 } catch (ImsException e) {
6998 throw new ServiceSpecificException(e.getCode());
6999 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007000 Binder.restoreCallingIdentity(identity);
7001 }
7002 }
7003
7004 @Override
7005 public int getCallComposerStatus(int subId) {
7006 enforceReadPrivilegedPermission("getCallComposerStatus");
7007
7008 final long identity = Binder.clearCallingIdentity();
7009 try {
7010 Phone phone = getPhone(subId);
7011 if (phone != null) {
7012 Phone defaultPhone = phone.getImsPhone();
7013 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7014 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7015 return imsPhone.getCallComposerStatus();
7016 }
7017 }
7018 } finally {
7019 Binder.restoreCallingIdentity(identity);
7020 }
7021 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7022 }
7023
7024 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007025 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7026 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007027 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007028 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 final long identity = Binder.clearCallingIdentity();
7031 try {
7032 final String iccId = getIccId(subId);
7033 final Phone phone = getPhone(subId);
7034 if (phone == null) {
7035 return false;
7036 }
7037 final String subscriberId = phone.getSubscriberId();
7038
7039 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007040 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 + subscriberId + " to " + number);
7042 }
7043
7044 if (TextUtils.isEmpty(iccId)) {
7045 return false;
7046 }
7047
7048 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7049
7050 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7051 if (alphaTag == null) {
7052 editor.remove(alphaTagPrefKey);
7053 } else {
7054 editor.putString(alphaTagPrefKey, alphaTag);
7055 }
7056
7057 // Record both the line number and IMSI for this ICCID, since we need to
7058 // track all merged IMSIs based on line number
7059 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7060 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7061 if (number == null) {
7062 editor.remove(numberPrefKey);
7063 editor.remove(subscriberPrefKey);
7064 } else {
7065 editor.putString(numberPrefKey, number);
7066 editor.putString(subscriberPrefKey, subscriberId);
7067 }
7068
7069 editor.commit();
7070 return true;
7071 } finally {
7072 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007073 }
Derek Tan7226c842014-07-02 17:42:23 -07007074 }
7075
7076 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007077 public String getLine1NumberForDisplay(int subId, String callingPackage,
7078 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007079 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007081 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007082 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007083 return null;
7084 }
Derek Tan97ebb422014-09-05 16:55:38 -07007085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 final long identity = Binder.clearCallingIdentity();
7087 try {
7088 String iccId = getIccId(subId);
7089 if (iccId != null) {
7090 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7091 if (DBG_MERGE) {
7092 log("getLine1NumberForDisplay returning "
7093 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7094 }
7095 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7098 return null;
7099 } finally {
7100 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007101 }
Derek Tan7226c842014-07-02 17:42:23 -07007102 }
7103
7104 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007105 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7106 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007108 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007109 return null;
7110 }
Derek Tan97ebb422014-09-05 16:55:38 -07007111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112 final long identity = Binder.clearCallingIdentity();
7113 try {
7114 String iccId = getIccId(subId);
7115 if (iccId != null) {
7116 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7117 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7118 }
7119 return null;
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007122 }
Derek Tan7226c842014-07-02 17:42:23 -07007123 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007124
7125 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007126 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7127 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007128 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7129 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007131 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007132 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007133 return null;
7134 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007135
Jordan Liub49b04b2019-05-06 14:45:15 -07007136 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7137 // the process, where TelephonyManager was instantiated.
7138 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007139 final long identity = Binder.clearCallingIdentity();
7140 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007141 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 final TelephonyManager tele = TelephonyManager.from(context);
7143 final SubscriptionManager sub = SubscriptionManager.from(context);
7144
7145 // Figure out what subscribers are currently active
7146 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147
Jordan Liub49b04b2019-05-06 14:45:15 -07007148 // Only consider subs which match the current subId
7149 // This logic can be simplified. See b/131189269 for progress.
7150 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007151 activeSubscriberIds.add(tele.getSubscriberId(subId));
7152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153
7154 // First pass, find a number override for an active subscriber
7155 String mergeNumber = null;
7156 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7157 for (String key : prefs.keySet()) {
7158 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7159 final String subscriberId = (String) prefs.get(key);
7160 if (activeSubscriberIds.contains(subscriberId)) {
7161 final String iccId = key.substring(
7162 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7163 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7164 mergeNumber = (String) prefs.get(numberKey);
7165 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007166 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167 + " for active subscriber " + subscriberId);
7168 }
7169 if (!TextUtils.isEmpty(mergeNumber)) {
7170 break;
7171 }
7172 }
7173 }
7174 }
7175
7176 // Shortcut when no active merged subscribers
7177 if (TextUtils.isEmpty(mergeNumber)) {
7178 return null;
7179 }
7180
7181 // Second pass, find all subscribers under that line override
7182 final ArraySet<String> result = new ArraySet<>();
7183 for (String key : prefs.keySet()) {
7184 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7185 final String number = (String) prefs.get(key);
7186 if (mergeNumber.equals(number)) {
7187 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7188 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7189 final String subscriberId = (String) prefs.get(subscriberKey);
7190 if (!TextUtils.isEmpty(subscriberId)) {
7191 result.add(subscriberId);
7192 }
7193 }
7194 }
7195 }
7196
7197 final String[] resultArray = result.toArray(new String[result.size()]);
7198 Arrays.sort(resultArray);
7199 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007200 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7202 }
7203 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007204 } finally {
7205 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007206 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007207 }
7208
7209 @Override
zoey chen38003472019-12-13 17:16:31 +08007210 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7211 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007212
7213 final long identity = Binder.clearCallingIdentity();
7214 try {
7215 final TelephonyManager telephonyManager = mApp.getSystemService(
7216 TelephonyManager.class);
7217 String subscriberId = telephonyManager.getSubscriberId(subId);
7218 if (subscriberId == null) {
7219 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007220 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007221 + subId);
7222 }
7223 return null;
7224 }
7225
7226 final SubscriptionInfo info = SubscriptionController.getInstance()
7227 .getSubscriptionInfo(subId);
7228 final ParcelUuid groupUuid = info.getGroupUuid();
7229 // If it doesn't belong to any group, return just subscriberId of itself.
7230 if (groupUuid == null) {
7231 return new String[]{subscriberId};
7232 }
7233
7234 // Get all subscriberIds from the group.
7235 final List<String> mergedSubscriberIds = new ArrayList<>();
7236 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007237 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007238 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007239 for (SubscriptionInfo subInfo : groupInfos) {
7240 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7241 if (subscriberId != null) {
7242 mergedSubscriberIds.add(subscriberId);
7243 }
7244 }
7245
7246 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7247 } finally {
7248 Binder.restoreCallingIdentity(identity);
7249
7250 }
7251 }
7252
7253 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007254 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007255 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007256 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257
7258 final long identity = Binder.clearCallingIdentity();
7259 try {
7260 final Phone phone = getPhone(subId);
7261 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007265 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007266
7267 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007268 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007269 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7270 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007271 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7272 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007273
7274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 final Phone phone = getPhone(subId);
7277 if (phone == null) {
7278 return false;
7279 }
7280 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7281 cdmaNonRoamingList);
7282 } finally {
7283 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007284 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007285 }
7286
7287 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007288 @Deprecated
7289 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7290 enforceModifyPermission();
7291
7292 int returnValue = 0;
7293 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007294 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007295 if(result.exception == null) {
7296 if (result.result != null) {
7297 byte[] responseData = (byte[])(result.result);
7298 if(responseData.length > oemResp.length) {
7299 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7300 responseData.length + "bytes. Buffer Size is " +
7301 oemResp.length + "bytes.");
7302 }
7303 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7304 returnValue = responseData.length;
7305 }
7306 } else {
7307 CommandException ex = (CommandException) result.exception;
7308 returnValue = ex.getCommandError().ordinal();
7309 if(returnValue > 0) returnValue *= -1;
7310 }
7311 } catch (RuntimeException e) {
7312 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7313 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7314 if(returnValue > 0) returnValue *= -1;
7315 }
7316
7317 return returnValue;
7318 }
7319
7320 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007321 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007322 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007323 try {
7324 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007325 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007326 mApp, phone.getSubId(), "getRadioAccessFamily");
7327 } catch (SecurityException e) {
7328 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7329 throw e;
7330 }
chen xub97461a2018-10-26 14:17:57 -07007331 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007332 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007333 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007334 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 final long identity = Binder.clearCallingIdentity();
7336 try {
chen xub97461a2018-10-26 14:17:57 -07007337 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007338 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007339 mApp, phone.getSubId(), "getRadioAccessFamily");
7340 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
chen xub97461a2018-10-26 14:17:57 -07007344 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007345 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007346
7347 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007348 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007349 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007350 try {
7351 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7352 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007353 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007354 }
7355 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007356 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007357 }
7358 RoleManager rm = mApp.getSystemService(RoleManager.class);
7359 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7360 if (!dialerRoleHolders.contains(callingPackage)) {
7361 throw new SecurityException("App must be the dialer role holder to"
7362 + " upload a call composer pic");
7363 }
7364
7365 Executors.newSingleThreadExecutor().execute(() -> {
7366 ByteArrayOutputStream output = new ByteArrayOutputStream(
7367 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7368 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7369 boolean readUntilEnd = false;
7370 int totalBytesRead = 0;
7371 byte[] buffer = new byte[16 * 1024];
7372 while (true) {
7373 int numRead;
7374 try {
7375 numRead = input.read(buffer);
7376 } catch (IOException e) {
7377 try {
7378 fd.checkError();
7379 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7380 null);
7381 } catch (IOException e1) {
7382 // This means that the other side closed explicitly with an error. If this
7383 // happens, log and ignore.
7384 loge("Remote end of call composer picture pipe closed: " + e1);
7385 }
7386 break;
7387 }
7388 if (numRead == -1) {
7389 readUntilEnd = true;
7390 break;
7391 }
7392 totalBytesRead += numRead;
7393 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7394 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7395 try {
7396 input.close();
7397 } catch (IOException e) {
7398 // ignore
7399 }
7400 break;
7401 }
7402 output.write(buffer, 0, numRead);
7403 }
7404 // Generally, the remote end will close the file descriptors. The only case where we
7405 // close is above, where the picture size is too big.
7406
7407 try {
7408 fd.checkError();
7409 } catch (IOException e) {
7410 loge("Remote end for call composer closed with an error: " + e);
7411 return;
7412 }
7413
Hall Liuaa4211e2021-01-20 15:43:39 -08007414 if (!readUntilEnd) {
7415 loge("Did not finish reading entire image; aborting");
7416 return;
7417 }
Hall Liu82694d52020-12-11 18:22:04 -08007418
Hall Liuaa4211e2021-01-20 15:43:39 -08007419 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7420 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7421 new CallComposerPictureTransfer.Factory() {},
7422 imageData,
7423 (result) -> {
7424 if (result.first != null) {
7425 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7426 Bundle outputResult = new Bundle();
7427 outputResult.putParcelable(
7428 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7429 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7430 outputResult);
7431 } else {
7432 callback.send(result.second, null);
7433 }
7434 }
7435 );
Hall Liu82694d52020-12-11 18:22:04 -08007436 });
7437 }
7438
7439 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007440 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007441 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007442 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443
7444 final long identity = Binder.clearCallingIdentity();
7445 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007446 ImsManager.getInstance(defaultPhone.getContext(),
7447 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 } finally {
7449 Binder.restoreCallingIdentity(identity);
7450 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007451 }
7452
7453 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007454 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007455 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7457 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007458 return false;
7459 }
Svet Ganovb320e182015-04-16 12:30:10 -07007460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 final long identity = Binder.clearCallingIdentity();
7462 try {
7463 // Check the user preference and the system-level IMS setting. Even if the user has
7464 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7465 // In the long run, we may instead need to check if there exists a connection service
7466 // which can support video calling.
7467 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007468 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 return imsManager.isVtEnabledByPlatform()
7470 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7471 && imsManager.isVtEnabledByUser();
7472 } finally {
7473 Binder.restoreCallingIdentity(identity);
7474 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007475 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007476
Andrew Leea1239f22015-03-02 17:44:07 -08007477 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7479 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007481 mApp, subId, callingPackage, callingFeatureId,
7482 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 return false;
7484 }
7485
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
7488 CarrierConfigManager configManager =
7489 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007490 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Andrew Leea1239f22015-03-02 17:44:07 -08007495 }
7496
7497 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007498 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007500 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 return false;
7502 }
7503
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 CarrierConfigManager configManager =
7507 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007508 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
7512 }
Andrew Leea1239f22015-03-02 17:44:07 -08007513 }
7514
Andrew Lee9431b832015-03-09 18:46:45 -07007515 @Override
7516 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007517 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007518 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007519 }
7520
7521 @Override
7522 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 final long identity = Binder.clearCallingIdentity();
7524 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007525 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 } finally {
7527 Binder.restoreCallingIdentity(identity);
7528 }
Andrew Lee9431b832015-03-09 18:46:45 -07007529 }
7530
Hall Liuf6668912018-10-31 17:05:23 -07007531 /**
7532 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7533 * support for the feature and device firmware support.
7534 *
7535 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7536 */
7537 @Override
7538 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 final Phone phone = getPhone(subscriptionId);
7541 if (phone == null) {
7542 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7543 return false;
7544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007546 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7548 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 return isCarrierSupported && isDeviceSupported;
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
Hall Liu98187582018-01-22 19:15:32 -08007554 }
7555
Hall Liuf6668912018-10-31 17:05:23 -07007556 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007557 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7558 * RTT setting, will return true if the device and carrier both support RTT.
7559 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007560 */
7561 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 final long identity = Binder.clearCallingIdentity();
7563 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007564 boolean isRttSupported = isRttSupported(subscriptionId);
7565 boolean isUserRttSettingOn = Settings.Secure.getInt(
7566 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7567 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7568 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7569 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 } finally {
7571 Binder.restoreCallingIdentity(identity);
7572 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007573 }
7574
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007575 @Deprecated
7576 @Override
7577 public String getDeviceId(String callingPackage) {
7578 return getDeviceIdWithFeature(callingPackage, null);
7579 }
7580
Sanket Padawe7310cc72015-01-14 09:53:20 -08007581 /**
7582 * Returns the unique device ID of phone, for example, the IMEI for
7583 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7584 *
7585 * <p>Requires Permission:
7586 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7587 */
7588 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007589 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007590 try {
7591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7592 } catch (SecurityException se) {
7593 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7594 throw new SecurityException("Package " + callingPackage + " does not belong to "
7595 + Binder.getCallingUid());
7596 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007597 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007598 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007599 return null;
7600 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007601 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007602 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007603 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007604 return null;
7605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007606
7607 final long identity = Binder.clearCallingIdentity();
7608 try {
7609 return phone.getDeviceId();
7610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007613 }
7614
Ping Sunc67b7c22016-03-02 19:16:45 +08007615 /**
7616 * {@hide}
7617 * Returns the IMS Registration Status on a particular subid
7618 *
7619 * @param subId
7620 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007621 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007622 Phone phone = getPhone(subId);
7623 if (phone != null) {
7624 return phone.isImsRegistered();
7625 } else {
7626 return false;
7627 }
7628 }
7629
Santos Cordon7a1885b2015-02-03 11:15:19 -08007630 @Override
7631 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632 final long identity = Binder.clearCallingIdentity();
7633 try {
7634 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007638 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007639
Tyler Gunnf70ed162019-04-03 15:28:53 -07007640 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007641 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007642 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007643 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007644 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007645 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7646 }
7647 final long identity = Binder.clearCallingIdentity();
7648 try {
7649 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7650 } finally {
7651 Binder.restoreCallingIdentity(identity);
7652 }
7653 }
7654
7655 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007656 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007657 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007658 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007659 mApp,
7660 subscriptionId,
7661 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 Phone phone = getPhone(subscriptionId);
7665 if (phone == null) {
7666 return null;
7667 }
7668 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7669 } finally {
7670 Binder.restoreCallingIdentity(identity);
7671 }
7672 }
7673
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007674 /**
7675 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007676 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007677 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 Phone phone = getPhone(subId);
7681 if (phone != null) {
7682 return phone.isWifiCallingEnabled();
7683 } else {
7684 return false;
7685 }
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007688 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007689 }
7690
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007691 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007692 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007693 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007694 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 final long identity = Binder.clearCallingIdentity();
7696 try {
7697 Phone phone = getPhone(subId);
7698 if (phone != null) {
7699 return phone.isVideoEnabled();
7700 } else {
7701 return false;
7702 }
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007705 }
7706 }
7707
7708 /**
7709 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7710 * defined in {@link ImsRegistrationImplBase}.
7711 */
7712 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713 final long identity = Binder.clearCallingIdentity();
7714 try {
7715 Phone phone = getPhone(subId);
7716 if (phone != null) {
7717 return phone.getImsRegistrationTech();
7718 } else {
7719 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7720 }
7721 } finally {
7722 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007723 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007724 }
7725
Stuart Scott8eef64f2015-04-08 15:13:54 -07007726 @Override
7727 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007728 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007729 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7730 return;
7731 }
Kai Shif70f46f2021-03-03 13:59:46 -08007732 Phone defaultPhone = getDefaultPhone();
7733 if (defaultPhone != null) {
7734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7735 mApp, getDefaultPhone().getSubId(), "factoryReset");
7736 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007737 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007738
Svet Ganovcc087f82015-05-12 20:35:54 -07007739 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007740 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7741 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007742 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007743 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007744 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007745 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007746 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007747 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007748 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007749 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007750 // There has been issues when Sms raw table somehow stores orphan
7751 // fragments. They lead to garbled message when new fragments come
7752 // in and combined with those stale ones. In case this happens again,
7753 // user can reset all network settings which will clean up this table.
7754 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007755 // Clean up IMS settings as well here.
7756 int slotId = getSlotIndex(subId);
7757 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7758 ImsManager.getInstance(mApp, slotId).factoryReset();
7759 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007760
Kai Shif70f46f2021-03-03 13:59:46 -08007761 if (defaultPhone == null) {
7762 return;
7763 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007764 // Erase modem config if erase modem on network setting is enabled.
7765 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7766 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7767 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007768 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007769 }
Kai Shif70f46f2021-03-03 13:59:46 -08007770
7771 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007772 } finally {
7773 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007774 }
7775 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007776
SongFerngWangfd89b102021-05-27 22:44:54 +08007777 @VisibleForTesting
7778 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7779 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7780 return;
7781 }
7782 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7783 RILConstants.PREFERRED_NETWORK_MODE);
7784 SubscriptionManager.setSubscriptionProperty(subId,
7785 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7786 "user=" + defaultNetworkType);
7787 phone.loadAllowedNetworksFromSubscriptionDatabase();
7788 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7789 defaultNetworkType, null);
7790 }
7791
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007792 private void cleanUpSmsRawTable(Context context) {
7793 ContentResolver resolver = context.getContentResolver();
7794 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7795 resolver.delete(uri, null, null);
7796 }
7797
Narayan Kamath1c496c22015-04-16 14:40:19 +01007798 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007799 public String getSimLocaleForSubscriber(int subId) {
7800 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7801 final Phone phone = getPhone(subId);
7802 if (phone == null) {
7803 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007804 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 final long identity = Binder.clearCallingIdentity();
7807 try {
chen xu5d3637b2019-01-21 23:31:38 -08007808 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007809 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007810 if (info == null) {
7811 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7812 return null;
7813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 // Try and fetch the locale from the carrier properties or from the SIM language
7815 // preferences (EF-PL and EF-LI)...
7816 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007818 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7819 if (localeFromDefaultSim != null) {
7820 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7821 if (DBG) log("Using locale from subId: " + subId + " locale: "
7822 + localeFromDefaultSim);
7823 return localeFromDefaultSim.toLanguageTag();
7824 } else {
7825 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826 }
7827 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 // The SIM language preferences only store a language (e.g. fr = French), not an
7830 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7831 // the SIM and carrier preferences does not include a country we add the country
7832 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007833 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007835 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836 return mccLocale.toLanguageTag();
7837 }
7838
7839 if (DBG) log("No locale found - returning null");
7840 return null;
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007844 }
7845
7846 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007847 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007848 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007849 }
7850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 /**
7852 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7853 */
7854 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007855 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007856 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007857 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007858
Chenjie Yu1ba97252018-01-11 18:16:20 -08007859 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007860 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007861
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007862 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007863 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7864 * representing the state of the modem.
7865 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007866 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7867 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007868 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007869 */
7870 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007871 public void requestModemActivityInfo(ResultReceiver result) {
7872 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007873 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874
7875 final long identity = Binder.clearCallingIdentity();
7876 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007877 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878 } finally {
7879 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007880 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007881 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007882
Siddharth Rayb8114062018-06-17 15:02:38 -07007883 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7884 // less than total activity duration.
7885 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7886 if (info == null) {
7887 return false;
7888 }
7889 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007890 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7891 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7892
Siddharth Rayb8114062018-06-17 15:02:38 -07007893 return (info.isValid()
7894 && (info.getSleepTimeMillis() <= activityDurationMs)
7895 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007896 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007897 && (totalTxTimeMs <= activityDurationMs));
7898 }
7899
Jack Yu85bd38a2015-11-09 11:34:32 -08007900 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007901 * Returns the service state information on specified subscription.
7902 */
7903 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007904 public ServiceState getServiceStateForSubscriber(int subId,
7905 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7906 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007908 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007909 return null;
7910 }
7911
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007912 boolean hasFinePermission = false;
7913 boolean hasCoarsePermission = false;
7914 if (!renounceFineLocationAccess) {
7915 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7916 LocationAccessPolicy.checkLocationPermission(mApp,
7917 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7918 .setCallingPackage(callingPackage)
7919 .setCallingFeatureId(callingFeatureId)
7920 .setCallingPid(Binder.getCallingPid())
7921 .setCallingUid(Binder.getCallingUid())
7922 .setMethod("getServiceStateForSubscriber")
7923 .setLogAsInfo(true)
7924 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7925 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7926 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7927 .build());
7928 hasFinePermission =
7929 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7930 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007931
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007932 if (!renounceCoarseLocationAccess) {
7933 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7934 LocationAccessPolicy.checkLocationPermission(mApp,
7935 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7936 .setCallingPackage(callingPackage)
7937 .setCallingFeatureId(callingFeatureId)
7938 .setCallingPid(Binder.getCallingPid())
7939 .setCallingUid(Binder.getCallingUid())
7940 .setMethod("getServiceStateForSubscriber")
7941 .setLogAsInfo(true)
7942 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7943 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7944 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7945 .build());
7946 hasCoarsePermission =
7947 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7948 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007949
Jack Yu479f40e2020-10-27 21:29:25 -07007950 final Phone phone = getPhone(subId);
7951 if (phone == null) {
7952 return null;
7953 }
7954
Jordan Liu0f2bc442020-11-18 16:47:37 -08007955 final long identity = Binder.clearCallingIdentity();
7956
Jack Yu479f40e2020-10-27 21:29:25 -07007957 boolean isCallingPackageDataService = phone.getDataServicePackages()
7958 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007960 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7961 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7962 Rlog.d(LOG_TAG,
7963 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7964 return null;
7965 }
7966
Hall Liuf19c44f2018-11-27 14:38:17 -08007967 ServiceState ss = phone.getServiceState();
7968
7969 // Scrub out the location info in ServiceState depending on what level of access
7970 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007971 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007972 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7973 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974 } finally {
7975 Binder.restoreCallingIdentity(identity);
7976 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007977 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007978
7979 /**
7980 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7981 *
7982 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7983 * voicemail ringtone.
7984 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7985 * PhoneAccount.
7986 */
7987 @Override
7988 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 final long identity = Binder.clearCallingIdentity();
7990 try {
7991 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7992 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007993 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007994 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7997 } finally {
7998 Binder.restoreCallingIdentity(identity);
7999 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008000 }
8001
8002 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008003 * Sets the per-account voicemail ringtone.
8004 *
8005 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8006 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8007 *
8008 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8009 * voicemail ringtone.
8010 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8011 * PhoneAccount.
8012 */
8013 @Override
8014 public void setVoicemailRingtoneUri(String callingPackage,
8015 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008016 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008017 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008018 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8019 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8021 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8022 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024
8025 final long identity = Binder.clearCallingIdentity();
8026 try {
8027 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8028 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008029 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030 }
8031 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8032 } finally {
8033 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008034 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008035 }
8036
8037 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008038 * Returns whether vibration is set for voicemail notification in Phone settings.
8039 *
8040 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8041 * voicemail vibration setting.
8042 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8043 */
8044 @Override
8045 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008046 final long identity = Binder.clearCallingIdentity();
8047 try {
8048 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8049 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008050 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8054 } finally {
8055 Binder.restoreCallingIdentity(identity);
8056 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008057 }
8058
Youhan Wange64578a2016-05-02 15:32:42 -07008059 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008060 * Sets the per-account voicemail vibration.
8061 *
8062 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8063 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8064 *
8065 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8066 * voicemail vibration setting.
8067 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8068 * specific PhoneAccount.
8069 */
8070 @Override
8071 public void setVoicemailVibrationEnabled(String callingPackage,
8072 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008073 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008074 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008075 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8076 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8078 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8079 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008080 }
8081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008082 final long identity = Binder.clearCallingIdentity();
8083 try {
8084 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8085 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008086 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 }
8088 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8089 } finally {
8090 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008091 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008092 }
8093
8094 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008095 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8096 *
8097 * @throws SecurityException if the caller does not have the required permission
8098 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008099 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008100 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008101 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008102 }
8103
8104 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008105 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8106 * permission.
8107 *
8108 * @throws SecurityException if the caller does not have the required permission
8109 */
8110 private void enforceSendSmsPermission() {
8111 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8112 }
8113
8114 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008115 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008116 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008117 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008118 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008119 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008120 final long identity = Binder.clearCallingIdentity();
8121 try {
8122 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008123 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 if (componentName == null) {
8125 throw new SecurityException(
8126 "Caller not current active visual voicemail package[null]");
8127 }
8128 String vvmPackage = componentName.getPackageName();
8129 if (!callingPackage.equals(vvmPackage)) {
8130 throw new SecurityException("Caller not current active visual voicemail package["
8131 + vvmPackage + "]");
8132 }
8133 } finally {
8134 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008135 }
8136 }
8137
8138 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008139 * Return the application ID for the app type.
8140 *
8141 * @param subId the subscription ID that this request applies to.
8142 * @param appType the uicc app type.
8143 * @return Application ID for specificied app type, or null if no uicc.
8144 */
8145 @Override
8146 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008147 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008148 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008149
8150 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008151 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152 if (phone == null) {
8153 return null;
8154 }
8155 String aid = null;
8156 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008157 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158 .getApplicationByType(appType).getAid();
8159 } catch (Exception e) {
8160 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8161 }
8162 return aid;
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008165 }
Youhan Wange64578a2016-05-02 15:32:42 -07008166 }
8167
Youhan Wang4001d252016-05-11 10:29:41 -07008168 /**
8169 * Return the Electronic Serial Number.
8170 *
8171 * @param subId the subscription ID that this request applies to.
8172 * @return ESN or null if error.
8173 */
8174 @Override
8175 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008176 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008177 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178
8179 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008180 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181 if (phone == null) {
8182 return null;
8183 }
8184 String esn = null;
8185 try {
8186 esn = phone.getEsn();
8187 } catch (Exception e) {
8188 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8189 }
8190 return esn;
8191 } finally {
8192 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008193 }
Youhan Wang4001d252016-05-11 10:29:41 -07008194 }
8195
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008196 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008197 * Return the Preferred Roaming List Version.
8198 *
8199 * @param subId the subscription ID that this request applies to.
8200 * @return PRLVersion or null if error.
8201 */
8202 @Override
8203 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008204 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008205 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008206
8207 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008208 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 if (phone == null) {
8210 return null;
8211 }
8212 String cdmaPrlVersion = null;
8213 try {
8214 cdmaPrlVersion = phone.getCdmaPrlVersion();
8215 } catch (Exception e) {
8216 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8217 }
8218 return cdmaPrlVersion;
8219 } finally {
8220 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008221 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008222 }
8223
8224 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008225 * Get snapshot of Telephony histograms
8226 * @return List of Telephony histograms
8227 * @hide
8228 */
8229 @Override
8230 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8232 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233
8234 final long identity = Binder.clearCallingIdentity();
8235 try {
8236 return RIL.getTelephonyRILTimingHistograms();
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008240 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008241
8242 /**
8243 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008244 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8245 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008246 * Require system privileges. In the future we may add this to carrier APIs.
8247 *
Michele Berionne482f8202018-11-27 18:57:59 -08008248 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008249 */
8250 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008251 @TelephonyManager.SetCarrierRestrictionResult
8252 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008253 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008254 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008255
Michele Berionne482f8202018-11-27 18:57:59 -08008256 if (carrierRestrictionRules == null) {
8257 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008258 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260 final long identity = Binder.clearCallingIdentity();
8261 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008262 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008263 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264 } finally {
8265 Binder.restoreCallingIdentity(identity);
8266 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008267 }
8268
8269 /**
8270 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008271 * Get the allowed carrier list and the excluded carrier list, including the priority between
8272 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008273 * Require system privileges. In the future we may add this to carrier APIs.
8274 *
Michele Berionne482f8202018-11-27 18:57:59 -08008275 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008276 */
8277 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008278 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008279 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008280 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281
8282 final long identity = Binder.clearCallingIdentity();
8283 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008284 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8285 if (response instanceof CarrierRestrictionRules) {
8286 return (CarrierRestrictionRules) response;
8287 }
8288 // Response is an Exception of some kind,
8289 // which is signalled to the user as a NULL retval
8290 return null;
8291 } catch (Exception e) {
8292 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8293 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 } finally {
8295 Binder.restoreCallingIdentity(identity);
8296 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008297 }
8298
fionaxu59545b42016-05-25 15:53:37 -07008299 /**
fionaxu59545b42016-05-25 15:53:37 -07008300 * Action set from carrier signalling broadcast receivers to enable/disable radio
8301 * @param subId the subscription ID that this action applies to.
8302 * @param enabled control enable or disable radio.
8303 * {@hide}
8304 */
8305 @Override
8306 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8307 enforceModifyPermission();
8308 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309
8310 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008311 if (phone == null) {
8312 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8313 return;
8314 }
8315 try {
8316 phone.carrierActionSetRadioEnabled(enabled);
8317 } catch (Exception e) {
8318 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319 } finally {
8320 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008321 }
8322 }
8323
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008324 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008325 * Enable or disable Voice over NR (VoNR)
8326 * @param subId the subscription ID that this action applies to.
8327 * @param enabled enable or disable VoNR.
8328 * @return operation result.
8329 */
8330 @Override
8331 public int setVoNrEnabled(int subId, boolean enabled) {
8332 enforceModifyPermission();
8333 final Phone phone = getPhone(subId);
8334
8335 final long identity = Binder.clearCallingIdentity();
8336 if (phone == null) {
8337 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8338 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8339 }
8340
8341 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8342 try {
8343 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8344 workSource);
8345 if (DBG) log("setVoNrEnabled result: " + result);
8346 return result;
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
8349 }
8350 }
8351
8352 /**
8353 * Is voice over NR enabled
8354 * @return true if VoNR is enabled else false
8355 */
8356 @Override
8357 public boolean isVoNrEnabled(int subId) {
8358 enforceReadPrivilegedPermission("isVoNrEnabled");
8359 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8360 final long identity = Binder.clearCallingIdentity();
8361 try {
8362 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8363 null, subId, workSource);
8364 if (DBG) log("isVoNrEnabled: " + isEnabled);
8365 return isEnabled;
8366 } finally {
8367 Binder.restoreCallingIdentity(identity);
8368 }
8369 }
8370
8371 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008372 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8373 * network status based on which carrier apps could apply actions accordingly,
8374 * enable/disable default url handler for example.
8375 *
8376 * @param subId the subscription ID that this action applies to.
8377 * @param report control start/stop reporting the default network status.
8378 * {@hide}
8379 */
8380 @Override
8381 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8382 enforceModifyPermission();
8383 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008384
8385 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008386 if (phone == null) {
8387 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8388 return;
8389 }
8390 try {
8391 phone.carrierActionReportDefaultNetworkStatus(report);
8392 } catch (Exception e) {
8393 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394 } finally {
8395 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008396 }
8397 }
8398
8399 /**
fionaxud9622282017-07-17 17:51:30 -07008400 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8401 * @param subId the subscription ID that this action applies to.
8402 * {@hide}
8403 */
8404 @Override
8405 public void carrierActionResetAll(int subId) {
8406 enforceModifyPermission();
8407 final Phone phone = getPhone(subId);
8408 if (phone == null) {
8409 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8410 return;
8411 }
8412 try {
8413 phone.carrierActionResetAll();
8414 } catch (Exception e) {
8415 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8416 }
8417 }
8418
8419 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008420 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8421 * bug report is being generated.
8422 */
8423 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008424 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008425 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8426 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008427 writer.println("Permission Denial: can't dump Phone from pid="
8428 + Binder.getCallingPid()
8429 + ", uid=" + Binder.getCallingUid()
8430 + "without permission "
8431 + android.Manifest.permission.DUMP);
8432 return;
8433 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008434 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008435 }
Jack Yueb89b242016-06-22 13:27:47 -07008436
Brad Ebingerdac2f002018-04-03 15:17:52 -07008437 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008438 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8439 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8440 @NonNull String[] args) {
8441 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8442 this, in.getFileDescriptor(), out.getFileDescriptor(),
8443 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008444 }
8445
Jack Yueb89b242016-06-22 13:27:47 -07008446 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008447 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008448 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008449 * @param reason the reason the data enable change is taking place
8450 * @param enabled True if enabling the data, otherwise disabling.
8451 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008452 */
8453 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008454 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008455 boolean enabled) {
8456 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8457 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8458 try {
8459 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008460 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008461 } catch (SecurityException se) {
8462 enforceModifyPermission();
8463 }
8464 } else {
8465 enforceModifyPermission();
8466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467
8468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 Phone phone = getPhone(subId);
8471 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008472 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8473 phone.carrierActionSetMeteredApnsEnabled(enabled);
8474 } else {
8475 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008477 }
8478 } finally {
8479 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008480 }
8481 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008482
8483 /**
8484 * Get Client request stats
8485 * @return List of Client Request Stats
8486 * @hide
8487 */
8488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008489 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8490 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008492 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008493 return null;
8494 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008495 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008497 final long identity = Binder.clearCallingIdentity();
8498 try {
8499 if (phone != null) {
8500 return phone.getClientRequestStats();
8501 }
8502
8503 return null;
8504 } finally {
8505 Binder.restoreCallingIdentity(identity);
8506 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008507 }
8508
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008509 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008510 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008511 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008512 }
Jack Yueb4124c2017-02-16 15:32:43 -08008513
8514 /**
Grace Chen70990072017-03-24 17:21:30 -07008515 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008516 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008517 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008518 * @param state State of SIM (power down, power up, pass through)
8519 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8520 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8521 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008522 *
8523 **/
8524 @Override
Grace Chen70990072017-03-24 17:21:30 -07008525 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008526 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008527 Phone phone = PhoneFactory.getPhone(slotIndex);
8528
vagdeviaf9a5b92018-08-15 16:01:53 -07008529 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008531 final long identity = Binder.clearCallingIdentity();
8532 try {
8533 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008534 phone.setSimPowerState(state, null, workSource);
8535 }
8536 } finally {
8537 Binder.restoreCallingIdentity(identity);
8538 }
8539 }
8540
8541 /**
8542 * Set SIM card power state.
8543 *
8544 * @param slotIndex SIM slot id.
8545 * @param state State of SIM (power down, power up, pass through)
8546 * @param callback callback to trigger after success or failure
8547 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8548 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8549 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8550 *
8551 **/
8552 @Override
8553 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8554 IIntegerConsumer callback) {
8555 enforceModifyPermission();
8556 Phone phone = PhoneFactory.getPhone(slotIndex);
8557
8558 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8559
8560 final long identity = Binder.clearCallingIdentity();
8561 try {
8562 if (phone != null) {
8563 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8564 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008565 }
8566 } finally {
8567 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008568 }
8569 }
Shuo Qiandd210312017-04-12 22:11:33 +00008570
Tyler Gunn65d45c22017-06-05 11:22:26 -07008571 private boolean isUssdApiAllowed(int subId) {
8572 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008573 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008574 if (configManager == null) {
8575 return false;
8576 }
8577 PersistableBundle pb = configManager.getConfigForSubId(subId);
8578 if (pb == null) {
8579 return false;
8580 }
8581 return pb.getBoolean(
8582 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8583 }
8584
Shuo Qiandd210312017-04-12 22:11:33 +00008585 /**
8586 * Check if phone is in emergency callback mode
8587 * @return true if phone is in emergency callback mode
8588 * @param subId sub id
8589 */
goneil9c5f4872017-12-05 14:07:56 -08008590 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008591 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008592 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008593 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594
8595 final long identity = Binder.clearCallingIdentity();
8596 try {
8597 if (phone != null) {
8598 return phone.isInEcm();
8599 } else {
8600 return false;
8601 }
8602 } finally {
8603 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008604 }
8605 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008606
8607 /**
8608 * Get the current signal strength information for the given subscription.
8609 * Because this information is not updated when the device is in a low power state
8610 * it should not be relied-upon to be current.
8611 * @param subId Subscription index
8612 * @return the most recent cached signal strength info from the modem
8613 */
8614 @Override
8615 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008616 final long identity = Binder.clearCallingIdentity();
8617 try {
8618 Phone p = getPhone(subId);
8619 if (p == null) {
8620 return null;
8621 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008623 return p.getSignalStrength();
8624 } finally {
8625 Binder.restoreCallingIdentity(identity);
8626 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008627 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008628
Pengquan Meng77b7f132018-08-22 14:49:57 -07008629 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008630 * Get the current modem radio state for the given slot.
8631 * @param slotIndex slot index.
8632 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008633 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008634 * @return the current radio power state from the modem
8635 */
8636 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008637 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008638 Phone phone = PhoneFactory.getPhone(slotIndex);
8639 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8641 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008642 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8643 }
8644
8645 final long identity = Binder.clearCallingIdentity();
8646 try {
8647 return phone.getRadioPowerState();
8648 } finally {
8649 Binder.restoreCallingIdentity(identity);
8650 }
8651 }
8652 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8653 }
8654
8655 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008656 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8657 *
8658 * <p>Requires one of the following permissions:
8659 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008660 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008661 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8662 * privileges.
8663 *
8664 * @param subId subscription id
8665 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8666 * {@code false}.
8667 */
8668 @Override
8669 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008670 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008671 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008672 try {
8673 mApp.enforceCallingOrSelfPermission(
8674 android.Manifest.permission.ACCESS_NETWORK_STATE,
8675 functionName);
8676 } catch (Exception e) {
8677 mApp.enforceCallingOrSelfPermission(
8678 permission.READ_BASIC_PHONE_STATE, functionName);
8679 }
Shuo Qian093013d2020-08-13 15:42:55 -07008680 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008681 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008682 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008683 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008684
Pengquan Menga1bb6272018-09-06 09:59:22 -07008685 boolean isEnabled = false;
8686 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008687 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008688 Phone phone = getPhone(subId);
8689 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008690 } finally {
8691 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008692 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008693 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008694 }
8695
8696
8697 /**
8698 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8699 *
8700 * <p> Requires permission:
8701 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8702 * privileges.
8703 *
8704 * @param subId subscription id
8705 * @param isEnabled {@code true} means enable, {@code false} means disable.
8706 */
8707 @Override
8708 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8710 mApp, subId, "setDataRoamingEnabled");
8711
Pengquan Menga1bb6272018-09-06 09:59:22 -07008712 final long identity = Binder.clearCallingIdentity();
8713 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008714 Phone phone = getPhone(subId);
8715 if (phone != null) {
8716 phone.setDataRoamingEnabled(isEnabled);
8717 }
8718 } finally {
8719 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008720 }
8721 }
8722
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008723 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008724 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008725 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008726 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008727 mApp, subId, "isManualNetworkSelectionAllowed");
8728
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008729 boolean isAllowed = true;
8730 final long identity = Binder.clearCallingIdentity();
8731 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008732 Phone phone = getPhone(subId);
8733 if (phone != null) {
8734 isAllowed = phone.isCspPlmnEnabled();
8735 }
8736 } finally {
8737 Binder.restoreCallingIdentity(identity);
8738 }
8739 return isAllowed;
8740 }
8741
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008742 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8743 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8744 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8745 // Update each UiccPort object based on privilege access
8746 UiccPort[] uiccPorts = card.getUiccPortList();
8747 for (UiccPort port : uiccPorts) {
8748 UiccProfile profile = port.getUiccProfile();
8749 if (profile == null ||
8750 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8751 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8752 return false;
8753 }
8754 }
8755 return true;
8756 }
8757
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008758 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008759 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008760 // Verify that tha callingPackage belongs to the calling UID
8761 mApp.getSystemService(AppOpsManager.class)
8762 .checkPackage(Binder.getCallingUid(), callingPackage);
8763
Jordan Liu1e142fc2019-04-22 15:10:43 -07008764 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008765 try {
8766 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008767 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008768 } catch (SecurityException e) {
8769 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8770 // has carrier privileges on an active UICC
8771 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8772 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008773 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008774 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008775 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008776
8777 final long identity = Binder.clearCallingIdentity();
8778 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008779 UiccController uiccController = UiccController.getInstance();
8780 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008781 if (hasReadPermission) {
8782 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008783 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008784
8785 // Remove private info if the caller doesn't have access
8786 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8787 for (UiccCardInfo cardInfo : cardInfos) {
8788 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8789 // is available
8790 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008791 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8792 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8793 if (card == null || card.getUiccPortList().length == 0) {
8794 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008795 filteredInfos.add(cardInfo.getUnprivileged());
8796 continue;
8797 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008798
8799 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008800 filteredInfos.add(cardInfo);
8801 } else {
8802 filteredInfos.add(cardInfo.getUnprivileged());
8803 }
8804 }
8805 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008806 } finally {
8807 Binder.restoreCallingIdentity(identity);
8808 }
8809 }
8810
8811 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008812 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008813 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008815 final long identity = Binder.clearCallingIdentity();
8816 try {
8817 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8818 if (slots == null) {
8819 Rlog.i(LOG_TAG, "slots is null.");
8820 return null;
8821 }
8822
8823 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8824 for (int i = 0; i < slots.length; i++) {
8825 UiccSlot slot = slots[i];
8826 if (slot == null) {
8827 continue;
8828 }
8829
Jordan Liu7be7e652019-05-06 18:55:02 +00008830 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008831 UiccCard card = slot.getUiccCard();
8832 if (card != null) {
8833 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008834 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008835 cardId = slot.getEid();
8836 if (TextUtils.isEmpty(cardId)) {
8837 cardId = slot.getIccId();
8838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008839 }
8840
Jordan Liu857451f2019-05-09 16:35:35 -07008841 if (cardId != null) {
8842 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8843 // if cardId is an EID, it's all digits so this is fine
8844 cardId = IccUtils.stripTrailingFs(cardId);
8845 }
8846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008847 int cardState = 0;
8848 switch (slot.getCardState()) {
8849 case CARDSTATE_ABSENT:
8850 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8851 break;
8852 case CARDSTATE_PRESENT:
8853 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8854 break;
8855 case CARDSTATE_ERROR:
8856 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8857 break;
8858 case CARDSTATE_RESTRICTED:
8859 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8860 break;
8861 default:
8862 break;
8863
8864 }
8865
8866 infos[i] = new UiccSlotInfo(
8867 slot.isActive(),
8868 slot.isEuicc(),
8869 cardId,
8870 cardState,
8871 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008872 slot.isExtendedApduSupported(),
8873 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008874 }
8875 return infos;
8876 } finally {
8877 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008878 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008879 }
8880
8881 @Override
8882 public boolean switchSlots(int[] physicalSlots) {
8883 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008884
8885 final long identity = Binder.clearCallingIdentity();
8886 try {
8887 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008891 }
Jack Yu4c988042018-02-27 15:30:01 -08008892
8893 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008894 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008895 final long identity = Binder.clearCallingIdentity();
8896 try {
8897 return UiccController.getInstance().getCardIdForDefaultEuicc();
8898 } finally {
8899 Binder.restoreCallingIdentity(identity);
8900 }
8901 }
8902
Pengquan Meng85728fb2018-03-12 16:31:21 -07008903 /**
goneil47ffb6e2018-04-06 15:40:58 -07008904 * A test API to reload the UICC profile.
8905 *
8906 * <p>Requires that the calling app has permission
8907 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8908 * @hide
8909 */
8910 @Override
8911 public void refreshUiccProfile(int subId) {
8912 enforceModifyPermission();
8913
8914 final long identity = Binder.clearCallingIdentity();
8915 try {
8916 Phone phone = getPhone(subId);
8917 if (phone == null) {
8918 return;
8919 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008920 UiccPort uiccPort = phone.getUiccPort();
8921 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008922 return;
8923 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008924 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008925 if (uiccProfile == null) {
8926 return;
8927 }
8928 uiccProfile.refresh();
8929 } finally {
8930 Binder.restoreCallingIdentity(identity);
8931 }
8932 }
8933
8934 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008935 * Returns false if the mobile data is disabled by default, otherwise return true.
8936 */
8937 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008938 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008939 }
8940
8941 /**
8942 * Returns true if the data roaming is enabled by default, i.e the system property
8943 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8944 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8945 */
8946 private boolean getDefaultDataRoamingEnabled(int subId) {
8947 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008948 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008949 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008950 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8951 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8952 return isDataRoamingEnabled;
8953 }
8954
8955 /**
8956 * Returns the default network type for the given {@code subId}, if the default network type is
8957 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8958 */
8959 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008960 List<Integer> list = TelephonyProperties.default_network();
8961 int phoneId = mSubscriptionController.getPhoneId(subId);
8962 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8963 return list.get(phoneId);
8964 }
8965 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008966 }
fionaxua13278b2018-03-21 00:08:13 -07008967
8968 @Override
8969 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008970 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008971 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008972
8973 final long identity = Binder.clearCallingIdentity();
8974 try {
8975 final Phone phone = getPhone(subId);
8976 if (phone == null) {
8977 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8978 return;
8979 }
chen xueaba88a2019-03-15 13:15:10 -07008980 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8981 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008982 if (carrierPrivilegeRules == null) {
8983 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8984 } else {
8985 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987 } finally {
8988 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008989 }
fionaxua13278b2018-03-21 00:08:13 -07008990 }
8991
8992 @Override
8993 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008994 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008995
8996 final long identity = Binder.clearCallingIdentity();
8997 try {
8998 final Phone phone = getPhone(subId);
8999 if (phone == null) {
9000 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9001 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9002 }
9003 return phone.getCarrierIdListVersion();
9004 } finally {
9005 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009006 }
fionaxua13278b2018-03-21 00:08:13 -07009007 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009008
9009 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009010 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9011 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009013 mApp, subId, callingPackage, callingFeatureId,
9014 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009015 return -1;
9016 }
9017
9018 final long identity = Binder.clearCallingIdentity();
9019 try {
9020 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009025
9026 @Override
9027 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009028 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009029 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009030 mApp, subId, "getCdmaRoamingMode");
9031
9032 final long identity = Binder.clearCallingIdentity();
9033 try {
9034 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9035 } finally {
9036 Binder.restoreCallingIdentity(identity);
9037 }
9038 }
9039
9040 @Override
9041 public boolean setCdmaRoamingMode(int subId, int mode) {
9042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9043 mApp, subId, "setCdmaRoamingMode");
9044
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
9051 }
9052
9053 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009054 public int getCdmaSubscriptionMode(int subId) {
9055 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009056 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009057 mApp, subId, "getCdmaSubscriptionMode");
9058
9059 final long identity = Binder.clearCallingIdentity();
9060 try {
9061 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9062 } finally {
9063 Binder.restoreCallingIdentity(identity);
9064 }
9065 }
9066
9067 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009068 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9070 mApp, subId, "setCdmaSubscriptionMode");
9071
9072 final long identity = Binder.clearCallingIdentity();
9073 try {
9074 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9075 } finally {
9076 Binder.restoreCallingIdentity(identity);
9077 }
9078 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009079
sqianc5eccab2018-10-19 18:46:41 -07009080 @Override
sqian8c685422019-02-22 15:55:18 -08009081 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009082 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009084 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9085 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009086 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9087 }
9088 final long identity = Binder.clearCallingIdentity();
9089 try {
sqian854d44b2018-12-12 16:48:18 -08009090 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9091 for (Phone phone: PhoneFactory.getPhones()) {
9092 if (phone.getEmergencyNumberTracker() != null
9093 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9094 emergencyNumberListInternal.put(
9095 phone.getSubId(),
9096 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9097 }
sqian11b7a0e2018-12-05 18:48:28 -08009098 }
sqian854d44b2018-12-12 16:48:18 -08009099 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009100 } finally {
9101 Binder.restoreCallingIdentity(identity);
9102 }
sqianc5eccab2018-10-19 18:46:41 -07009103 }
9104
9105 @Override
sqian8c685422019-02-22 15:55:18 -08009106 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009107 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009108 if (!exactMatch) {
9109 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009110 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009111 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009112 }
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
sqian854d44b2018-12-12 16:48:18 -08009115 for (Phone phone: PhoneFactory.getPhones()) {
9116 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009117 && phone.getEmergencyNumberTracker()
9118 .isEmergencyNumber(number, exactMatch)) {
9119 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009120 }
sqian11b7a0e2018-12-05 18:48:28 -08009121 }
9122 return false;
9123 } finally {
9124 Binder.restoreCallingIdentity(identity);
9125 }
9126 }
9127
sqianf4ca7ed2019-01-15 18:32:07 -08009128 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009129 * Start emergency callback mode for GsmCdmaPhone for testing.
9130 */
9131 @Override
9132 public void startEmergencyCallbackMode() {
9133 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9134 "startEmergencyCallbackMode");
9135 enforceModifyPermission();
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
9138 for (Phone phone : PhoneFactory.getPhones()) {
9139 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9140 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9141 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9142 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9143 gsmCdmaPhone.obtainMessage(
9144 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9145 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9146 }
9147 }
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
9152
9153 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009154 * Update emergency number list for test mode.
9155 */
9156 @Override
9157 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9158 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9159 "updateEmergencyNumberListTestMode");
9160
9161 final long identity = Binder.clearCallingIdentity();
9162 try {
9163 for (Phone phone: PhoneFactory.getPhones()) {
9164 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9165 if (tracker != null) {
9166 tracker.executeEmergencyNumberTestModeCommand(action, num);
9167 }
9168 }
9169 } finally {
9170 Binder.restoreCallingIdentity(identity);
9171 }
9172 }
9173
9174 /**
9175 * Get the full emergency number list for test mode.
9176 */
9177 @Override
9178 public List<String> getEmergencyNumberListTestMode() {
9179 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9180 "getEmergencyNumberListTestMode");
9181
9182 final long identity = Binder.clearCallingIdentity();
9183 try {
9184 Set<String> emergencyNumbers = new HashSet<>();
9185 for (Phone phone: PhoneFactory.getPhones()) {
9186 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9187 if (tracker != null) {
9188 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9189 emergencyNumbers.add(num.getNumber());
9190 }
9191 }
9192 }
9193 return new ArrayList<>(emergencyNumbers);
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
9196 }
9197 }
9198
chen xud6b45bd2018-10-30 22:27:10 -07009199 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009200 public int getEmergencyNumberDbVersion(int subId) {
9201 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9202
9203 final long identity = Binder.clearCallingIdentity();
9204 try {
9205 final Phone phone = getPhone(subId);
9206 if (phone == null) {
9207 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9208 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9209 }
9210 return phone.getEmergencyNumberDbVersion();
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 }
9215
9216 @Override
9217 public void notifyOtaEmergencyNumberDbInstalled() {
9218 enforceModifyPermission();
9219
9220 final long identity = Binder.clearCallingIdentity();
9221 try {
9222 for (Phone phone: PhoneFactory.getPhones()) {
9223 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9224 if (tracker != null) {
9225 tracker.updateOtaEmergencyNumberDatabase();
9226 }
9227 }
9228 } finally {
9229 Binder.restoreCallingIdentity(identity);
9230 }
9231 }
9232
9233 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009234 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009235 enforceActiveEmergencySessionPermission();
9236
9237 final long identity = Binder.clearCallingIdentity();
9238 try {
9239 for (Phone phone: PhoneFactory.getPhones()) {
9240 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9241 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009242 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9243 }
9244 }
9245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
9248 }
9249
9250 @Override
9251 public void resetOtaEmergencyNumberDbFilePath() {
9252 enforceActiveEmergencySessionPermission();
9253
9254 final long identity = Binder.clearCallingIdentity();
9255 try {
9256 for (Phone phone: PhoneFactory.getPhones()) {
9257 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9258 if (tracker != null) {
9259 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009260 }
9261 }
9262 } finally {
9263 Binder.restoreCallingIdentity(identity);
9264 }
9265 }
9266
9267 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009268 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9269 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9270 Phone phone = getPhone(subId);
9271 if (phone == null) {
9272 return null;
9273 }
9274 final long identity = Binder.clearCallingIdentity();
9275 try {
9276 UiccProfile profile = UiccController.getInstance()
9277 .getUiccProfileForPhone(phone.getPhoneId());
9278 if (profile != null) {
9279 return profile.getCertsFromCarrierPrivilegeAccessRules();
9280 }
9281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
9284 return null;
9285 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009286
9287 /**
9288 * Enable or disable a modem stack.
9289 */
9290 @Override
9291 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9292 enforceModifyPermission();
9293
9294 final long identity = Binder.clearCallingIdentity();
9295 try {
9296 Phone phone = PhoneFactory.getPhone(slotIndex);
9297 if (phone == null) {
9298 return false;
9299 } else {
9300 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9301 }
9302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
Michelecea4cf22018-12-21 15:00:11 -08009306
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009307 /**
9308 * Whether a modem stack is enabled or not.
9309 */
9310 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009311 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9312 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009313 Phone phone = PhoneFactory.getPhone(slotIndex);
9314 if (phone == null) return false;
9315
9316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009317 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9318 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009319 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9320 }
9321
9322 final long identity = Binder.clearCallingIdentity();
9323 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009324 try {
9325 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9326 } catch (NoSuchElementException ex) {
9327 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9328 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009329 } finally {
9330 Binder.restoreCallingIdentity(identity);
9331 }
9332 }
9333
Michelecea4cf22018-12-21 15:00:11 -08009334 @Override
Michele0ea7d782019-03-19 14:58:42 -07009335 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009336 enforceModifyPermission();
9337
9338 final long identity = Binder.clearCallingIdentity();
9339 try {
9340 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009341 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009342 .commit();
9343 } finally {
9344 Binder.restoreCallingIdentity(identity);
9345 }
9346 }
9347
9348 @Override
Michele0ea7d782019-03-19 14:58:42 -07009349 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009350 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009352 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9353 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009354 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009355 }
Michelecea4cf22018-12-21 15:00:11 -08009356
9357 final long identity = Binder.clearCallingIdentity();
9358 try {
Michele0ea7d782019-03-19 14:58:42 -07009359 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009360 } finally {
9361 Binder.restoreCallingIdentity(identity);
9362 }
9363 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009364
Michele0ea7d782019-03-19 14:58:42 -07009365 @TelephonyManager.IsMultiSimSupportedResult
9366 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009367 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9368 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9369 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009370 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9371 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009372 }
9373 // Check if the hardware supports multisim functionality. If usage of multisim is not
9374 // supported by the modem, indicate that it is restricted.
9375 PhoneCapability staticCapability =
9376 mPhoneConfigurationManager.getStaticPhoneCapability();
9377 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009378 loge("isMultiSimSupportedInternal: no static configuration available");
9379 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009380 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009381 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009382 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9383 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009384 }
9385 // Check if support of multiple SIMs is restricted by carrier
9386 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009387 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009388 }
9389
Michele0ea7d782019-03-19 14:58:42 -07009390 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009391 }
9392
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009393 /**
9394 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009395 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9396 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9397 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009398 * @param numOfSims number of active sims we want to switch to
9399 */
9400 @Override
9401 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009402 if (numOfSims == 1) {
9403 enforceModifyPermission();
9404 } else {
9405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9406 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9407 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009408 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009409
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009410 try {
Michele30b57b22019-03-01 12:01:14 -08009411 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009412 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009413 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9414 return;
9415 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009416 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
9420 }
9421
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009422 @Override
9423 public boolean isApplicationOnUicc(int subId, int appType) {
9424 enforceReadPrivilegedPermission("isApplicationOnUicc");
9425 Phone phone = getPhone(subId);
9426 if (phone == null) {
9427 return false;
9428 }
9429 final long identity = Binder.clearCallingIdentity();
9430 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009431 UiccPort uiccPort = phone.getUiccPort();
9432 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009433 return false;
9434 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009435 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009436 if (uiccProfile == null) {
9437 return false;
9438 }
9439 if (TelephonyManager.APPTYPE_SIM <= appType
9440 && appType <= TelephonyManager.APPTYPE_ISIM) {
9441 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9442 }
9443 return false;
9444 } finally {
9445 Binder.restoreCallingIdentity(identity);
9446 }
9447 }
9448
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009449 /**
chen xub4baa772019-04-03 10:23:41 -07009450 * Get whether making changes to modem configurations will trigger reboot.
9451 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009452 */
9453 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009454 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9455 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009457 mApp, subId, callingPackage, callingFeatureId,
9458 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009459 return false;
9460 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009461 final long identity = Binder.clearCallingIdentity();
9462 try {
9463 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
9468
Nathan Harold29f5f052019-02-15 13:41:57 -08009469 private void updateModemStateMetrics() {
9470 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9471 // TODO: check the state for each modem if the api is ready.
9472 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9473 }
9474
Pengquan Meng3889a572019-01-23 11:16:29 -08009475 @Override
9476 public int[] getSlotsMapping() {
9477 enforceReadPrivilegedPermission("getSlotsMapping");
9478
9479 final long identity = Binder.clearCallingIdentity();
9480 try {
9481 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9482 // All logical slots should have a mapping to a physical slot.
9483 int[] logicalSlotsMapping = new int[phoneCount];
9484 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9485 for (int i = 0; i < slotInfos.length; i++) {
9486 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9487 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9488 }
9489 }
9490 return logicalSlotsMapping;
9491 } finally {
9492 Binder.restoreCallingIdentity(identity);
9493 }
9494 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009495
9496 /**
9497 * Get the IRadio HAL Version
9498 */
9499 @Override
9500 public int getRadioHalVersion() {
9501 Phone phone = getDefaultPhone();
9502 if (phone == null) return -1;
9503 HalVersion hv = phone.getHalVersion();
9504 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9505 return hv.major * 100 + hv.minor;
9506 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009507
9508 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009509 * Get the current calling package name.
9510 * @return the current calling package name
9511 */
9512 @Override
9513 public String getCurrentPackageName() {
9514 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9515 }
9516
9517 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009518 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9519 * corresponding network requests on a subId.
9520 *
9521 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009522 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009523 * 2) APN is un-metered for this subscription, or
9524 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009525 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009526 *
9527 * @return whether data is allowed for a apn type.
9528 *
9529 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009530 */
9531 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009532 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009533 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9534 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009535
9536 // Now that all security checks passes, perform the operation as ourselves.
9537 final long identity = Binder.clearCallingIdentity();
9538 try {
9539 Phone phone = getPhone(subId);
9540 if (phone == null) return false;
9541
Jack Yu41407ee2019-05-13 16:54:09 -07009542 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009543 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9544 } finally {
9545 Binder.restoreCallingIdentity(identity);
9546 }
9547 }
9548
9549 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009550 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009551 enforceReadPrivilegedPermission("isApnMetered");
9552
9553 // Now that all security checks passes, perform the operation as ourselves.
9554 final long identity = Binder.clearCallingIdentity();
9555 try {
9556 Phone phone = getPhone(subId);
9557 if (phone == null) return true; // By default return true.
9558
Jack Yu41407ee2019-05-13 16:54:09 -07009559 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009560 } finally {
9561 Binder.restoreCallingIdentity(identity);
9562 }
9563 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009564
9565 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009566 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9567 int subscriptionId, IBooleanConsumer resultCallback) {
9568 enforceModifyPermission();
9569 long token = Binder.clearCallingIdentity();
9570 try {
9571 Phone phone = getPhone(subscriptionId);
9572 if (phone == null) {
9573 try {
9574 if (resultCallback != null) {
9575 resultCallback.accept(false);
9576 }
9577 } catch (RemoteException e) {
9578 // ignore
9579 }
9580 return;
9581 }
9582 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9583 Pair.create(specifiers, (x) -> {
9584 try {
9585 if (resultCallback != null) {
9586 resultCallback.accept(x);
9587 }
9588 } catch (RemoteException e) {
9589 // ignore
9590 }
9591 });
9592 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9593 } finally {
9594 Binder.restoreCallingIdentity(token);
9595 }
9596 }
9597
9598 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009599 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9600 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009601 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009602 mApp, subId, "getSystemSelectionChannels");
9603 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9604 final long identity = Binder.clearCallingIdentity();
9605 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009606 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9607 if (result instanceof IllegalStateException) {
9608 throw (IllegalStateException) result;
9609 }
9610 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009611 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9612 return specifiers;
9613 } finally {
9614 Binder.restoreCallingIdentity(identity);
9615 }
9616 }
9617
9618 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009619 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009620 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009621 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9622 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9623 if (iccRecords == null) {
9624 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9625 return false;
9626 }
9627 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9628 }
9629
9630 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009631 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9632 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009633 if (callingPackage == null) {
9634 callingPackage = getCurrentPackageName();
9635 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009636 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9637 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009638 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9639 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009640 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9641 }
9642 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9643 Intent intent = new Intent();
9644 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9645 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9646 // Bring up choose default SMS subscription dialog right now
9647 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9648 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9649 mApp.startActivity(intent);
9650 }
chen xud5ca2d52019-05-28 15:20:57 -07009651
9652 @Override
9653 public String getMmsUAProfUrl(int subId) {
9654 //TODO investigate if this API should require proper permission check in R b/133791609
9655 final long identity = Binder.clearCallingIdentity();
9656 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009657 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9658 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9659 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9660 return carrierUAProfUrl;
9661 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009662 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9663 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009664 } finally {
9665 Binder.restoreCallingIdentity(identity);
9666 }
9667 }
9668
9669 @Override
9670 public String getMmsUserAgent(int subId) {
9671 //TODO investigate if this API should require proper permission check in R b/133791609
9672 final long identity = Binder.clearCallingIdentity();
9673 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009674 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9675 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9676 if (!TextUtils.isEmpty(carrierUserAgent)) {
9677 return carrierUserAgent;
9678 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009679 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9680 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009681 } finally {
9682 Binder.restoreCallingIdentity(identity);
9683 }
9684 }
Jack Yub07d4972019-05-28 16:12:25 -07009685
9686 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009687 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9688 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009689
Jack Yub07d4972019-05-28 16:12:25 -07009690 final long identity = Binder.clearCallingIdentity();
9691 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009692 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009693 if (phone == null) return false;
9694
Hall Liua62f5da2020-09-25 10:42:19 -07009695 switch (policy) {
9696 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9697 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9698 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9699 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9700 default:
9701 throw new IllegalArgumentException(policy + " is not a valid policy");
9702 }
Jack Yub07d4972019-05-28 16:12:25 -07009703 } finally {
9704 Binder.restoreCallingIdentity(identity);
9705 }
9706 }
9707
9708 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009709 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009710 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009711 enforceModifyPermission();
9712
changbettyd5c246e2019-12-24 15:40:37 +08009713 final long identity = Binder.clearCallingIdentity();
9714 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009715 Phone phone = getPhone(subscriptionId);
9716 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009717
Hall Liua62f5da2020-09-25 10:42:19 -07009718 switch (policy) {
9719 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9720 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9721 break;
9722 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9723 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9724 break;
9725 default:
9726 throw new IllegalArgumentException(policy + " is not a valid policy");
9727 }
changbettyd5c246e2019-12-24 15:40:37 +08009728 } finally {
9729 Binder.restoreCallingIdentity(identity);
9730 }
9731 }
9732
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009733 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009734 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009735 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9736 * otherwise.
9737 */
9738 @Override
9739 public void setCepEnabled(boolean isCepEnabled) {
9740 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9741
9742 final long identity = Binder.clearCallingIdentity();
9743 try {
9744 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9745 for (Phone phone : PhoneFactory.getPhones()) {
9746 Phone defaultPhone = phone.getImsPhone();
9747 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9748 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9749 ImsPhoneCallTracker imsPhoneCallTracker =
9750 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9751 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9752 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9753 + imsPhone.getMsisdn());
9754 }
9755 }
9756 } finally {
9757 Binder.restoreCallingIdentity(identity);
9758 }
9759 }
allenwtsu46dcc572020-01-08 18:24:03 +08009760
9761 /**
9762 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9763 *
9764 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9765 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9766 * before being read.
9767 */
9768 @Override
9769 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9770 isCompressed) {
9771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9772 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9774 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9775 }
9776 if (!isImsAvailableOnDevice()) {
9777 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9778 "IMS not available on device.");
9779 }
9780
9781 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009782 try {
Hui Wang761a6682020-10-31 05:12:53 +00009783 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9784 } finally {
9785 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009786 }
9787 }
zoey chene02881a2019-12-30 16:11:23 +08009788
9789 @Override
9790 public boolean isIccLockEnabled(int subId) {
9791 enforceReadPrivilegedPermission("isIccLockEnabled");
9792
9793 // Now that all security checks passes, perform the operation as ourselves.
9794 final long identity = Binder.clearCallingIdentity();
9795 try {
9796 Phone phone = getPhone(subId);
9797 if (phone != null && phone.getIccCard() != null) {
9798 return phone.getIccCard().getIccLockEnabled();
9799 } else {
9800 return false;
9801 }
9802 } finally {
9803 Binder.restoreCallingIdentity(identity);
9804 }
9805 }
9806
9807 /**
9808 * Set the ICC pin lock enabled or disabled.
9809 *
9810 * @return an integer representing the status of IccLock enabled or disabled in the following
9811 * three cases:
9812 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9813 * successfully.
9814 * - Positive number and zero for remaining password attempts.
9815 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9816 *
9817 */
9818 @Override
9819 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9820 enforceModifyPermission();
9821
9822 Phone phone = getPhone(subId);
9823 if (phone == null) {
9824 return 0;
9825 }
9826 // Now that all security checks passes, perform the operation as ourselves.
9827 final long identity = Binder.clearCallingIdentity();
9828 try {
9829 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9830 new Pair<Boolean, String>(enabled, password), phone, null);
9831 return attemptsRemaining;
9832
9833 } catch (Exception e) {
9834 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9835 } finally {
9836 Binder.restoreCallingIdentity(identity);
9837 }
9838 return 0;
9839 }
9840
9841 /**
9842 * Change the ICC password used in ICC pin lock.
9843 *
9844 * @return an integer representing the status of IccLock changed in the following three cases:
9845 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9846 * - Positive number and zero for remaining password attempts.
9847 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9848 *
9849 */
9850 @Override
9851 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9852 enforceModifyPermission();
9853
9854 Phone phone = getPhone(subId);
9855 if (phone == null) {
9856 return 0;
9857 }
9858 // Now that all security checks passes, perform the operation as ourselves.
9859 final long identity = Binder.clearCallingIdentity();
9860 try {
9861 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9862 new Pair<String, String>(oldPassword, newPassword), phone, null);
9863 return attemptsRemaining;
9864
9865 } catch (Exception e) {
9866 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9867 } finally {
9868 Binder.restoreCallingIdentity(identity);
9869 }
9870 return 0;
9871 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009872
9873 /**
9874 * Request for receiving user activity notification
9875 */
9876 @Override
9877 public void requestUserActivityNotification() {
9878 if (!mNotifyUserActivity.get()
9879 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9880 mNotifyUserActivity.set(true);
9881 }
9882 }
9883
9884 /**
9885 * Called when userActivity is signalled in the power manager.
9886 * This is safe to call from any thread, with any window manager locks held or not.
9887 */
9888 @Override
9889 public void userActivity() {
9890 // ***************************************
9891 // * Inherited from PhoneWindowManager *
9892 // ***************************************
9893 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9894 // WITH ITS LOCKS HELD.
9895 //
9896 // This code must be VERY careful about the locks
9897 // it acquires.
9898 // In fact, the current code acquires way too many,
9899 // and probably has lurking deadlocks.
9900
9901 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9902 throw new SecurityException("Only the OS may call notifyUserActivity()");
9903 }
9904
9905 if (mNotifyUserActivity.getAndSet(false)) {
9906 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9907 USER_ACTIVITY_NOTIFICATION_DELAY);
9908 }
9909 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009910
9911 @Override
9912 public boolean canConnectTo5GInDsdsMode() {
9913 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9914 }
Jack Yud10cdd42020-09-28 20:28:01 -07009915
9916 @Override
9917 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9918 String callingFeatureId) {
9919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9920 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9921 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9922 }
9923
9924 Phone phone = getPhone(subId);
9925 if (phone == null) {
9926 throw new RuntimeException("phone is not available");
9927 }
9928 // Now that all security checks passes, perform the operation as ourselves.
9929 final long identity = Binder.clearCallingIdentity();
9930 try {
9931 return phone.getEquivalentHomePlmns();
9932 } finally {
9933 Binder.restoreCallingIdentity(identity);
9934 }
9935 }
Daniel Bright59e67312020-11-13 11:49:37 -08009936
9937 @Override
9938 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009939 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9940 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009941 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009942 if (radioInterfaceCapabilities == null) {
9943 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009944 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009945 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009946 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009947
Hui Wang641e81c2020-10-12 12:14:23 -07009948 @Override
9949 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9950 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009951 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9952 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9953 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9954 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9955 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009956 if (DBG) {
9957 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9958 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9959 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9960 }
9961
9962 if (!SubscriptionManager.isValidSubscriptionId(subId)
9963 || appType < TelephonyManager.APPTYPE_UNKNOWN
9964 || appType > TelephonyManager.APPTYPE_ISIM
9965 || nafUrl == null || securityProtocol == null || callback == null) {
9966 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9967 if (callback != null) {
9968 try {
9969 callback.onAuthenticationFailure(
9970 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9971 } catch (RemoteException exception) {
9972 log("Fail to notify onAuthenticationFailure due to " + exception);
9973 }
9974 return;
9975 }
9976 }
9977
9978 final long token = Binder.clearCallingIdentity();
9979 try {
9980 getGbaManager(subId).bootstrapAuthenticationRequest(
9981 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9982 forceBootStrapping, callback));
9983 } finally {
9984 Binder.restoreCallingIdentity(token);
9985 }
9986 }
9987
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009988 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009989 * Attempts to set the radio power state for all phones for thermal reason.
9990 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009991 * requested radio power state will actually be set. See {@link
9992 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9993 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009994 * @param enable {@code true} if trying to turn radio on.
9995 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9996 * false}.
9997 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009998 private boolean setRadioPowerForThermal(boolean enable) {
9999 boolean isPhoneAvailable = false;
10000 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10001 Phone phone = PhoneFactory.getPhone(i);
10002 if (phone != null) {
10003 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10004 isPhoneAvailable = true;
10005 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010006 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010007
10008 // return true if successfully informed the phone object about the thermal radio power
10009 // request.
10010 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010011 }
10012
10013 private int handleDataThrottlingRequest(int subId,
10014 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010015 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10016 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10017 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10018 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10019 throw new IllegalArgumentException("modem does not support data throttling");
10020 }
10021
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010022 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10023 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010024 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010025 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10026 }
10027
10028 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10029
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010030 if (isDataThrottlingSupported) {
10031 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010032 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010033 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10034 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10035 } else if (thermalMitigationResult
10036 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010037 log("Modem likely does not support data throttling on secondary carrier. Data " +
10038 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10039 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010040 }
10041 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010042 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010043
10044 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010045 }
10046
Jack Nudelman644b91a2021-03-12 14:09:48 -080010047 private static List<String> getThermalMitigationAllowlist(Context context) {
10048 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10049 for (String pckg : context.getResources()
10050 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10051 sThermalMitigationAllowlistedPackages.add(pckg);
10052 }
10053 }
10054
10055 return sThermalMitigationAllowlistedPackages;
10056 }
10057
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010058 private boolean isAnyPhoneInEmergencyState() {
10059 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10060 if (tm.isInEmergencyCall()) {
10061 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10062 return true;
10063 }
10064 for (Phone phone : PhoneFactory.getPhones()) {
10065 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10066 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10067 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10068 + phone.isInEcm());
10069 return true;
10070 }
10071 }
10072
10073 return false;
10074 }
10075
Jack Nudelman644b91a2021-03-12 14:09:48 -080010076 /**
10077 * Used by shell commands to add an authorized package name for thermal mitigation.
10078 * @param packageName name of package to be allowlisted
10079 * @param context
10080 */
10081 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10082 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10083 sThermalMitigationAllowlistedPackages.add(packageName);
10084 }
10085
10086 /**
10087 * Used by shell commands to remove an authorized package name for thermal mitigation.
10088 * @param packageName name of package to remove from allowlist
10089 * @param context
10090 */
10091 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10092 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10093 sThermalMitigationAllowlistedPackages.remove(packageName);
10094 }
10095
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010096 /**
10097 * Thermal mitigation request to control functionalities at modem.
10098 *
10099 * @param subId the id of the subscription.
10100 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010101 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010102 *
10103 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10104 */
10105 @Override
10106 @ThermalMitigationResult
10107 public int sendThermalMitigationRequest(
10108 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010109 ThermalMitigationRequest thermalMitigationRequest,
10110 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010111 enforceModifyPermission();
10112
Jack Nudelman644b91a2021-03-12 14:09:48 -080010113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10114 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10115 .contains(callingPackage)) {
10116 throw new SecurityException("Calling package must be configured in the device config. "
10117 + "calling package: " + callingPackage);
10118 }
10119
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010120 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10121 final long identity = Binder.clearCallingIdentity();
10122
10123 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10124 try {
10125 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10126 switch (thermalMitigationAction) {
10127 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10128 thermalMitigationResult =
10129 handleDataThrottlingRequest(subId,
10130 thermalMitigationRequest.getDataThrottlingRequest());
10131 break;
10132 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10133 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10134 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10135 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10136 }
10137
10138 // Ensure that radio is on. If not able to power on due to phone being
10139 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010140 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010141 thermalMitigationResult =
10142 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10143 break;
10144 }
10145
10146 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10147 false);
10148 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10149 break;
10150 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10151 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10152 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10153 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10154 }
10155
10156 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10157 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010158 Phone phone = getPhone(subId);
10159 if (phone == null) {
10160 thermalMitigationResult =
10161 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10162 break;
10163 }
10164
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010165 TelephonyConnectionService service =
10166 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010167 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010168 Log.e(LOG_TAG, "An emergency call is pending");
10169 thermalMitigationResult =
10170 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10171 break;
10172 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010173 thermalMitigationResult =
10174 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10175 break;
10176 }
10177 } else {
10178 thermalMitigationResult =
10179 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10180 break;
10181 }
10182
10183 // Turn radio off. If not able to power off due to phone being unavailable,
10184 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010185 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010186 thermalMitigationResult =
10187 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10188 break;
10189 }
10190 thermalMitigationResult =
10191 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10192 break;
10193 default:
10194 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10195 + "not exist. Requested action: " + thermalMitigationAction);
10196 }
10197 } catch (IllegalArgumentException e) {
10198 throw e;
10199 } catch (Exception e) {
10200 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10201 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10202 } finally {
10203 Binder.restoreCallingIdentity(identity);
10204 }
10205
10206 if (DBG) {
10207 log("thermalMitigationRequest returning with thermalMitigationResult: "
10208 + thermalMitigationResult);
10209 }
10210
10211 return thermalMitigationResult;
10212 }
Hui Wang641e81c2020-10-12 12:14:23 -070010213
10214 /**
10215 * Set the GbaService Package Name that Telephony will bind to.
10216 *
10217 * @param subId The sim that the GbaService is associated with.
10218 * @param packageName The name of the package to be replaced with.
10219 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10220 */
10221 @Override
10222 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10223 enforceModifyPermission();
10224
10225 final long identity = Binder.clearCallingIdentity();
10226 try {
10227 return getGbaManager(subId).overrideServicePackage(packageName);
10228 } finally {
10229 Binder.restoreCallingIdentity(identity);
10230 }
10231 }
10232
10233 /**
10234 * Return the package name of the currently bound GbaService.
10235 *
10236 * @param subId The sim that the GbaService is associated with.
10237 * @return the package name of the GbaService configuration, null if GBA is not supported.
10238 */
10239 @Override
10240 public String getBoundGbaService(int subId) {
10241 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10242
10243 final long identity = Binder.clearCallingIdentity();
10244 try {
10245 return getGbaManager(subId).getServicePackage();
10246 } finally {
10247 Binder.restoreCallingIdentity(identity);
10248 }
10249 }
10250
10251 /**
10252 * Set the release time for telephony to unbind GbaService.
10253 *
10254 * @param subId The sim that the GbaService is associated with.
10255 * @param interval The release time to unbind GbaService by millisecond.
10256 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10257 */
10258 @Override
10259 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10260 enforceModifyPermission();
10261
10262 final long identity = Binder.clearCallingIdentity();
10263 try {
10264 return getGbaManager(subId).overrideReleaseTime(interval);
10265 } finally {
10266 Binder.restoreCallingIdentity(identity);
10267 }
10268 }
10269
10270 /**
10271 * Return the release time for telephony to unbind GbaService.
10272 *
10273 * @param subId The sim that the GbaService is associated with.
10274 * @return The release time to unbind GbaService by millisecond.
10275 */
10276 @Override
10277 public int getGbaReleaseTime(int subId) {
10278 enforceReadPrivilegedPermission("getGbaReleaseTime");
10279
10280 final long identity = Binder.clearCallingIdentity();
10281 try {
10282 return getGbaManager(subId).getReleaseTime();
10283 } finally {
10284 Binder.restoreCallingIdentity(identity);
10285 }
10286 }
10287
10288 private GbaManager getGbaManager(int subId) {
10289 GbaManager instance = GbaManager.getInstance(subId);
10290 if (instance == null) {
10291 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10292 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10293 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10294 }
10295 return instance;
10296 }
Hui Wang761a6682020-10-31 05:12:53 +000010297
10298 /**
10299 * indicate whether the device and the carrier can support
10300 * RCS VoLTE single registration.
10301 */
10302 @Override
10303 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010304 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10305 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10306 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10307 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010308
10309 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10310 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10311 }
10312
10313 final long identity = Binder.clearCallingIdentity();
10314 try {
10315 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10316 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010317 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10318 if (isCapable != null) {
10319 return isCapable;
10320 }
Hui Wang761a6682020-10-31 05:12:53 +000010321 }
Hui Wang67af90e2021-06-04 16:57:15 -070010322 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10323 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010324 } finally {
10325 Binder.restoreCallingIdentity(identity);
10326 }
10327 }
10328
10329 /**
10330 * Register RCS provisioning callback.
10331 */
10332 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010333 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010334 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010335 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010336 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010337 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10338 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010339
10340 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10341 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10342 }
10343 if (!isImsAvailableOnDevice()) {
10344 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10345 "IMS not available on device.");
10346 }
10347
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010350 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010351 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010352 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10353 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010354 }
Hui Wang761a6682020-10-31 05:12:53 +000010355 } finally {
10356 Binder.restoreCallingIdentity(identity);
10357 }
10358 }
10359
10360 /**
10361 * Unregister RCS provisioning callback.
10362 */
10363 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010364 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010365 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010366 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010367 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010368 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10369 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010370
10371 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10372 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10373 }
10374 if (!isImsAvailableOnDevice()) {
10375 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10376 "IMS not available on device.");
10377 }
10378
10379 final long identity = Binder.clearCallingIdentity();
10380 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010381 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010382 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010383 } finally {
10384 Binder.restoreCallingIdentity(identity);
10385 }
10386 }
10387
10388 /**
10389 * trigger RCS reconfiguration.
10390 */
10391 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010392 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10393 "triggerRcsReconfiguration",
10394 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010395
10396 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10397 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10398 }
10399 if (!isImsAvailableOnDevice()) {
10400 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10401 "IMS not available on device.");
10402 }
10403
10404 final long identity = Binder.clearCallingIdentity();
10405 try {
10406 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10407 } finally {
10408 Binder.restoreCallingIdentity(identity);
10409 }
10410 }
10411
10412 /**
10413 * Provide the client configuration parameters of the RCS application.
10414 */
10415 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010416 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10417 "setRcsClientConfiguration",
10418 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010419
10420 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10421 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10422 }
10423 if (!isImsAvailableOnDevice()) {
10424 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10425 "IMS not available on device.");
10426 }
10427
10428 final long identity = Binder.clearCallingIdentity();
10429
10430 try {
10431 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10432 if (configBinder == null) {
10433 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010434 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10435 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010436 } else {
10437 configBinder.setRcsClientConfiguration(rcc);
10438 }
10439 } catch (RemoteException e) {
10440 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010441 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10442 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010443 } finally {
10444 Binder.restoreCallingIdentity(identity);
10445 }
10446 }
10447
10448 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010449 * Enables or disables the test mode for RCS VoLTE single registration.
10450 */
10451 @Override
10452 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10453 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10454 "setRcsSingleRegistrationTestModeEnabled");
10455
10456 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10457 }
10458
10459 /**
10460 * Gets the test mode for RCS VoLTE single registration.
10461 */
10462 @Override
10463 public boolean getRcsSingleRegistrationTestModeEnabled() {
10464 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10465 "getRcsSingleRegistrationTestModeEnabled");
10466
10467 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10468 }
10469
10470 /**
Hui Wang761a6682020-10-31 05:12:53 +000010471 * Overrides the config of RCS VoLTE single registration enabled for the device.
10472 */
10473 @Override
10474 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10475 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10476 "setDeviceSingleRegistrationEnabledOverride");
10477 enforceModifyPermission();
10478
10479 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10480 : Boolean.parseBoolean(enabledStr);
10481 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010482 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010483 }
10484
10485 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010486 * Sends a device to device communication message. Only usable via shell.
10487 * @param message message to send.
10488 * @param value message value.
10489 */
10490 @Override
10491 public void sendDeviceToDeviceMessage(int message, int value) {
10492 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010493 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010494 enforceModifyPermission();
10495
10496 final long identity = Binder.clearCallingIdentity();
10497 try {
10498 TelephonyConnectionService service =
10499 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10500 if (service == null) {
10501 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10502 return;
10503 }
10504 service.sendTestDeviceToDeviceMessage(message, value);
10505 } finally {
10506 Binder.restoreCallingIdentity(identity);
10507 }
10508 }
10509
Tyler Gunnbabbda02021-02-10 11:05:02 -080010510 /**
10511 * Sets the specified device to device transport active.
10512 * @param transport The transport to set active.
10513 */
10514 @Override
10515 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10516 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10517 "setActiveDeviceToDeviceTransport");
10518 enforceModifyPermission();
10519
10520 final long identity = Binder.clearCallingIdentity();
10521 try {
10522 TelephonyConnectionService service =
10523 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10524 if (service == null) {
10525 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10526 return;
10527 }
10528 service.setActiveDeviceToDeviceTransport(transport);
10529 } finally {
10530 Binder.restoreCallingIdentity(identity);
10531 }
10532 }
Tyler Gunn92479152021-01-20 16:30:10 -080010533
Tyler Gunnd4575212021-05-03 14:46:49 -070010534 @Override
10535 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10536 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10537 "setDeviceToDeviceForceEnabled");
10538
10539 final long identity = Binder.clearCallingIdentity();
10540 try {
10541 Arrays.stream(PhoneFactory.getPhones()).forEach(
10542 p -> {
10543 Phone thePhone = p.getImsPhone();
10544 if (thePhone != null && thePhone instanceof ImsPhone) {
10545 ImsPhone imsPhone = (ImsPhone) thePhone;
10546 CallTracker tracker = imsPhone.getCallTracker();
10547 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10548 ImsPhoneCallTracker imsPhoneCallTracker =
10549 (ImsPhoneCallTracker) tracker;
10550 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10551 }
10552 }
10553 }
10554 );
10555 } finally {
10556 Binder.restoreCallingIdentity(identity);
10557 }
10558 }
10559
Tyler Gunn92479152021-01-20 16:30:10 -080010560 /**
Hui Wang761a6682020-10-31 05:12:53 +000010561 * Gets the config of RCS VoLTE single registration enabled for the device.
10562 */
10563 @Override
10564 public boolean getDeviceSingleRegistrationEnabled() {
10565 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10566 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10567 }
10568
10569 /**
10570 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10571 */
10572 @Override
10573 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10574 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10575 "setCarrierSingleRegistrationEnabledOverride");
10576 enforceModifyPermission();
10577
10578 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10579 : Boolean.parseBoolean(enabledStr);
10580 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10581 subId, enabled);
10582 }
10583
10584 /**
10585 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10586 */
10587 @Override
10588 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10589 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10590 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10591 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010592
10593 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010594 * Overrides the ims feature validation result
10595 */
10596 @Override
10597 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10598 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10599 "setImsFeatureValidationOverride");
10600
10601 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10602 : Boolean.parseBoolean(enabledStr);
10603 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10604 subId, enabled);
10605 }
10606
10607 /**
10608 * Gets the ims feature validation override value
10609 */
10610 @Override
10611 public boolean getImsFeatureValidationOverride(int subId) {
10612 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10613 "getImsFeatureValidationOverride");
10614 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10615 }
10616
10617 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010618 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10619 * their mobile plan.
10620 */
10621 @Override
10622 public String getMobileProvisioningUrl() {
10623 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10624 final long identity = Binder.clearCallingIdentity();
10625 try {
10626 return getDefaultPhone().getMobileProvisioningUrl();
10627 } finally {
10628 Binder.restoreCallingIdentity(identity);
10629 }
10630 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010631
James.cf Linbcdf8b32021-01-14 16:44:13 +080010632 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010633 * Get the EAB contact from the EAB database.
10634 */
10635 @Override
10636 public String getContactFromEab(String contact) {
10637 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10638 enforceModifyPermission();
10639 final long identity = Binder.clearCallingIdentity();
10640 try {
10641 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10642 } finally {
10643 Binder.restoreCallingIdentity(identity);
10644 }
10645 }
10646
10647 /**
Calvin Pana1434322021-07-01 19:27:01 +080010648 * Get the EAB capability from the EAB database.
10649 */
10650 @Override
10651 public String getCapabilityFromEab(String contact) {
10652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10653 enforceModifyPermission();
10654 final long identity = Binder.clearCallingIdentity();
10655 try {
10656 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10657 } finally {
10658 Binder.restoreCallingIdentity(identity);
10659 }
10660 }
10661
10662 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010663 * Remove the EAB contacts from the EAB database.
10664 */
10665 @Override
10666 public int removeContactFromEab(int subId, String contacts) {
10667 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10668 enforceModifyPermission();
10669 final long identity = Binder.clearCallingIdentity();
10670 try {
10671 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10672 } finally {
10673 Binder.restoreCallingIdentity(identity);
10674 }
10675 }
10676
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010677 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010678 public boolean getDeviceUceEnabled() {
10679 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10680 final long identity = Binder.clearCallingIdentity();
10681 try {
10682 return mApp.getDeviceUceEnabled();
10683 } finally {
10684 Binder.restoreCallingIdentity(identity);
10685 }
10686 }
10687
10688 @Override
10689 public void setDeviceUceEnabled(boolean isEnabled) {
10690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10691 final long identity = Binder.clearCallingIdentity();
10692 try {
10693 mApp.setDeviceUceEnabled(isEnabled);
10694 } finally {
10695 Binder.restoreCallingIdentity(identity);
10696 }
10697 }
10698
Brad Ebinger14d467f2021-02-12 06:18:28 +000010699 /**
10700 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10701 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10702 */
10703 // Used for SHELL command only right now.
10704 @Override
10705 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10706 List<String> featureTags) {
10707 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10708 "addUceRegistrationOverrideShell");
10709 final long identity = Binder.clearCallingIdentity();
10710 try {
10711 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10712 new ArraySet<>(featureTags));
10713 } catch (ImsException e) {
10714 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10715 } finally {
10716 Binder.restoreCallingIdentity(identity);
10717 }
10718 }
10719
10720 /**
10721 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10722 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10723 */
10724 // Used for SHELL command only right now.
10725 @Override
10726 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10727 List<String> featureTags) {
10728 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10729 "removeUceRegistrationOverrideShell");
10730 final long identity = Binder.clearCallingIdentity();
10731 try {
10732 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10733 new ArraySet<>(featureTags));
10734 } catch (ImsException e) {
10735 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10736 } finally {
10737 Binder.restoreCallingIdentity(identity);
10738 }
10739 }
10740
10741 /**
10742 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10743 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10744 */
10745 // Used for SHELL command only right now.
10746 @Override
10747 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10748 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10749 "clearUceRegistrationOverrideShell");
10750 final long identity = Binder.clearCallingIdentity();
10751 try {
10752 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10753 } catch (ImsException e) {
10754 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10755 } finally {
10756 Binder.restoreCallingIdentity(identity);
10757 }
10758 }
10759
10760 /**
10761 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10762 */
10763 // Used for SHELL command only right now.
10764 @Override
10765 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10767 "getLatestRcsContactUceCapabilityShell");
10768 final long identity = Binder.clearCallingIdentity();
10769 try {
10770 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10771 } catch (ImsException e) {
10772 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10773 } finally {
10774 Binder.restoreCallingIdentity(identity);
10775 }
10776 }
10777
10778 /**
10779 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10780 * device does not have an active PUBLISH.
10781 */
10782 // Used for SHELL command only right now.
10783 @Override
10784 public String getLastUcePidfXmlShell(int subId) {
10785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10786 final long identity = Binder.clearCallingIdentity();
10787 try {
10788 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10789 } catch (ImsException e) {
10790 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10791 } finally {
10792 Binder.restoreCallingIdentity(identity);
10793 }
10794 }
10795
James.cf Line8713a42021-04-29 16:04:26 +080010796 /**
10797 * Remove UCE requests cannot be sent to the network status.
10798 */
10799 // Used for SHELL command only right now.
10800 @Override
10801 public boolean removeUceRequestDisallowedStatus(int subId) {
10802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10803 final long identity = Binder.clearCallingIdentity();
10804 try {
10805 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10806 } catch (ImsException e) {
10807 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10808 } finally {
10809 Binder.restoreCallingIdentity(identity);
10810 }
10811 }
10812
James.cf Lin0fc71b02021-05-25 01:37:38 +080010813 /**
10814 * Remove UCE requests cannot be sent to the network status.
10815 */
10816 // Used for SHELL command only.
10817 @Override
10818 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10819 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10820 final long identity = Binder.clearCallingIdentity();
10821 try {
10822 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10823 } catch (ImsException e) {
10824 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10825 } finally {
10826 Binder.restoreCallingIdentity(identity);
10827 }
10828 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010829
James.cf Lin4b784aa2021-01-31 03:25:15 +080010830 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010831 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10832 String callingPackage) {
10833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10834 mApp, subId, "setSignalStrengthUpdateRequest");
10835
10836 final int callingUid = Binder.getCallingUid();
10837 // Verify that tha callingPackage belongs to the calling UID
10838 mApp.getSystemService(AppOpsManager.class)
10839 .checkPackage(callingUid, callingPackage);
10840
Rambo Wang3607f502021-02-01 21:51:40 -080010841 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010842
10843 final long identity = Binder.clearCallingIdentity();
10844 try {
10845 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10846 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10847
10848 if (result instanceof IllegalStateException) {
10849 throw (IllegalStateException) result;
10850 }
10851 } finally {
10852 Binder.restoreCallingIdentity(identity);
10853 }
10854 }
10855
10856 @Override
10857 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10858 String callingPackage) {
10859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10860 mApp, subId, "clearSignalStrengthUpdateRequest");
10861
10862 final int callingUid = Binder.getCallingUid();
10863 // Verify that tha callingPackage belongs to the calling UID
10864 mApp.getSystemService(AppOpsManager.class)
10865 .checkPackage(callingUid, callingPackage);
10866
10867 final long identity = Binder.clearCallingIdentity();
10868 try {
10869 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10870 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10871
10872 if (result instanceof IllegalStateException) {
10873 throw (IllegalStateException) result;
10874 }
10875 } finally {
10876 Binder.restoreCallingIdentity(identity);
10877 }
10878 }
10879
Rambo Wang3607f502021-02-01 21:51:40 -080010880 private static void validateSignalStrengthUpdateRequest(Context context,
10881 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010882 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10883 // phone/system process do not have further restriction on request
10884 return;
10885 }
10886
10887 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010888 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010889 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010890 context.enforceCallingOrSelfPermission(
10891 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10892 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010893 }
10894
10895 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10896 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10897 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10898 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10899 || info.isEnabled()) {
10900 throw new IllegalArgumentException(
10901 "Only system can set hide fields in SignalThresholdInfo");
10902 }
10903
10904 // Thresholds length for each RAN need in range. This has been validated in
10905 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10906 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10907 final int[] thresholds = info.getThresholds();
10908 Objects.requireNonNull(thresholds);
10909 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10910 || thresholds.length
10911 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10912 throw new IllegalArgumentException(
10913 "thresholds length is out of range: " + thresholds.length);
10914 }
10915 }
10916 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010917
10918 /**
10919 * Gets the current phone capability.
10920 *
10921 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10922 * @return the PhoneCapability which describes the data connection capability of modem.
10923 * It's used to evaluate possible phone config change, for example from single
10924 * SIM device to multi-SIM device.
10925 */
10926 @Override
10927 public PhoneCapability getPhoneCapability() {
10928 enforceReadPrivilegedPermission("getPhoneCapability");
10929 final long identity = Binder.clearCallingIdentity();
10930 try {
10931 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
Michele Berionne5e411512020-11-13 02:36:59 +000010936
10937 /**
10938 * Prepare TelephonyManager for an unattended reboot. The reboot is
10939 * required to be done shortly after the API is invoked.
10940 */
10941 @Override
10942 @TelephonyManager.PrepareUnattendedRebootResult
10943 public int prepareForUnattendedReboot() {
10944 enforceRebootPermission();
10945
10946 final long identity = Binder.clearCallingIdentity();
10947 try {
10948 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10949 } finally {
10950 Binder.restoreCallingIdentity(identity);
10951 }
10952 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010953
10954 /**
10955 * Request to get the current slicing configuration including URSP rules and
10956 * NSSAIs (configured, allowed and rejected).
10957 *
10958 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10959 */
10960 @Override
10961 public void getSlicingConfig(ResultReceiver callback) {
10962 enforceReadPrivilegedPermission("getSlicingConfig");
10963
10964 final long identity = Binder.clearCallingIdentity();
10965 try {
10966 Phone phone = getDefaultPhone();
10967 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10968 } finally {
10969 Binder.restoreCallingIdentity(identity);
10970 }
10971 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000010972
10973 /**
10974 * Register an IMS connection state callback
10975 */
10976 @Override
10977 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
10978 String callingPackage) {
10979 if (feature == ImsFeature.FEATURE_MMTEL) {
10980 // ImsMmTelManager
10981 // The following also checks READ_PRIVILEGED_PHONE_STATE.
10982 TelephonyPermissions
10983 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
10984 mApp, subId, "registerImsStateCallback");
10985 } else if (feature == ImsFeature.FEATURE_RCS) {
10986 // ImsRcsManager or SipDelegateManager
10987 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10988 Binder.getCallingUid(), "registerImsStateCallback",
10989 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
10990 Manifest.permission.READ_PRECISE_PHONE_STATE,
10991 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
10992 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
10993 }
10994
10995 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
10996 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10997 "IMS not available on device.");
10998 }
10999
11000 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11001 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11002 }
11003
11004 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11005 if (controller == null) {
11006 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11007 "IMS not available on device.");
11008 }
11009
11010 if (callingPackage == null) {
11011 callingPackage = getCurrentPackageName();
11012 }
11013
11014 final long token = Binder.clearCallingIdentity();
11015 try {
11016 int slotId = getSlotIndexOrException(subId);
11017 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11018 } catch (ImsException e) {
11019 throw new ServiceSpecificException(e.getCode());
11020 } finally {
11021 Binder.restoreCallingIdentity(token);
11022 }
11023 }
11024
11025 /**
11026 * Unregister an IMS connection state callback
11027 */
11028 @Override
11029 public void unregisterImsStateCallback(IImsStateCallback cb) {
11030 final long token = Binder.clearCallingIdentity();
11031 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11032 if (controller == null) {
11033 return;
11034 }
11035 try {
11036 controller.unregisterImsStateCallback(cb);
11037 } finally {
11038 Binder.restoreCallingIdentity(token);
11039 }
11040 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011041
11042 /**
11043 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11044 *
11045 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11046 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11047 * SecurityException.
11048 * If there is current registered network this value will be same as the registered cell
11049 * identity. If the device goes out of service the previous cell identity is cached and
11050 * will be returned. If the cache age of the Cell identity is more than 24 hours
11051 * it will be cleared and null will be returned.
11052 *
11053 */
11054 @Override
11055 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11056 String callingFeatureId) {
11057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11058 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11059 LocationAccessPolicy.checkLocationPermission(mApp,
11060 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11061 .setCallingPackage(callingPackage)
11062 .setCallingFeatureId(callingFeatureId)
11063 .setCallingPid(Binder.getCallingPid())
11064 .setCallingUid(Binder.getCallingUid())
11065 .setMethod("getLastKnownCellIdentity")
11066 .setLogAsInfo(true)
11067 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11068 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11069 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11070 .build());
11071
11072 boolean hasFinePermission =
11073 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11074 if (!hasFinePermission
11075 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11076 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11077 + "and BIND_CONNECTION_SERVICE permission.");
11078 }
11079
11080 final long identity = Binder.clearCallingIdentity();
11081 try {
11082 Phone phone = getPhone(subId);
11083 if (phone == null) return null;
11084 ServiceStateTracker sst = phone.getServiceStateTracker();
11085 if (sst == null) return null;
11086 return sst.getLastKnownCellIdentity();
11087 } finally {
11088 Binder.restoreCallingIdentity(identity);
11089 }
11090 }
jimsun38340bf2021-10-26 15:01:23 +080011091
11092 /**
11093 * Sets the modem service class Name that Telephony will bind to.
11094 *
11095 * @param serviceName The class name of the modem service.
11096 * @return true if the operation is succeed, otherwise false.
11097 */
11098 public boolean setModemService(String serviceName) {
11099 Log.d(LOG_TAG, "setModemService - " + serviceName);
11100 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11102 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11103 "setModemService");
11104 return mPhoneConfigurationManager.setModemService(serviceName);
11105 }
11106
11107 /**
11108 * Return the class name of the currently bounded modem service.
11109 *
11110 * @return the class name of the modem service.
11111 */
11112 public String getModemService() {
11113 String result;
11114 Log.d(LOG_TAG, "getModemService");
11115 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11116 TelephonyPermissions
11117 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11118 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11119 "getModemService");
11120 result = mPhoneConfigurationManager.getModemService();
11121 Log.d(LOG_TAG, "result = " + result);
11122 return result;
11123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011124}