blob: a35ac9bdee117d3488b9797232af875abd094643 [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()
1150 ? CommandsInterface.CF_ACTION_ENABLE
1151 : 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 Haroldf096d982020-11-18 17:18:06 -08003041 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003042 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3043 throw new SecurityException(
3044 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3045 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003046
Jordan Liu1617b712019-07-10 15:06:26 -07003047 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3049 return null;
3050 }
Svetoslav64fad262015-04-14 14:35:21 -07003051
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003052 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003054 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003055 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056
Nathan Haroldf180aac2018-06-01 18:43:55 -07003057 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3058 for (CellInfo ci : info) {
3059 if (ci instanceof CellInfoGsm) {
3060 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3061 } else if (ci instanceof CellInfoWcdma) {
3062 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003065 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 }
3067
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003068 private List<CellInfo> getCachedCellInfo() {
3069 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3070 for (Phone phone : PhoneFactory.getPhones()) {
3071 List<CellInfo> info = phone.getAllCellInfo();
3072 if (info != null) cellInfos.addAll(info);
3073 }
3074 return cellInfos;
3075 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003076
3077 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003078 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003079 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003080 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003081
3082 LocationAccessPolicy.LocationPermissionResult locationResult =
3083 LocationAccessPolicy.checkLocationPermission(mApp,
3084 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3085 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003086 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003087 .setCallingPid(Binder.getCallingPid())
3088 .setCallingUid(Binder.getCallingUid())
3089 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003090 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003091 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3092 .build());
3093 switch (locationResult) {
3094 case DENIED_HARD:
3095 throw new SecurityException("Not allowed to access cell info");
3096 case DENIED_SOFT:
3097 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 }
3099
Nathan Haroldf096d982020-11-18 17:18:06 -08003100 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003101 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3102 return getCachedCellInfo();
3103 }
3104
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003105 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003106 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3110 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003111 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003112 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 if (info != null) cellInfos.addAll(info);
3114 }
3115 return cellInfos;
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003118 }
3119 }
3120
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003121 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003122 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3123 String callingFeatureId) {
3124 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3125 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003126 }
3127
3128 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003129 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3130 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003131 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003132 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003133 }
3134
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003135 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3136 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003137 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003138 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003139
3140 LocationAccessPolicy.LocationPermissionResult locationResult =
3141 LocationAccessPolicy.checkLocationPermission(mApp,
3142 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3143 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003144 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003145 .setCallingPid(Binder.getCallingPid())
3146 .setCallingUid(Binder.getCallingUid())
3147 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003148 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3149 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003150 .build());
3151 switch (locationResult) {
3152 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003153 if (TelephonyPermissions
3154 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003155 // Safetynet logging for b/154934934
3156 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3157 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003158 throw new SecurityException("Not allowed to access cell info");
3159 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003160 if (TelephonyPermissions
3161 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003162 // Safetynet logging for b/154934934
3163 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3164 }
Nathan Harold5320c422019-05-09 10:26:08 -07003165 try {
3166 cb.onCellInfo(new ArrayList<CellInfo>());
3167 } catch (RemoteException re) {
3168 // Drop without consequences
3169 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003170 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003171 }
3172
Nathan Harolda939a962019-05-09 10:13:47 -07003173
3174 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003175 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3176
3177 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3178 }
3179
3180 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003182 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003183 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003187 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 }
3192
Shishir Agrawala9f32182016-04-12 12:00:16 -07003193 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003194 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003195 Phone phone = PhoneFactory.getPhone(slotIndex);
3196 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003197 return null;
3198 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003199 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003200 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003201 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003202 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003203 return null;
3204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205
3206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 return phone.getImei();
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003212 }
3213
3214 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003215 public String getTypeAllocationCodeForSlot(int slotIndex) {
3216 Phone phone = PhoneFactory.getPhone(slotIndex);
3217 String tac = null;
3218 if (phone != null) {
3219 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003220 try {
3221 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3222 } catch (IndexOutOfBoundsException e) {
3223 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3224 return null;
3225 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003226 }
3227 return tac;
3228 }
3229
3230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003231 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003232 Phone phone = PhoneFactory.getPhone(slotIndex);
3233 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003234 return null;
3235 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003236
Jeff Davidson913390f2018-02-23 17:11:49 -08003237 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003238 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003239 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003240 return null;
3241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242
3243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 return phone.getMeid();
3246 } finally {
3247 Binder.restoreCallingIdentity(identity);
3248 }
Jack Yu2af8d712017-03-15 17:14:14 -07003249 }
3250
3251 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003252 public String getManufacturerCodeForSlot(int slotIndex) {
3253 Phone phone = PhoneFactory.getPhone(slotIndex);
3254 String manufacturerCode = null;
3255 if (phone != null) {
3256 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003257 try {
3258 manufacturerCode =
3259 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3260 } catch (IndexOutOfBoundsException e) {
3261 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3262 return null;
3263 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003264 }
3265 return manufacturerCode;
3266 }
3267
3268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003269 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3270 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003271 Phone phone = PhoneFactory.getPhone(slotIndex);
3272 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003273 return null;
3274 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003275 int subId = phone.getSubId();
3276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003277 mApp, subId, callingPackage, callingFeatureId,
3278 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003279 return null;
3280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 return phone.getDeviceSvn();
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003288 }
3289
fionaxu43304da2017-11-27 22:51:16 -08003290 @Override
3291 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 final Phone phone = getPhone(subId);
3295 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
fionaxu43304da2017-11-27 22:51:16 -08003299 }
3300
3301 @Override
3302 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303 final long identity = Binder.clearCallingIdentity();
3304 try {
3305 final Phone phone = getPhone(subId);
3306 return phone == null ? null : phone.getCarrierName();
3307 } finally {
3308 Binder.restoreCallingIdentity(identity);
3309 }
fionaxu43304da2017-11-27 22:51:16 -08003310 }
3311
calvinpanffe225e2018-11-01 19:43:06 +08003312 @Override
chen xu0026ca62019-03-06 15:28:50 -08003313 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 final Phone phone = getPhone(subId);
3317 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003318 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
3322 }
3323
3324 @Override
chen xu0026ca62019-03-06 15:28:50 -08003325 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003329 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
3333 }
3334
chen xu651eec72018-11-11 19:03:44 -08003335 @Override
chen xu864e11c2018-12-06 22:10:03 -08003336 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3337 if (!isSubscriptionMccMnc) {
3338 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3339 }
chen xu651eec72018-11-11 19:03:44 -08003340 final Phone phone = PhoneFactory.getPhone(slotIndex);
3341 if (phone == null) {
3342 return TelephonyManager.UNKNOWN_CARRIER_ID;
3343 }
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
3350 }
3351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 //
3353 // Internal helper methods.
3354 //
3355
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003356 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003357 * Make sure the caller is the calling package itself
3358 *
3359 * @throws SecurityException if the caller is not the calling package
3360 */
3361 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3362 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003363 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3364 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003365 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003366 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003367 } catch (PackageManager.NameNotFoundException e) {
3368 // packageUid is -1
3369 }
3370 if (packageUid != callingUid) {
3371 throw new SecurityException(message + ": Package " + callingPackage
3372 + " does not belong to " + callingUid);
3373 }
3374 }
3375
3376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003377 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3378 *
3379 * @throws SecurityException if the caller does not have the required permission
3380 */
3381 private void enforceModifyPermission() {
3382 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3383 }
3384
Shuo Qian3b6ee772019-11-13 17:43:31 -08003385 private void enforceActiveEmergencySessionPermission() {
3386 mApp.enforceCallingOrSelfPermission(
3387 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3388 }
3389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 /**
3391 * Make sure the caller has the CALL_PHONE permission.
3392 *
3393 * @throws SecurityException if the caller does not have the required permission
3394 */
3395 private void enforceCallPermission() {
3396 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3397 }
3398
paulhu5a773602019-08-23 19:17:33 +08003399 private void enforceSettingsPermission() {
3400 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003401 }
3402
Michele Berionne5e411512020-11-13 02:36:59 +00003403 private void enforceRebootPermission() {
3404 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3405 }
3406
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003407 private String createTelUrl(String number) {
3408 if (TextUtils.isEmpty(number)) {
3409 return null;
3410 }
3411
Jake Hambye994d462014-02-03 13:10:13 -08003412 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 }
3414
Ihab Awadf9e92732013-12-05 18:02:52 -08003415 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003416 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3417 }
3418
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003419 private static void logv(String msg) {
3420 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3421 }
3422
Ihab Awadf9e92732013-12-05 18:02:52 -08003423 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003424 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3425 }
3426
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003427 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003428 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003429 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003430 }
3431
Sanket Padawe356d7632015-06-22 14:03:32 -07003432 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003433 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 final Phone phone = PhoneFactory.getPhone(slotIndex);
3437 if (phone == null) {
3438 return PhoneConstants.PHONE_TYPE_NONE;
3439 } else {
3440 return phone.getPhoneType();
3441 }
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 }
3446
3447 /**
3448 * Returns the CDMA ERI icon index to display
3449 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003450 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003451 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3452 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3453 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003454 }
3455
Sanket Padawe356d7632015-06-22 14:03:32 -07003456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003457 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3458 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003460 mApp, subId, callingPackage, callingFeatureId,
3461 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003462 return -1;
3463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464
3465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 final Phone phone = getPhone(subId);
3468 if (phone != null) {
3469 return phone.getCdmaEriIconIndex();
3470 } else {
3471 return -1;
3472 }
3473 } finally {
3474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476 }
3477
3478 /**
3479 * Returns the CDMA ERI icon mode,
3480 * 0 - ON
3481 * 1 - FLASHING
3482 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003483 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003484 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3485 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3486 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003487 }
3488
Sanket Padawe356d7632015-06-22 14:03:32 -07003489 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003490 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3491 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003493 mApp, subId, callingPackage, callingFeatureId,
3494 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003495 return -1;
3496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003497
3498 final long identity = Binder.clearCallingIdentity();
3499 try {
3500 final Phone phone = getPhone(subId);
3501 if (phone != null) {
3502 return phone.getCdmaEriIconMode();
3503 } else {
3504 return -1;
3505 }
3506 } finally {
3507 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003509 }
3510
3511 /**
3512 * Returns the CDMA ERI text,
3513 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003515 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3516 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3517 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003518 }
3519
Sanket Padawe356d7632015-06-22 14:03:32 -07003520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003521 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3522 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003524 mApp, subId, callingPackage, callingFeatureId,
3525 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003526 return null;
3527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 final Phone phone = getPhone(subId);
3532 if (phone != null) {
3533 return phone.getCdmaEriText();
3534 } else {
3535 return null;
3536 }
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003540 }
3541
3542 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003543 * Returns the CDMA MDN.
3544 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003546 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3548 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003553 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554 return phone.getLine1Number();
3555 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003556 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557 return null;
3558 }
3559 } finally {
3560 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003561 }
3562 }
3563
3564 /**
3565 * Returns the CDMA MIN.
3566 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003567 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003568 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3570 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571
3572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 final Phone phone = getPhone(subId);
3575 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3576 return phone.getCdmaMin();
3577 } else {
3578 return null;
3579 }
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003582 }
3583 }
3584
Hall Liud892bec2018-11-30 14:51:45 -08003585 @Override
3586 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3587 INumberVerificationCallback callback, String callingPackage) {
3588 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3589 != PERMISSION_GRANTED) {
3590 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3591 }
3592 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3593
3594 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3595 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003596 throw new SecurityException("Calling package must be configured in the device config: "
3597 + "calling package: " + callingPackage
3598 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003599 }
3600
3601 if (range == null) {
3602 throw new NullPointerException("Range must be non-null");
3603 }
3604
3605 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003606 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003607
3608 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3609 }
3610
Junda Liuca05d5d2014-08-14 22:36:34 -07003611 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003612 * Returns true if CDMA provisioning needs to run.
3613 */
3614 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003615 final long identity = Binder.clearCallingIdentity();
3616 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003617 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003618 } finally {
3619 Binder.restoreCallingIdentity(identity);
3620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003621 }
3622
3623 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003624 * Sets the voice mail number of a given subId.
3625 */
3626 @Override
3627 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003628 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3629 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630
3631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3634 new Pair<String, String>(alphaTag, number), new Integer(subId));
3635 return success;
3636 } finally {
3637 Binder.restoreCallingIdentity(identity);
3638 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003639 }
3640
Ta-wei Yen87c49842016-05-13 21:19:52 -07003641 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003642 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003644 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3645 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003646 if (!TextUtils.equals(callingPackage, systemDialer)) {
3647 throw new SecurityException("caller must be system dialer");
3648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3653 if (phoneAccountHandle == null) {
3654 return null;
3655 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003659 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003660 }
3661
3662 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003663 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3664 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003667 mApp, subId, callingPackage, callingFeatureId,
3668 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003669 return null;
3670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003672 final long identity = Binder.clearCallingIdentity();
3673 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003674 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003678 }
3679
3680 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003681 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3682 VisualVoicemailSmsFilterSettings settings) {
3683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684
3685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003688 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003692 }
3693
3694 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003695 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003697
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003701 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003705 }
3706
3707 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003708 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3709 String callingPackage, int subId) {
3710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711
3712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003715 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003719 }
3720
3721 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003722 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724
3725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003728 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003732 }
3733
3734 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003735 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3736 String callingAttributionTag, int subId, String number, int port, String text,
3737 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003739 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003740 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003741 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003742 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3743 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003744 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003745
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003746 /**
fionaxu0152e512016-11-14 13:36:14 -08003747 * Sets the voice activation state of a given subId.
3748 */
3749 @Override
3750 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3752 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753
3754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 final Phone phone = getPhone(subId);
3757 if (phone != null) {
3758 phone.setVoiceActivationState(activationState);
3759 } else {
3760 loge("setVoiceActivationState fails with invalid subId: " + subId);
3761 }
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003764 }
3765 }
3766
3767 /**
3768 * Sets the data activation state of a given subId.
3769 */
3770 @Override
3771 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3773 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774
3775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 final Phone phone = getPhone(subId);
3778 if (phone != null) {
3779 phone.setDataActivationState(activationState);
3780 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003781 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782 }
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003785 }
3786 }
3787
3788 /**
3789 * Returns the voice activation state of a given subId.
3790 */
3791 @Override
3792 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794
fionaxu0152e512016-11-14 13:36:14 -08003795 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 if (phone != null) {
3799 return phone.getVoiceActivationState();
3800 } else {
3801 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3802 }
3803 } finally {
3804 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003805 }
3806 }
3807
3808 /**
3809 * Returns the data activation state of a given subId.
3810 */
3811 @Override
3812 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003813 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814
fionaxu0152e512016-11-14 13:36:14 -08003815 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 final long identity = Binder.clearCallingIdentity();
3817 try {
3818 if (phone != null) {
3819 return phone.getDataActivationState();
3820 } else {
3821 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3822 }
3823 } finally {
3824 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003825 }
3826 }
3827
3828 /**
Wink Saville36469e72014-06-11 15:17:00 -07003829 * Returns the unread count of voicemails for a subId
3830 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003831 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003832 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3833 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003835 mApp, subId, callingPackage, callingFeatureId,
3836 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003837 return 0;
3838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 final Phone phone = getPhone(subId);
3842 if (phone != null) {
3843 return phone.getVoiceMessageCount();
3844 } else {
3845 return 0;
3846 }
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003850 }
3851
3852 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003853 * returns true, if the device is in a state where both voice and data
3854 * are supported simultaneously. This can change based on location or network condition.
3855 */
3856 @Override
3857 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003858 final long identity = Binder.clearCallingIdentity();
3859 try {
3860 final Phone phone = getPhone(subId);
3861 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
3864 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003865 }
3866
3867 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003868 * Send the dialer code if called from the current default dialer or the caller has
3869 * carrier privilege.
3870 * @param inputCode The dialer code to send
3871 */
3872 @Override
3873 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003874 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003875 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003876 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3877 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003878 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003879 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003880 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882
3883 final long identity = Binder.clearCallingIdentity();
3884 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003885 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 } finally {
3887 Binder.restoreCallingIdentity(identity);
3888 }
fionaxu235cc5e2017-03-06 22:25:57 -08003889 }
3890
Pengquan Menga1bb6272018-09-06 09:59:22 -07003891 @Override
3892 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003893 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003894 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003895 mApp, subId, "getNetworkSelectionMode");
3896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 if (!isActiveSubscription(subId)) {
3899 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3900 }
3901 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003904 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003905 }
3906
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003908 public boolean isInEmergencySmsMode() {
3909 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3910 final long identity = Binder.clearCallingIdentity();
3911 try {
3912 for (Phone phone : PhoneFactory.getPhones()) {
3913 if (phone.isInEmergencySmsMode()) {
3914 return true;
3915 }
3916 }
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
3920 return false;
3921 }
3922
shilu366312e2019-12-17 09:28:10 -08003923 /**
3924 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3925 * @param subId The subscription to use to check the configuration.
3926 * @param c The callback that will be used to send the result.
3927 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003928 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003929 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3930 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003931 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003932 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003933
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003934 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3935 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3936 "IMS not available on device.");
3937 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003938 final long token = Binder.clearCallingIdentity();
3939 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003940 int slotId = getSlotIndexOrException(subId);
3941 verifyImsMmTelConfiguredOrThrow(slotId);
3942 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003943 } catch (ImsException e) {
3944 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 } finally {
3946 Binder.restoreCallingIdentity(token);
3947 }
3948 }
3949
shilu366312e2019-12-17 09:28:10 -08003950 /**
3951 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3952 * @param subId The subscription to use to check the configuration.
3953 * @param c The callback that will be used to send the result.
3954 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003956 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003957 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003958 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003959 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3960 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3961 }
Meng Wangafbc5852019-09-19 17:37:13 -07003962 final long token = Binder.clearCallingIdentity();
3963 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003964 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3965 .removeRegistrationCallbackForSubscription(c, subId);
3966 } catch (ImsException e) {
3967 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3968 + "is inactive, ignoring unregister.");
3969 // If the subscription is no longer active, just return, since the callback
3970 // will already have been removed internally.
3971 } finally {
3972 Binder.restoreCallingIdentity(token);
3973 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 }
3975
Brad Ebingera34a6c22019-10-22 17:36:18 -07003976 /**
3977 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3978 */
3979 @Override
3980 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3981 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3982 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3983 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3984 "IMS not available on device.");
3985 }
3986 final long token = Binder.clearCallingIdentity();
3987 try {
3988 Phone phone = getPhone(subId);
3989 if (phone == null) {
3990 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3991 + subId + "'");
3992 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3993 }
3994 phone.getImsRegistrationState(regState -> {
3995 try {
3996 consumer.accept((regState == null)
3997 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3998 } catch (RemoteException e) {
3999 // Ignore if the remote process is no longer available to call back.
4000 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4001 }
4002 });
4003 } finally {
4004 Binder.restoreCallingIdentity(token);
4005 }
4006 }
4007
4008 /**
4009 * Get the transport type for the IMS service registration state.
4010 */
4011 @Override
4012 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004013 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004014 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004015 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4016 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4017 "IMS not available on device.");
4018 }
4019 final long token = Binder.clearCallingIdentity();
4020 try {
4021 Phone phone = getPhone(subId);
4022 if (phone == null) {
4023 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4024 + subId + "'");
4025 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4026 }
4027 phone.getImsRegistrationTech(regTech -> {
4028 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4029 int regTechConverted = (regTech == null)
4030 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4031 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4032 regTechConverted);
4033 try {
4034 consumer.accept(regTechConverted);
4035 } catch (RemoteException e) {
4036 // Ignore if the remote process is no longer available to call back.
4037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4038 }
4039 });
4040 } finally {
4041 Binder.restoreCallingIdentity(token);
4042 }
4043 }
4044
shilu366312e2019-12-17 09:28:10 -08004045 /**
4046 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4047 * @param subId The subscription to use to check the configuration.
4048 * @param c The callback that will be used to send the result.
4049 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004051 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4052 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004053 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004054 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004055 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4056 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4057 "IMS not available on device.");
4058 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 final long token = Binder.clearCallingIdentity();
4060 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004061 int slotId = getSlotIndexOrException(subId);
4062 verifyImsMmTelConfiguredOrThrow(slotId);
4063 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004064 } catch (ImsException e) {
4065 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 } finally {
4067 Binder.restoreCallingIdentity(token);
4068 }
4069 }
4070
shilu366312e2019-12-17 09:28:10 -08004071 /**
4072 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4073 * @param subId The subscription to use to check the configuration.
4074 * @param c The callback that will be used to send the result.
4075 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004077 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004078 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004079 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004080 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4081 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4082 }
Meng Wangafbc5852019-09-19 17:37:13 -07004083
4084 final long token = Binder.clearCallingIdentity();
4085 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004086 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004087 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004088 } catch (ImsException e) {
4089 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4090 + "is inactive, ignoring unregister.");
4091 // If the subscription is no longer active, just return, since the callback
4092 // will already have been removed internally.
4093 } finally {
4094 Binder.restoreCallingIdentity(token);
4095 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 }
4097
4098 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004099 public boolean isCapable(int subId, int capability, int regTech) {
4100 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 final long token = Binder.clearCallingIdentity();
4102 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004103 int slotId = getSlotIndexOrException(subId);
4104 verifyImsMmTelConfiguredOrThrow(slotId);
4105 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004106 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4108 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004109 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004110 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4111 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 } finally {
4113 Binder.restoreCallingIdentity(token);
4114 }
4115 }
4116
4117 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004118 public boolean isAvailable(int subId, int capability, int regTech) {
4119 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004120 final long token = Binder.clearCallingIdentity();
4121 try {
4122 Phone phone = getPhone(subId);
4123 if (phone == null) return false;
4124 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004125 } catch (com.android.ims.ImsException e) {
4126 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4127 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 } finally {
4129 Binder.restoreCallingIdentity(token);
4130 }
4131 }
4132
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004133 /**
4134 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4135 * subscription.
4136 * @param subId The subscription to use to check the configuration.
4137 * @param callback The callback that will be used to send the result.
4138 * @param capability The MmTelFeature capability that will be used to send the result.
4139 * @param transportType The transport type of the MmTelFeature capability.
4140 */
4141 @Override
4142 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4143 int transportType) {
4144 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4145 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4146 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4147 "IMS not available on device.");
4148 }
4149 final long token = Binder.clearCallingIdentity();
4150 try {
4151 int slotId = getSlotIndex(subId);
4152 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4153 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4154 + subId + "'");
4155 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4156 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004157 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004158 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4159 transportType, aBoolean -> {
4160 try {
4161 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4162 } catch (RemoteException e) {
4163 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4164 + "running. Ignore");
4165 }
4166 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004167 } catch (ImsException e) {
4168 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004169 } finally {
4170 Binder.restoreCallingIdentity(token);
4171 }
4172 }
4173
shilu366312e2019-12-17 09:28:10 -08004174 /**
4175 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4176 * @param subId The subscription to use to check the configuration.
4177 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004178 @Override
4179 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004180 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004181 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004182
Brad Ebinger35c841c2018-10-01 10:40:55 -07004183 final long token = Binder.clearCallingIdentity();
4184 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004185 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004186 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004187 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004188 } catch (ImsException e) {
4189 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 } finally {
4191 Binder.restoreCallingIdentity(token);
4192 }
4193 }
4194
4195 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004196 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004198 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 final long identity = Binder.clearCallingIdentity();
4200 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004201 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004202 // This setting doesn't require an active ImsService connection, so do not verify. The
4203 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004204 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004205 } catch (ImsException e) {
4206 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
4210 }
4211
shilu366312e2019-12-17 09:28:10 -08004212 /**
4213 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4214 * @param subId The subscription to use to check the configuration.
4215 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004217 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004218 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004219 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 final long identity = Binder.clearCallingIdentity();
4221 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004222 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004223 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004224 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004225 } catch (ImsException e) {
4226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
4230 }
4231
4232 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004233 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004235 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 final long identity = Binder.clearCallingIdentity();
4237 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004238 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004239 // This setting doesn't require an active ImsService connection, so do not verify. The
4240 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004241 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004242 } catch (ImsException e) {
4243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
shilu366312e2019-12-17 09:28:10 -08004249 /**
4250 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4251 * @param subId The subscription to use to check the configuration.
4252 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 @Override
4254 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004255 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004256 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 final long identity = Binder.clearCallingIdentity();
4258 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004260 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004262 } catch (ImsException e) {
4263 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
4267 }
4268
4269 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004270 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004272 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 final long identity = Binder.clearCallingIdentity();
4274 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004275 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004276 // This setting doesn't require an active ImsService connection, so do not verify. The
4277 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004279 } catch (ImsException e) {
4280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
4284 }
4285
shilu366312e2019-12-17 09:28:10 -08004286 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004287 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4288 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4289 * @param subId The subscription to use to check the configuration.
4290 */
4291 @Override
4292 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004293 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004294 mApp, subId, "isCrossSimCallingEnabledByUser");
4295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004300 } catch (ImsException e) {
4301 throw new ServiceSpecificException(e.getCode());
4302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
4305 }
4306
4307 /**
4308 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4309 * Requires MODIFY_PHONE_STATE permission.
4310 * @param subId The subscription to use to check the configuration.
4311 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4312 * false otherwise
4313 */
4314 @Override
4315 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4317 "setCrossSimCallingEnabled");
4318 final long identity = Binder.clearCallingIdentity();
4319 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004320 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004321 // This setting doesn't require an active ImsService connection, so do not verify. The
4322 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004323 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004324 } catch (ImsException e) {
4325 throw new ServiceSpecificException(e.getCode());
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
4329 }
4330
4331 /**
shilu366312e2019-12-17 09:28:10 -08004332 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4333 * @param subId The subscription to use to check the configuration.
4334 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004336
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004338 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004339 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004340 final long identity = Binder.clearCallingIdentity();
4341 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004342 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004343 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004344 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004345 } catch (ImsException e) {
4346 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 } finally {
4348 Binder.restoreCallingIdentity(identity);
4349 }
4350 }
4351
4352 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004353 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004355 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 final long identity = Binder.clearCallingIdentity();
4357 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004359 // This setting doesn't require an active ImsService connection, so do not verify. The
4360 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004361 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004362 } catch (ImsException e) {
4363 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 } finally {
4365 Binder.restoreCallingIdentity(identity);
4366 }
4367 }
4368
4369 @Override
4370 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4372 "setVoWiFiNonPersistent");
4373 final long identity = Binder.clearCallingIdentity();
4374 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004375 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004376 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004377 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004378 } catch (ImsException e) {
4379 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
4383 }
4384
shilu366312e2019-12-17 09:28:10 -08004385 /**
4386 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4387 * @param subId The subscription to use to check the configuration.
4388 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004389 @Override
4390 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004391 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004392 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 final long identity = Binder.clearCallingIdentity();
4394 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004396 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004397 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004398 } catch (ImsException e) {
4399 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004400 } finally {
4401 Binder.restoreCallingIdentity(identity);
4402 }
4403 }
4404
4405 @Override
4406 public void setVoWiFiModeSetting(int subId, int mode) {
4407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4408 "setVoWiFiModeSetting");
4409 final long identity = Binder.clearCallingIdentity();
4410 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004411 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004412 // This setting doesn't require an active ImsService connection, so do not verify. The
4413 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004415 } catch (ImsException e) {
4416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
4420 }
4421
4422 @Override
4423 public int getVoWiFiRoamingModeSetting(int subId) {
4424 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4425 final long identity = Binder.clearCallingIdentity();
4426 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004427 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004428 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004429 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*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 void setVoWiFiRoamingModeSetting(int subId, int mode) {
4439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4440 "setVoWiFiRoamingModeSetting");
4441 final long identity = Binder.clearCallingIdentity();
4442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004444 // This setting doesn't require an active ImsService connection, so do not verify. The
4445 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004446 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004447 } catch (ImsException e) {
4448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
4452 }
4453
4454 @Override
4455 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4457 "setRttCapabilityEnabled");
4458 final long identity = Binder.clearCallingIdentity();
4459 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004461 // This setting doesn't require an active ImsService connection, so do not verify. The
4462 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004463 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004464 } catch (ImsException e) {
4465 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
shilu366312e2019-12-17 09:28:10 -08004471 /**
4472 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4473 * @param subId The subscription to use to check the configuration.
4474 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 @Override
4476 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004478 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 final long identity = Binder.clearCallingIdentity();
4480 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004482 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004484 } catch (ImsException e) {
4485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
4489 }
4490
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004491 @Override
4492 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4493 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4494 final long identity = Binder.clearCallingIdentity();
4495 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004496 if (!isImsAvailableOnDevice()) {
4497 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4498 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004499 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 int slotId = getSlotIndexOrException(subId);
4501 verifyImsMmTelConfiguredOrThrow(slotId);
4502 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004503 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004504 } catch (ImsException e) {
4505 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
4509 }
4510
4511 @Override
4512 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4513 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4514 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004515 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4516 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4517 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004518 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004519 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004520 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004521 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004522 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4523 + "is inactive, ignoring unregister.");
4524 // If the subscription is no longer active, just return, since the callback will already
4525 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
4529 }
4530
allenwtsu99c623b2020-01-03 18:24:23 +08004531
4532 private void checkModifyPhoneStatePermission(int subId, String message) {
4533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4534 message);
4535 }
4536
4537 private boolean isImsProvisioningRequired(int subId, int capability,
4538 boolean isMmtelCapability) {
4539 Phone phone = getPhone(subId);
4540 if (phone == null) {
4541 loge("phone instance null for subid " + subId);
4542 return false;
4543 }
4544 if (isMmtelCapability) {
4545 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4546 return false;
4547 }
4548 } else {
4549 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4550 return false;
4551 }
4552 }
4553 return true;
4554 }
4555
4556 @Override
4557 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4558 boolean isProvisioned) {
4559 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4560
4561 final long identity = Binder.clearCallingIdentity();
4562 try {
4563 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4564 if (!isImsProvisioningRequired(subId, capability, false)) {
4565 return;
4566 }
4567
4568 // this capability requires provisioning, route to the correct API.
4569 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4570 switch (capability) {
4571 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4572 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4573 ims.setEabProvisioned(isProvisioned);
4574 break;
4575 default: {
4576 throw new IllegalArgumentException("Tried to set provisioning for "
4577 + "rcs capability '" + capability + "', which does not require "
4578 + "provisioning.");
4579 }
4580 }
4581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
4584
4585 }
4586
4587
4588 @Override
4589 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4590 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4594 if (!isImsProvisioningRequired(subId, capability, false)) {
4595 return true;
4596 }
4597
4598 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4599 switch (capability) {
4600 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4601 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4602 return ims.isEabProvisionedOnDevice();
4603
4604 default: {
4605 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4606 + "capability '" + capability + "', which does not require "
4607 + "provisioning.");
4608 }
4609 }
4610
4611 } finally {
4612 Binder.restoreCallingIdentity(identity);
4613 }
4614 }
4615
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004616 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004617 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4618 boolean isProvisioned) {
4619 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004620 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4621 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4622 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004623 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4624 }
allenwtsu99c623b2020-01-03 18:24:23 +08004625 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004626 final long identity = Binder.clearCallingIdentity();
4627 try {
4628 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004629 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004630 return;
4631 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004632 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4633 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4634 loge("setImsProvisioningStatusForCapability: called for technology that does "
4635 + "not support provisioning - " + tech);
4636 return;
4637 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004638
4639 // this capability requires provisioning, route to the correct API.
4640 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4641 switch (capability) {
4642 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4643 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4644 ims.setVolteProvisioned(isProvisioned);
4645 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4646 ims.setWfcProvisioned(isProvisioned);
4647 }
4648 break;
4649 }
4650 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4651 // There is currently no difference in VT provisioning type.
4652 ims.setVtProvisioned(isProvisioned);
4653 break;
4654 }
4655 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4656 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4657 // change the capability of the feature instead if needed.
4658 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4659 == isProvisioned) {
4660 // No change in provisioning.
4661 return;
4662 }
4663 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4664 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004665 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004666 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004667 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4668 + ", Exception" + e.getMessage());
4669 }
4670 break;
4671 }
4672 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004673 throw new IllegalArgumentException("Tried to set provisioning for "
4674 + "MmTel capability '" + capability + "', which does not require "
4675 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004676 }
4677 }
4678
4679 } finally {
4680 Binder.restoreCallingIdentity(identity);
4681 }
4682 }
4683
4684 @Override
4685 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4686 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004687 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4688 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4689 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4691 }
4692 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4693 final long identity = Binder.clearCallingIdentity();
4694 try {
4695 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004696 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004697 return true;
4698 }
4699
Brad Ebinger0d79c572021-04-17 15:20:49 -07004700 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4701 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4702 loge("getImsProvisioningStatusForCapability: called for technology that does "
4703 + "not support provisioning - " + tech);
4704 return true;
4705 }
4706
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004707 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4708 switch (capability) {
4709 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4710 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4711 return ims.isVolteProvisionedOnDevice();
4712 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4713 return ims.isWfcProvisionedOnDevice();
4714 }
4715 // This should never happen, since we are checking tech above to make sure it
4716 // is either LTE or IWLAN.
4717 throw new IllegalArgumentException("Invalid radio technology for voice "
4718 + "capability.");
4719 }
4720 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4721 // There is currently no difference in VT provisioning type.
4722 return ims.isVtProvisionedOnDevice();
4723 }
4724 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4725 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4726 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4727 }
4728 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004729 throw new IllegalArgumentException(
4730 "Tried to get provisioning for MmTel capability '" + capability
4731 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004732 }
4733 }
4734
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
4738 }
4739
4740 @Override
4741 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4742 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4743 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4744 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4745 }
4746 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4747 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4748 return (provisionedBits & capability) > 0;
4749 }
4750
4751 @Override
4752 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4753 boolean isProvisioned) {
4754 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4755 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4756 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4757 }
4758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4759 "setProvisioningStatusForCapability");
4760 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4761 // If the current provisioning status for capability already matches isProvisioned,
4762 // do nothing.
4763 if (((provisionedBits & capability) > 0) == isProvisioned) {
4764 return;
4765 }
4766 if (isProvisioned) {
4767 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4768 } else {
4769 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4770 }
4771 }
4772
4773 /**
4774 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4775 * technology. The bitfield should mirror the bitfield defined by
4776 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4777 */
4778 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4779 String key = getMmTelProvisioningKey(subId, tech);
4780 // Default is no capabilities are provisioned.
4781 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4782 }
4783
4784 /**
4785 * Sets the MmTel capability provisioning bitfield (defined by
4786 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4787 * technology specified.
4788 *
4789 * Note: This is a synchronous command and should not be called on UI thread.
4790 */
4791 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4792 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4793 String key = getMmTelProvisioningKey(subId, tech);
4794 editor.putInt(key, newField);
4795 editor.commit();
4796 }
4797
4798 private static String getMmTelProvisioningKey(int subId, int tech) {
4799 // resulting key is provision_ims_mmtel_{subId}_{tech}
4800 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4801 }
4802
4803 /**
4804 * Query CarrierConfig to see if the specified capability requires provisioning for the
4805 * carrier associated with the subscription id.
4806 */
4807 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4808 int capability) {
4809 CarrierConfigManager configManager = new CarrierConfigManager(context);
4810 PersistableBundle c = configManager.getConfigForSubId(subId);
4811 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004812 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004813 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4814 false);
4815 boolean requireVoiceVtProvisioning = c.getBoolean(
4816 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4817
4818 // First check to make sure that the capability requires provisioning.
4819 switch (capability) {
4820 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4821 // intentional fallthrough
4822 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4823 if (requireVoiceVtProvisioning) {
4824 // Voice and Video requires provisioning
4825 return true;
4826 }
4827 break;
4828 }
4829 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4830 if (requireUtProvisioning) {
4831 // UT requires provisioning
4832 return true;
4833 }
4834 break;
4835 }
4836 }
4837 return false;
4838 }
4839
allenwtsu99c623b2020-01-03 18:24:23 +08004840 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4841 int capability) {
4842 CarrierConfigManager configManager = new CarrierConfigManager(context);
4843 PersistableBundle c = configManager.getConfigForSubId(subId);
4844
4845 boolean requireRcsProvisioning = c.getBoolean(
4846 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4847
4848 // First check to make sure that the capability requires provisioning.
4849 switch (capability) {
4850 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4851 // intentional fallthrough
4852 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4853 if (requireRcsProvisioning) {
4854 // OPTION or PRESENCE requires provisioning
4855 return true;
4856 }
4857 break;
4858 }
4859 }
4860 return false;
4861 }
4862
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004863 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004864 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004865 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4866 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4867 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004868 enforceReadPrivilegedPermission("getImsProvisioningInt");
4869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004872 int slotId = getSlotIndex(subId);
4873 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4874 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4875 + subId + "' for key:" + key);
4876 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4877 }
calvinpanb5a34062021-02-08 19:59:36 +08004878 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004879 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004880 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4881 + subId + "' for key:" + key);
4882 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
4886 }
4887
4888 @Override
4889 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4891 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4892 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004893 enforceReadPrivilegedPermission("getImsProvisioningString");
4894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 int slotId = getSlotIndex(subId);
4898 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4899 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4900 + subId + "' for key:" + key);
4901 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4902 }
calvinpanb5a34062021-02-08 19:59:36 +08004903 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004904 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004905 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4906 + subId + "' for key:" + key);
4907 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004908 } finally {
4909 Binder.restoreCallingIdentity(identity);
4910 }
4911 }
4912
4913 @Override
4914 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004915 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4916 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4917 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4919 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 final long identity = Binder.clearCallingIdentity();
4921 try {
4922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004923 int slotId = getSlotIndex(subId);
4924 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4925 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4926 + subId + "' for key:" + key);
4927 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4928 }
calvinpanb5a34062021-02-08 19:59:36 +08004929 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4930 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004932 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004933 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
4937 }
4938
4939 @Override
4940 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004941 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4942 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4943 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4945 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004946 final long identity = Binder.clearCallingIdentity();
4947 try {
4948 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004949 int slotId = getSlotIndex(subId);
4950 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4951 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4952 + subId + "' for key:" + key);
4953 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4954 }
calvinpanb5a34062021-02-08 19:59:36 +08004955 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4956 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004958 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004960 } finally {
4961 Binder.restoreCallingIdentity(identity);
4962 }
4963 }
4964
Brad Ebinger919631e2021-06-02 17:46:35 -07004965 /**
4966 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4967 * for the given slot ID or no ImsResolver instance has been created.
4968 * @param slotId The slot ID that the IMS service is created for.
4969 * @throws ImsException If there is no ImsService configured for this slot.
4970 */
4971 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4972 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4973 ImsFeature.FEATURE_MMTEL)) {
4974 throw new ImsException("This subscription does not support MMTEL over IMS",
4975 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4976 }
4977 }
4978
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004979 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004980 int slotId = SubscriptionManager.getSlotIndex(subId);
4981 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004982 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4983 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004984 }
4985 return slotId;
4986 }
4987
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004988 private int getSlotIndex(int subId) {
4989 int slotId = SubscriptionManager.getSlotIndex(subId);
4990 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4991 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4992 }
4993 return slotId;
4994 }
4995
Wink Saville36469e72014-06-11 15:17:00 -07004996 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004997 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004998 */
4999 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005000 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5001 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08005002 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005003 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005004 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005005 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005006 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005007 mApp, subId, callingPackage, callingFeatureId,
5008 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005009 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5010 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 final long identity = Binder.clearCallingIdentity();
5013 try {
5014 final Phone phone = getPhone(subId);
5015 if (phone != null) {
5016 return phone.getServiceState().getDataNetworkType();
5017 } else {
5018 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5019 }
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005023 }
5024
5025 /**
5026 * Returns the data network type
5027 */
5028 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005029 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005030 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5031 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005032 }
5033
5034 /**
5035 * Returns the data network type for a subId
5036 */
5037 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005038 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5039 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005040 String functionName = "getDataNetworkTypeForSubscriber";
5041 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5042 mApp, functionName)) {
5043 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5044 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5045 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5046 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005047 }
5048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 final long identity = Binder.clearCallingIdentity();
5050 try {
5051 final Phone phone = getPhone(subId);
5052 if (phone != null) {
5053 return phone.getServiceState().getDataNetworkType();
5054 } else {
5055 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5056 }
5057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005060 }
5061
5062 /**
Wink Saville36469e72014-06-11 15:17:00 -07005063 * Returns the Voice network type for a subId
5064 */
5065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005066 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5067 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005068 String functionName = "getVoiceNetworkTypeForSubscriber";
5069 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5070 mApp, functionName)) {
5071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5072 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5073 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5074 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005075 }
5076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 final Phone phone = getPhone(subId);
5080 if (phone != null) {
5081 return phone.getServiceState().getVoiceNetworkType();
5082 } else {
5083 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5084 }
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005088 }
5089
5090 /**
5091 * @return true if a ICC card is present
5092 */
5093 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005094 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005095 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5096 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005097 }
5098
5099 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005100 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005101 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005102 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005103 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 final Phone phone = PhoneFactory.getPhone(slotIndex);
5107 if (phone != null) {
5108 return phone.getIccCard().hasIccCard();
5109 } else {
5110 return false;
5111 }
5112 } finally {
5113 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005115 }
5116
5117 /**
5118 * Return if the current radio is LTE on CDMA. This
5119 * is a tri-state return value as for a period of time
5120 * the mode may be unknown.
5121 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005122 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005123 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005124 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005125 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005126 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005127 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5128 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5129 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005130 }
5131
Sanket Padawe356d7632015-06-22 14:03:32 -07005132 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005133 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5134 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005135 try {
5136 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5137 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005138 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5139 }
5140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141 final long identity = Binder.clearCallingIdentity();
5142 try {
5143 final Phone phone = getPhone(subId);
5144 if (phone == null) {
5145 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5146 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005147 return TelephonyProperties.lte_on_cdma_device()
5148 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 }
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005152 }
Wink Saville36469e72014-06-11 15:17:00 -07005153 }
5154
Wink Saville36469e72014-06-11 15:17:00 -07005155 /**
5156 * {@hide}
5157 * Returns Default subId, 0 in the case of single standby.
5158 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005159 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005160 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005161 }
5162
Shishir Agrawala9f32182016-04-12 12:00:16 -07005163 private int getSlotForDefaultSubscription() {
5164 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5165 }
5166
Wink Savilleb564aae2014-10-23 10:18:09 -07005167 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005168 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005169 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005170
Pengquan Menge92a50d2018-09-21 15:54:48 -07005171 private boolean isActiveSubscription(int subId) {
5172 return mSubscriptionController.isActiveSubId(subId);
5173 }
5174
Ihab Awadf2177b72013-11-25 13:33:23 -08005175 /**
5176 * @see android.telephony.TelephonyManager.WifiCallingChoices
5177 */
5178 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 final long identity = Binder.clearCallingIdentity();
5180 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005181 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5183 getWhenToMakeWifiCallsDefaultPreference());
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005187 }
5188
5189 /**
5190 * @see android.telephony.TelephonyManager.WifiCallingChoices
5191 */
5192 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 final long identity = Binder.clearCallingIdentity();
5194 try {
5195 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005196 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005201 }
5202
Sailesh Nepald1e68152013-12-12 19:08:02 -08005203 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005204 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005205 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005206 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005207
Jordan Liu4c733742019-02-28 12:03:40 -08005208 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5209 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5210 if (phoneId == -1) {
5211 throw new IllegalArgumentException("Given slot index: " + slotIndex
5212 + " does not correspond to an active phone");
5213 }
5214 return PhoneFactory.getPhone(phoneId);
5215 }
5216
Shishir Agrawal566b7612013-10-28 14:41:00 -07005217 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005218 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5219 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5221 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005223 if (DBG) {
5224 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5225 }
5226 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5227 p2);
5228 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005229
Jordan Liu4c733742019-02-28 12:03:40 -08005230
5231 @Override
5232 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5233 int slotIndex, String callingPackage, String aid, int p2) {
5234 enforceModifyPermission();
5235 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5236 if (DBG) {
5237 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5238 }
5239 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5240 callingPackage, aid, p2);
5241 }
5242
5243 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5244 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 if (TextUtils.equals(ISDR_AID, aid)) {
5248 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005249 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5250 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 if (bestComponent == null
5252 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5253 loge("The calling package is not allowed to access ISD-R.");
5254 throw new SecurityException(
5255 "The calling package is not allowed to access ISD-R.");
5256 }
Derek Tan740e1672017-06-27 14:56:27 -07005257 }
Derek Tan740e1672017-06-27 14:56:27 -07005258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005260 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5261 null /* workSource */);
5262 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 return response;
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
5266 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005267 }
5268
5269 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005270 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5272 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005273 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5274 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5275 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005276
Jordan Liu4c733742019-02-28 12:03:40 -08005277 @Override
5278 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5279 enforceModifyPermission();
5280 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5281 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5282 channel);
5283 }
5284
5285 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 if (channel < 0) {
5289 return false;
5290 }
Jordan Liu4c733742019-02-28 12:03:40 -08005291 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5292 null /* workSource */);
5293 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 return success;
5295 } finally {
5296 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005297 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005298 }
5299
5300 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005301 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005302 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5304 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005305 if (DBG) {
5306 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5307 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5308 + p3 + " data=" + data);
5309 }
5310 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5311 command, p1, p2, p3, data);
5312 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005313
Jordan Liu4c733742019-02-28 12:03:40 -08005314 @Override
5315 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5316 int command, int p1, int p2, int p3, String data) {
5317 enforceModifyPermission();
5318 if (DBG) {
5319 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5320 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5321 + p3 + " data=" + data);
5322 }
5323 return iccTransmitApduLogicalChannelWithPermission(
5324 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5325 data);
5326 }
5327
5328 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5329 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 final long identity = Binder.clearCallingIdentity();
5331 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005332 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 return "";
5334 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005337 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5338 null /* workSource */);
5339 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 // Append the returned status code to the end of the response payload.
5342 String s = Integer.toHexString(
5343 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5344 if (response.payload != null) {
5345 s = IccUtils.bytesToHexString(response.payload) + s;
5346 }
5347 return s;
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005350 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005351 }
Jake Hambye994d462014-02-03 13:10:13 -08005352
Evan Charltonc66da362014-05-16 14:06:40 -07005353 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005354 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5355 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5357 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005359 if (DBG) {
5360 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5361 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5362 }
5363 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5364 cla, command, p1, p2, p3, data);
5365 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005366
Jordan Liu4c733742019-02-28 12:03:40 -08005367 @Override
5368 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5369 int command, int p1, int p2, int p3, String data) {
5370 enforceModifyPermission();
5371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5372 if (DBG) {
5373 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5374 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5375 + " data=" + data);
5376 }
5377
5378 return iccTransmitApduBasicChannelWithPermission(
5379 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5380 p2, p3, data);
5381 }
5382
5383 // open APDU basic channel assuming the caller has sufficient permissions
5384 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5385 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
5388 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5389 && TextUtils.equals(ISDR_AID, data)) {
5390 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005391 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5392 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 if (bestComponent == null
5394 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5395 loge("The calling package is not allowed to select ISD-R.");
5396 throw new SecurityException(
5397 "The calling package is not allowed to select ISD-R.");
5398 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005399 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005402 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5403 null /* workSource */);
5404 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 // Append the returned status code to the end of the response payload.
5407 String s = Integer.toHexString(
5408 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5409 if (response.payload != null) {
5410 s = IccUtils.bytesToHexString(response.payload) + s;
5411 }
5412 return s;
5413 } finally {
5414 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005415 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005416 }
5417
5418 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005419 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005420 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5422 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 if (DBG) {
5427 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5428 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5429 }
5430
5431 IccIoResult response =
5432 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5433 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5434 subId);
5435
5436 if (DBG) {
5437 log("Exchange SIM_IO [R]" + response);
5438 }
5439
5440 byte[] result = null;
5441 int length = 2;
5442 if (response.payload != null) {
5443 length = 2 + response.payload.length;
5444 result = new byte[length];
5445 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5446 } else {
5447 result = new byte[length];
5448 }
5449
5450 result[length - 1] = (byte) response.sw2;
5451 result[length - 2] = (byte) response.sw1;
5452 return result;
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005455 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005456 }
5457
Nathan Haroldb3014052017-01-25 15:57:32 -08005458 /**
5459 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5460 * on a particular subscription
5461 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005462 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5463 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005465 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005466 return null;
5467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468
5469 final long identity = Binder.clearCallingIdentity();
5470 try {
5471 if (appType != TelephonyManager.APPTYPE_USIM
5472 && appType != TelephonyManager.APPTYPE_SIM) {
5473 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5474 return null;
5475 }
5476 Object response = sendRequest(
5477 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5478 if (response instanceof String[]) {
5479 return (String[]) response;
5480 }
yincheng zhao2737e882019-09-06 17:06:54 -07005481 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005483 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 } finally {
5485 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005486 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005487 }
5488
yincheng zhao2737e882019-09-06 17:06:54 -07005489 /**
5490 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5491 * subscription.
5492 *
5493 * @param subId the id of the subscription.
5494 * @param appType the uicc app type, must be USIM or SIM.
5495 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5496 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005497 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005498 * @return number of fplmns that is successfully written to the SIM.
5499 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005500 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5501 String callingFeatureId) {
5502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5503 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005504 if (DBG) logv("no permissions for setForbiddenplmns");
5505 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5506 }
5507 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5508 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5509 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5510 }
5511 if (fplmns == null) {
5512 throw new IllegalArgumentException("Fplmn List provided is null");
5513 }
5514 for (String fplmn : fplmns) {
5515 if (!CellIdentity.isValidPlmn(fplmn)) {
5516 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5517 }
5518 }
5519 final long identity = Binder.clearCallingIdentity();
5520 try {
5521 Object response = sendRequest(
5522 CMD_SET_FORBIDDEN_PLMNS,
5523 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5524 subId);
5525 return (int) response;
5526 } finally {
5527 Binder.restoreCallingIdentity(identity);
5528 }
5529 }
5530
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005531 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005532 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5534 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5539 if (response.payload == null) {
5540 return "";
5541 }
Evan Charltonc66da362014-05-16 14:06:40 -07005542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 // Append the returned status code to the end of the response payload.
5544 String s = Integer.toHexString(
5545 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5546 s = IccUtils.bytesToHexString(response.payload) + s;
5547 return s;
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
Evan Charltonc66da362014-05-16 14:06:40 -07005551 }
5552
Jake Hambye994d462014-02-03 13:10:13 -08005553 /**
5554 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5555 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5556 *
5557 * @param itemID the ID of the item to read
5558 * @return the NV item as a String, or null on error.
5559 */
5560 @Override
5561 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005562 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5564 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565
5566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005569 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5571 return value;
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
Jake Hambye994d462014-02-03 13:10:13 -08005575 }
5576
5577 /**
5578 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5579 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5580 *
5581 * @param itemID the ID of the item to read
5582 * @param itemValue the value to write, as a String
5583 * @return true on success; false on any failure
5584 */
5585 @Override
5586 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005587 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5589 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5594 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005595 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5597 return success;
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
Jake Hambye994d462014-02-03 13:10:13 -08005601 }
5602
5603 /**
5604 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5605 * Used for device configuration by some CDMA operators.
5606 *
5607 * @param preferredRoamingList byte array containing the new PRL
5608 * @return true on success; false on any failure
5609 */
5610 @Override
5611 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5613 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614
5615 final long identity = Binder.clearCallingIdentity();
5616 try {
5617 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5618 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5619 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5620 return success;
5621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
Jake Hambye994d462014-02-03 13:10:13 -08005624 }
5625
5626 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005627 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005628 * Used for device configuration by some CDMA operators.
5629 *
chen xu6dac5ab2018-10-26 17:39:23 -07005630 * @param slotIndex - device slot.
5631 *
Jake Hambye994d462014-02-03 13:10:13 -08005632 * @return true on success; false on any failure
5633 */
5634 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005635 public boolean resetModemConfig(int slotIndex) {
5636 Phone phone = PhoneFactory.getPhone(slotIndex);
5637 if (phone != null) {
5638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5639 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640
chen xu6dac5ab2018-10-26 17:39:23 -07005641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5644 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5645 return success;
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 }
chen xu6dac5ab2018-10-26 17:39:23 -07005650 return false;
5651 }
5652
5653 /**
5654 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5655 *
5656 * @param slotIndex - device slot.
5657 *
5658 * @return true on success; false on any failure
5659 */
5660 @Override
5661 public boolean rebootModem(int slotIndex) {
5662 Phone phone = PhoneFactory.getPhone(slotIndex);
5663 if (phone != null) {
5664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5665 mApp, phone.getSubId(), "rebootModem");
5666
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5670 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5671 return success;
5672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
5675 }
5676 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005677 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005678
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005679 public String[] getPcscfAddress(String apnType, String callingPackage,
5680 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005681 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5683 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005684 return new String[0];
5685 }
5686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 final long identity = Binder.clearCallingIdentity();
5688 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005689 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 } finally {
5691 Binder.restoreCallingIdentity(identity);
5692 }
Wink Saville36469e72014-06-11 15:17:00 -07005693 }
5694
Brad Ebinger51f743a2017-01-23 13:50:20 -08005695 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005696 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5697 * {@link #disableIms(int)}.
5698 * @param slotIndex device slot.
5699 */
5700 public void resetIms(int slotIndex) {
5701 enforceModifyPermission();
5702
5703 final long identity = Binder.clearCallingIdentity();
5704 try {
5705 if (mImsResolver == null) {
5706 // may happen if the does not support IMS.
5707 return;
5708 }
5709 mImsResolver.disableIms(slotIndex);
5710 mImsResolver.enableIms(slotIndex);
5711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
5714 }
5715
5716 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005717 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5718 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005719 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005720 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005721 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722
5723 final long identity = Binder.clearCallingIdentity();
5724 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005725 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005726 // may happen if the device does not support IMS.
5727 return;
5728 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005729 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005733 }
5734
5735 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005736 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5737 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005738 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005739 public void disableIms(int slotId) {
5740 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005744 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005745 // may happen if the device does not support IMS.
5746 return;
5747 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005748 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005752 }
5753
5754 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005755 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5756 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005757 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005758 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005759 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761
5762 final long identity = Binder.clearCallingIdentity();
5763 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005764 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005765 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5766 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005767 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005768 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005772 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005773 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005774 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5775 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005776 @Override
5777 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005778 enforceModifyPermission();
5779
5780 final long identity = Binder.clearCallingIdentity();
5781 try {
5782 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005783 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005784 } finally {
5785 Binder.restoreCallingIdentity(identity);
5786 }
5787 }
5788
5789 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005790 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005791 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005792 */
5793 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5794 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795
5796 final long identity = Binder.clearCallingIdentity();
5797 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005798 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005799 // may happen if the device does not support IMS.
5800 return null;
5801 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005802 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803 } finally {
5804 Binder.restoreCallingIdentity(identity);
5805 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005806 }
5807
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005808 /**
5809 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005810 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005811 */
5812 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814
5815 final long identity = Binder.clearCallingIdentity();
5816 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005818 // may happen if the device does not support IMS.
5819 return null;
5820 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 } finally {
5823 Binder.restoreCallingIdentity(identity);
5824 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005825 }
5826
Brad Ebinger884c07b2018-02-15 16:17:40 -08005827 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005828 * Sets the ImsService Package Name that Telephony will bind to.
5829 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005830 * @param slotIndex the slot ID that the ImsService should bind for.
5831 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005832 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005833 * @param featureTypes An integer array of feature types associated with a packageName.
5834 * @param packageName The name of the package that the current configuration will be replaced
5835 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005836 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005837 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005838 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5839 int[] featureTypes, String packageName) {
5840 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5843 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005844 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 final long identity = Binder.clearCallingIdentity();
5847 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005848 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005849 // may happen if the device does not support IMS.
5850 return false;
5851 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 Map<Integer, String> featureConfig = new HashMap<>();
5853 for (int featureType : featureTypes) {
5854 featureConfig.put(featureType, packageName);
5855 }
5856 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5857 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005861 }
5862
5863 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005864 * Clears any carrier ImsService overrides for the slot index specified that were previously
5865 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5866 *
5867 * This should only be used for testing.
5868 *
5869 * @param slotIndex the slot ID that the ImsService should bind for.
5870 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5871 */
5872 @Override
5873 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5874 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5875 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5876 "clearCarrierImsServiceOverride");
5877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5878 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5879 "clearCarrierImsServiceOverride");
5880
5881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 if (mImsResolver == null) {
5884 // may happen if the device does not support IMS.
5885 return false;
5886 }
5887 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
5891 }
5892
5893 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005894 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005895 *
5896 * @param slotId The slot that the ImsService is associated with.
5897 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5898 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005900 * @return the package name of the ImsService configuration.
5901 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005902 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5903 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005904 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005905 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005906 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005907 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5908 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 final long identity = Binder.clearCallingIdentity();
5911 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005912 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005913 // may happen if the device does not support IMS.
5914 return "";
5915 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005916 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005917 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5918 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 } finally {
5920 Binder.restoreCallingIdentity(identity);
5921 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005922 }
5923
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005924 /**
5925 * Get the MmTelFeature state associated with the requested subscription id.
5926 * @param subId The subscription that the MmTelFeature is associated with.
5927 * @param callback A callback with an integer containing the
5928 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5929 */
5930 @Override
5931 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5932 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5933 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5934 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5935 "IMS not available on device.");
5936 }
5937 final long token = Binder.clearCallingIdentity();
5938 try {
5939 int slotId = getSlotIndex(subId);
5940 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5941 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5942 + subId + "'");
5943 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5944 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005945 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005946 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5947 try {
5948 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5949 } catch (RemoteException e) {
5950 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5951 + "Ignore");
5952 }
5953 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005954 } catch (ImsException e) {
5955 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005956 } finally {
5957 Binder.restoreCallingIdentity(token);
5958 }
5959 }
5960
Daniel Brightbb5840b2021-01-12 15:48:18 -08005961 /**
5962 * Sets the ims registration state on all valid {@link Phone}s.
5963 */
5964 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005965 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966
5967 final long identity = Binder.clearCallingIdentity();
5968 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005969 // NOTE: Before S, this method only set the default phone.
5970 for (final Phone phone : PhoneFactory.getPhones()) {
5971 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5972 phone.setImsRegistrationState(registered);
5973 }
5974 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 } finally {
5976 Binder.restoreCallingIdentity(identity);
5977 }
Wink Saville36469e72014-06-11 15:17:00 -07005978 }
5979
5980 /**
Stuart Scott54788802015-03-30 13:18:01 -07005981 * Set the network selection mode to automatic.
5982 *
5983 */
5984 @Override
5985 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5987 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988
5989 final long identity = Binder.clearCallingIdentity();
5990 try {
shilufc958392020-01-20 11:36:01 -08005991 if (!isActiveSubscription(subId)) {
5992 return;
5993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005995 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5996 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
Stuart Scott54788802015-03-30 13:18:01 -07006000 }
6001
Jack Yud10cdd42020-09-28 20:28:01 -07006002 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006003 * Ask the radio to connect to the input network and change selection mode to manual.
6004 *
6005 * @param subId the id of the subscription.
6006 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6007 * the operator to attach to.
6008 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6009 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6010 * normal network selection next time.
6011 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006012 */
6013 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006014 public boolean setNetworkSelectionModeManual(
6015 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6017 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006018
6019 if (!isActiveSubscription(subId)) {
6020 return false;
6021 }
6022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 final long identity = Binder.clearCallingIdentity();
6024 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006025 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006027 if (DBG) {
6028 log("setNetworkSelectionModeManual: subId: " + subId
6029 + " operator: " + operatorInfo);
6030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6032 } finally {
6033 Binder.restoreCallingIdentity(identity);
6034 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006035 }
shilu84f6e8b2019-12-19 13:58:01 -08006036 /**
6037 * Get the manual network selection
6038 *
6039 * @param subId the id of the subscription.
6040 *
6041 * @return the previously saved user selected PLMN
6042 */
6043 @Override
6044 public String getManualNetworkSelectionPlmn(int subId) {
6045 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006046 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006047 mApp, subId, "getManualNetworkSelectionPlmn");
6048
6049 final long identity = Binder.clearCallingIdentity();
6050 try {
6051 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006052 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006053 }
6054
6055 final Phone phone = getPhone(subId);
6056 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006057 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006058 }
6059 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6060 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6061 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6062 } finally {
6063 Binder.restoreCallingIdentity(identity);
6064 }
6065 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006066
6067 /**
6068 * Scans for available networks.
6069 */
6070 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006071 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6072 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6074 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006075 LocationAccessPolicy.LocationPermissionResult locationResult =
6076 LocationAccessPolicy.checkLocationPermission(mApp,
6077 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6078 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006079 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006080 .setCallingPid(Binder.getCallingPid())
6081 .setCallingUid(Binder.getCallingUid())
6082 .setMethod("getCellNetworkScanResults")
6083 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006084 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6085 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006086 .build());
6087 switch (locationResult) {
6088 case DENIED_HARD:
6089 throw new SecurityException("Not allowed to access scan results -- location");
6090 case DENIED_SOFT:
6091 return null;
6092 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093
Pengquan Menga1bb6272018-09-06 09:59:22 -07006094 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 try {
6096 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006097 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006102 }
6103
6104 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006105 * Get the call forwarding info, given the call forwarding reason.
6106 */
6107 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006108 public void getCallForwarding(int subId, int callForwardingReason,
6109 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006110 enforceReadPrivilegedPermission("getCallForwarding");
6111 long identity = Binder.clearCallingIdentity();
6112 try {
6113 if (DBG) {
6114 log("getCallForwarding: subId " + subId
6115 + " callForwardingReason" + callForwardingReason);
6116 }
Hall Liu27d24262020-09-18 19:04:59 -07006117
6118 Phone phone = getPhone(subId);
6119 if (phone == null) {
6120 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006121 callback.onError(
6122 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006123 } catch (RemoteException e) {
6124 // ignore
6125 }
6126 return;
6127 }
6128
6129 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6130 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6131 @Override
6132 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6133 try {
6134 callback.onCallForwardingInfoAvailable(info);
6135 } catch (RemoteException e) {
6136 // ignore
6137 }
6138 }
6139
6140 @Override
6141 public void onError(int error) {
6142 try {
6143 callback.onError(error);
6144 } catch (RemoteException e) {
6145 // ignore
6146 }
6147 }
6148 });
6149 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006150 } finally {
6151 Binder.restoreCallingIdentity(identity);
6152 }
6153 }
6154
6155 /**
6156 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6157 * reason, the number to forward, and the timeout before the forwarding is attempted.
6158 */
6159 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006160 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6161 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006162 enforceModifyPermission();
6163 long identity = Binder.clearCallingIdentity();
6164 try {
6165 if (DBG) {
6166 log("setCallForwarding: subId " + subId
6167 + " callForwardingInfo" + callForwardingInfo);
6168 }
Hall Liu27d24262020-09-18 19:04:59 -07006169
6170 Phone phone = getPhone(subId);
6171 if (phone == null) {
6172 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006173 callback.accept(
6174 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006175 } catch (RemoteException e) {
6176 // ignore
6177 }
6178 return;
6179 }
6180
6181 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6182 FunctionalUtils.ignoreRemoteException(callback::accept));
6183
6184 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006185 } finally {
6186 Binder.restoreCallingIdentity(identity);
6187 }
6188 }
6189
6190 /**
Hall Liu27d24262020-09-18 19:04:59 -07006191 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006192 */
6193 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006194 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006195 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006196 long identity = Binder.clearCallingIdentity();
6197 try {
Hall Liu27d24262020-09-18 19:04:59 -07006198 Phone phone = getPhone(subId);
6199 if (phone == null) {
6200 try {
6201 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6202 } catch (RemoteException e) {
6203 // ignore
6204 }
6205 return;
6206 }
SongFerngWang0e767992021-03-31 22:08:45 +08006207 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6208 PersistableBundle c = configManager.getConfigForSubId(subId);
6209 boolean requireUssd = c.getBoolean(
6210 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006211
Shuo Qian4a594052020-01-23 11:59:30 -08006212 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006213 if (requireUssd) {
6214 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6215 getSubscriptionCarrierId(subId));
6216 String newUssdCommand = "";
6217 try {
6218 newUssdCommand = carrierXmlParser.getFeature(
6219 CarrierXmlParser.FEATURE_CALL_WAITING)
6220 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6221 } catch (NullPointerException e) {
6222 loge("Failed to generate USSD number" + e);
6223 }
6224 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6225 mMainThreadHandler, callback, carrierXmlParser,
6226 CarrierXmlParser.SsEntry.SSAction.QUERY);
6227 final String ussdCommand = newUssdCommand;
6228 Executors.newSingleThreadExecutor().execute(() -> {
6229 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6230 });
6231 } else {
6232 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6233 callback::accept);
6234 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6235 }
Shuo Qian4a594052020-01-23 11:59:30 -08006236 } finally {
6237 Binder.restoreCallingIdentity(identity);
6238 }
6239 }
6240
6241 /**
Hall Liu27d24262020-09-18 19:04:59 -07006242 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006243 */
6244 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006245 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006246 enforceModifyPermission();
6247 long identity = Binder.clearCallingIdentity();
6248 try {
Hall Liu27d24262020-09-18 19:04:59 -07006249 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6250
6251 Phone phone = getPhone(subId);
6252 if (phone == null) {
6253 try {
6254 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6255 } catch (RemoteException e) {
6256 // ignore
6257 }
6258 return;
6259 }
6260
SongFerngWang0e767992021-03-31 22:08:45 +08006261 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6262 PersistableBundle c = configManager.getConfigForSubId(subId);
6263 boolean requireUssd = c.getBoolean(
6264 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006265
SongFerngWang0e767992021-03-31 22:08:45 +08006266 if (DBG) log("getCallWaitingStatus: subId " + subId);
6267 if (requireUssd) {
6268 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6269 getSubscriptionCarrierId(subId));
6270 CarrierXmlParser.SsEntry.SSAction ssAction =
6271 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6272 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6273 String newUssdCommand = "";
6274 try {
6275 newUssdCommand = carrierXmlParser.getFeature(
6276 CarrierXmlParser.FEATURE_CALL_WAITING)
6277 .makeCommand(ssAction, null);
6278 } catch (NullPointerException e) {
6279 loge("Failed to generate USSD number" + e);
6280 }
6281 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6282 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6283 final String ussdCommand = newUssdCommand;
6284 Executors.newSingleThreadExecutor().execute(() -> {
6285 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6286 });
6287 } else {
6288 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6289 FunctionalUtils.ignoreRemoteException(callback::accept));
6290
6291 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6292 }
Shuo Qian4a594052020-01-23 11:59:30 -08006293 } finally {
6294 Binder.restoreCallingIdentity(identity);
6295 }
6296 }
6297
6298 /**
yinxub1bed742017-04-17 11:45:04 -07006299 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006300 *
yinxub1bed742017-04-17 11:45:04 -07006301 * @param subId id of the subscription
6302 * @param request contains the radio access networks with bands/channels to scan
6303 * @param messenger callback messenger for scan results or errors
6304 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006305 * @return the id of the requested scan which can be used to stop the scan.
6306 */
6307 @Override
6308 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006309 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6311 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006312 LocationAccessPolicy.LocationPermissionResult locationResult =
6313 LocationAccessPolicy.checkLocationPermission(mApp,
6314 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6315 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006316 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006317 .setCallingPid(Binder.getCallingPid())
6318 .setCallingUid(Binder.getCallingUid())
6319 .setMethod("requestNetworkScan")
6320 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006321 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6322 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006323 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006324 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006325 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6326 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006327 if (e != null) {
6328 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6329 throw e;
6330 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006331 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006332 return TelephonyScanManager.INVALID_SCAN_ID;
6333 }
6334 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 }
Hall Liu912dfd32019-04-25 14:02:26 -07006336 int callingUid = Binder.getCallingUid();
6337 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006338 final long identity = Binder.clearCallingIdentity();
6339 try {
6340 return mNetworkScanRequestTracker.startNetworkScan(
6341 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006342 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006343 } finally {
6344 Binder.restoreCallingIdentity(identity);
6345 }
yinxu504e1392017-04-12 16:03:22 -07006346 }
6347
Hall Liub2ac8ef2019-02-28 15:56:23 -08006348 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006349 NetworkScanRequest request, int subId, String callingPackage) {
6350 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006351 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6352 boolean hasNetworkScanPermission =
6353 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6354 == PERMISSION_GRANTED;
6355
6356 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6357 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6358 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006359 }
6360
6361 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6362 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006363 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6364 return new SecurityException("Specific channels must not be"
6365 + " scanned without location access.");
6366 }
6367 }
6368 }
6369
Hall Liub2ac8ef2019-02-28 15:56:23 -08006370 return null;
6371 }
6372
yinxu504e1392017-04-12 16:03:22 -07006373 /**
6374 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006375 *
6376 * @param subId id of the subscription
6377 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006378 */
6379 @Override
6380 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6382 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383
Hall Liu912dfd32019-04-25 14:02:26 -07006384 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 final long identity = Binder.clearCallingIdentity();
6386 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006387 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
yinxu504e1392017-04-12 16:03:22 -07006391 }
6392
6393 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006394 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006395 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006396 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006397 */
6398 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006399 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006400 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006401 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006402 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403
6404 final long identity = Binder.clearCallingIdentity();
6405 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006406 if (DBG) log("getAllowedNetworkTypesBitmask");
6407 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6408 int networkTypesBitmask = (result != null ? result[0] : -1);
6409 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6410 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006414 }
6415
6416 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006417 * Get the allowed network types for certain reason.
6418 *
6419 * @param subId the id of the subscription.
6420 * @param reason the reason the allowed network type change is taking place
6421 * @return the allowed network types.
6422 */
6423 @Override
6424 public long getAllowedNetworkTypesForReason(int subId,
6425 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006426 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006427 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006428 final long identity = Binder.clearCallingIdentity();
6429 try {
6430 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
6434 }
6435
6436 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006437 * Enable/Disable E-UTRA-NR Dual Connectivity
6438 * @param subId subscription id of the sim card
6439 * @param nrDualConnectivityState expected NR dual connectivity state
6440 * This can be passed following states
6441 * <ol>
6442 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6443 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6444 * <li>Disable NR dual connectivity and force secondary cell to be released
6445 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6446 * </ol>
6447 * @return operation result.
6448 */
6449 @Override
6450 public int setNrDualConnectivityState(int subId,
6451 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6453 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006454 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006455 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6456 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6457 }
6458
Sooraj Sasindran37444802020-08-11 10:40:43 -07006459 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6463 nrDualConnectivityState, subId,
6464 workSource);
6465 if (DBG) log("enableNRDualConnectivity result: " + result);
6466 return result;
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
6470 }
6471
6472 /**
6473 * Is E-UTRA-NR Dual Connectivity enabled
6474 * @return true if dual connectivity is enabled else false
6475 */
6476 @Override
6477 public boolean isNrDualConnectivityEnabled(int subId) {
6478 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006479 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006480 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006481 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006482 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6483 return false;
6484 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6486 final long identity = Binder.clearCallingIdentity();
6487 try {
6488 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6489 null, subId, workSource);
6490 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6491 return isEnabled;
6492 } finally {
6493 Binder.restoreCallingIdentity(identity);
6494 }
6495 }
6496
6497 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006498 * Set the allowed network types of the device and
6499 * provide the reason triggering the allowed network change.
6500 *
6501 * @param subId the id of the subscription.
6502 * @param reason the reason the allowed network type change is taking place
6503 * @param allowedNetworkTypes the allowed network types.
6504 * @return true on success; false on any failure.
6505 */
6506 @Override
6507 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006508 @TelephonyManager.AllowedNetworkTypesReason int reason,
6509 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6511 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006512 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006513 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6514 return false;
6515 }
6516 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6517 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006518 return false;
6519 }
6520
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006521 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6522 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6523
6524
6525 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6526 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6527 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006528 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006529
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006530 final long identity = Binder.clearCallingIdentity();
6531 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006532 Boolean success = (Boolean) sendRequest(
6533 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6534 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6535
6536 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6537 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
6541 }
6542
6543 /**
Miaoa84611c2019-03-15 09:21:10 +08006544 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006545 *
Miaoa84611c2019-03-15 09:21:10 +08006546 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006547 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006548 * @hide
6549 */
6550 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006551 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006554 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 try {
Miaoa84611c2019-03-15 09:21:10 +08006556 if (phone != null) {
6557 return phone.hasMatchedTetherApnSetting();
6558 } else {
6559 return false;
6560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 } finally {
6562 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006563 }
Junda Liu475951f2014-11-07 16:45:03 -08006564 }
6565
6566 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006567 * Get the user enabled state of Mobile Data.
6568 *
6569 * TODO: remove and use isUserDataEnabled.
6570 * This can't be removed now because some vendor codes
6571 * calls through ITelephony directly while they should
6572 * use TelephonyManager.
6573 *
6574 * @return true on enabled
6575 */
6576 @Override
6577 public boolean getDataEnabled(int subId) {
6578 return isUserDataEnabled(subId);
6579 }
6580
6581 /**
6582 * Get whether mobile data is enabled per user setting.
6583 *
6584 * There are other factors deciding whether mobile data is actually enabled, but they are
6585 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006586 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006587 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6588 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006589 *
6590 * @return {@code true} if data is enabled else {@code false}
6591 */
6592 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006593 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006594 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006595 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006596 try {
6597 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6598 functionName);
6599 } catch (Exception e) {
6600 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6601 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006602 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006604 mApp, subId, functionName);
6605
Robert Greenwalt646120a2014-05-23 11:54:03 -07006606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607
6608 final long identity = Binder.clearCallingIdentity();
6609 try {
6610 int phoneId = mSubscriptionController.getPhoneId(subId);
6611 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6612 Phone phone = PhoneFactory.getPhone(phoneId);
6613 if (phone != null) {
6614 boolean retVal = phone.isUserDataEnabled();
6615 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6616 return retVal;
6617 } else {
6618 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6619 return false;
6620 }
6621 } finally {
6622 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006623 }
6624 }
6625
6626 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006627 * Checks if the device is capable of mobile data by considering whether whether the
6628 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6629 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006630 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006631 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006632 */
6633 @Override
6634 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006635 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006636 try {
6637 try {
6638 mApp.enforceCallingOrSelfPermission(
6639 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006640 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006641 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006642 try {
6643 mApp.enforceCallingOrSelfPermission(
6644 android.Manifest.permission.READ_PHONE_STATE,
6645 functionName);
6646 } catch (Exception e2) {
6647 mApp.enforceCallingOrSelfPermission(
6648 permission.READ_BASIC_PHONE_STATE, functionName);
6649 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006650 }
6651 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006652 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654
6655 final long identity = Binder.clearCallingIdentity();
6656 try {
6657 int phoneId = mSubscriptionController.getPhoneId(subId);
6658 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6659 Phone phone = PhoneFactory.getPhone(phoneId);
6660 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006661 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6663 return retVal;
6664 } else {
6665 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6666 return false;
6667 }
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006670 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006671 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006672
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006673 /**
6674 * Check if data is enabled for a specific reason
6675 * @param subId Subscription index
6676 * @param reason the reason the data enable change is taking place
6677 * @return {@code true} if the overall data is enabled; {@code false} if not.
6678 */
6679 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006680 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006681 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006682 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006683 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006684 try {
6685 mApp.enforceCallingOrSelfPermission(
6686 android.Manifest.permission.ACCESS_NETWORK_STATE,
6687 functionName);
6688 } catch (Exception e) {
6689 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6690 functionName);
6691 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006692 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006693 try {
6694 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006695 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006696 } catch (Exception e2) {
6697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006698 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006699 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006700 }
6701
6702
6703 final long identity = Binder.clearCallingIdentity();
6704 try {
6705 int phoneId = mSubscriptionController.getPhoneId(subId);
6706 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006707 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006708 + " reason=" + reason);
6709 }
6710 Phone phone = PhoneFactory.getPhone(phoneId);
6711 if (phone != null) {
6712 boolean retVal;
6713 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6714 retVal = phone.isUserDataEnabled();
6715 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006716 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006717 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006718 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006719 return retVal;
6720 } else {
6721 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006722 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006723 + subId + " retVal=false");
6724 }
6725 return false;
6726 }
6727 } finally {
6728 Binder.restoreCallingIdentity(identity);
6729 }
6730 }
6731
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006732 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006733 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006734 if (uid == Process.PHONE_UID) {
6735 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6736 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006737 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6738 }
6739
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006740 //load access rules from carrier configs, and check those as well: b/139133814
6741 SubscriptionController subController = SubscriptionController.getInstance();
6742 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6743 || subController == null) return privilegeFromSim;
6744
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006745 PackageManager pkgMgr = phone.getContext().getPackageManager();
6746 String[] packages = pkgMgr.getPackagesForUid(uid);
6747
6748 final long identity = Binder.clearCallingIdentity();
6749 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006750 int subId = phone.getSubId();
6751 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6752 // A test override is in place for the privileges for this subId, so don't try to
6753 // read the subscription privileges.
6754 return privilegeFromSim;
6755 }
6756 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006757 SubscriptionManager subManager = (SubscriptionManager)
6758 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6759 for (String pkg : packages) {
6760 if (subManager.canManageSubscription(subInfo, pkg)) {
6761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6762 }
6763 }
6764 return privilegeFromSim;
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
6768 }
6769
6770 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6771 String pkgName) {
6772 //load access rules from carrier configs, and check those as well: b/139133814
6773 SubscriptionController subController = SubscriptionController.getInstance();
6774 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6775 || subController == null) return privilegeFromSim;
6776
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 return subManager.canManageSubscription(subInfo, pkgName)
6789 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
6793 }
6794
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006795 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006796 public int getCarrierPrivilegeStatus(int subId) {
6797 final Phone phone = getPhone(subId);
6798 if (phone == null) {
6799 loge("getCarrierPrivilegeStatus: Invalid subId");
6800 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6801 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006802 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6803 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006804 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006805 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6806 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006807
6808 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006809 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006810 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006811 }
Junda Liu29340342014-07-10 15:23:27 -07006812
6813 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006814 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006815 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006816 final Phone phone = getPhone(subId);
6817 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006818 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006819 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6820 }
6821 UiccProfile profile =
6822 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6823 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006824 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006825 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6826 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006827 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006828 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006829 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006830 }
6831
6832 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006833 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006834 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006835 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006836 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006837 }
6838
6839 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006840 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6841 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006842 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006843 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6844 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006845 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006846 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006847 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006848 }
6849
6850 @Override
6851 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006852 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006853 if (TextUtils.isEmpty(pkgName))
6854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006855 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6856 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006857 UiccPort port = UiccController.getInstance().getUiccPort(i);
6858 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006859 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006860 continue;
6861 }
6862
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006863 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006864 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006865 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006866 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6867 break;
6868 }
6869 }
6870
6871 return result;
Junda Liu29340342014-07-10 15:23:27 -07006872 }
Derek Tan89e89d42014-07-08 17:00:10 -07006873
6874 @Override
Junda Liue64de782015-04-16 17:19:16 -07006875 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006876 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006877 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6878 loge("phoneId " + phoneId + " is not valid.");
6879 return null;
6880 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006881 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6882 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006883 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006884 return null ;
6885 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006886 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006887 }
6888
Amith Yamasani6e118872016-02-19 12:53:51 -08006889 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006890 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006891 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006892 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006893 List<String> privilegedPackages = new ArrayList<>();
6894 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006895 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006896 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006897 if (port != null) {
6898 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006899 if (packages == null) {
6900 // Only check packages in user 0 for now
6901 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006902 PackageManager.MATCH_DISABLED_COMPONENTS
6903 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006904 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006905 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006906 }
6907 for (int p = packages.size() - 1; p >= 0; p--) {
6908 PackageInfo pkgInfo = packages.get(p);
6909 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006910 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006911 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006912 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006913 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006914 privilegedPackages.add(pkgInfo.packageName);
6915 }
6916 }
6917 }
6918 }
6919 return privilegedPackages;
6920 }
6921
chen xuf7e9fe82019-05-09 19:31:02 -07006922 @Override
6923 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006924 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6925
6926 final long identity = Binder.clearCallingIdentity();
6927
chen xuf7e9fe82019-05-09 19:31:02 -07006928 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006929 try {
6930 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6931 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6932 }
6933 } finally {
6934 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006935 }
6936 return privilegedPackages;
6937 }
6938
Wink Savilleb564aae2014-10-23 10:18:09 -07006939 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006940 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006941 UiccPort port = phone == null ? null : phone.getUiccPort();
6942 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006943 return null;
6944 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006945 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006946 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006947 return null;
6948 }
6949 return iccId;
6950 }
6951
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006952 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006953 public void setCallComposerStatus(int subId, int status) {
6954 enforceModifyPermission();
6955
6956 final long identity = Binder.clearCallingIdentity();
6957 try {
6958 Phone phone = getPhone(subId);
6959 if (phone != null) {
6960 Phone defaultPhone = phone.getImsPhone();
6961 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6962 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6963 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006964 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6965 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006966 }
6967 }
Shuo Qian284ae752020-12-22 19:10:14 -08006968 } catch (ImsException e) {
6969 throw new ServiceSpecificException(e.getCode());
6970 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006971 Binder.restoreCallingIdentity(identity);
6972 }
6973 }
6974
6975 @Override
6976 public int getCallComposerStatus(int subId) {
6977 enforceReadPrivilegedPermission("getCallComposerStatus");
6978
6979 final long identity = Binder.clearCallingIdentity();
6980 try {
6981 Phone phone = getPhone(subId);
6982 if (phone != null) {
6983 Phone defaultPhone = phone.getImsPhone();
6984 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6985 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6986 return imsPhone.getCallComposerStatus();
6987 }
6988 }
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
6991 }
6992 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6993 }
6994
6995 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006996 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6997 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006998 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006999 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 final long identity = Binder.clearCallingIdentity();
7002 try {
7003 final String iccId = getIccId(subId);
7004 final Phone phone = getPhone(subId);
7005 if (phone == null) {
7006 return false;
7007 }
7008 final String subscriberId = phone.getSubscriberId();
7009
7010 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007011 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 + subscriberId + " to " + number);
7013 }
7014
7015 if (TextUtils.isEmpty(iccId)) {
7016 return false;
7017 }
7018
7019 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7020
7021 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7022 if (alphaTag == null) {
7023 editor.remove(alphaTagPrefKey);
7024 } else {
7025 editor.putString(alphaTagPrefKey, alphaTag);
7026 }
7027
7028 // Record both the line number and IMSI for this ICCID, since we need to
7029 // track all merged IMSIs based on line number
7030 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7031 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7032 if (number == null) {
7033 editor.remove(numberPrefKey);
7034 editor.remove(subscriberPrefKey);
7035 } else {
7036 editor.putString(numberPrefKey, number);
7037 editor.putString(subscriberPrefKey, subscriberId);
7038 }
7039
7040 editor.commit();
7041 return true;
7042 } finally {
7043 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007044 }
Derek Tan7226c842014-07-02 17:42:23 -07007045 }
7046
7047 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007048 public String getLine1NumberForDisplay(int subId, String callingPackage,
7049 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007050 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007052 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007053 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007054 return null;
7055 }
Derek Tan97ebb422014-09-05 16:55:38 -07007056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 final long identity = Binder.clearCallingIdentity();
7058 try {
7059 String iccId = getIccId(subId);
7060 if (iccId != null) {
7061 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7062 if (DBG_MERGE) {
7063 log("getLine1NumberForDisplay returning "
7064 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7065 }
7066 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7069 return null;
7070 } finally {
7071 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007072 }
Derek Tan7226c842014-07-02 17:42:23 -07007073 }
7074
7075 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007076 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7077 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007079 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007080 return null;
7081 }
Derek Tan97ebb422014-09-05 16:55:38 -07007082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 final long identity = Binder.clearCallingIdentity();
7084 try {
7085 String iccId = getIccId(subId);
7086 if (iccId != null) {
7087 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7088 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7089 }
7090 return null;
7091 } finally {
7092 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007093 }
Derek Tan7226c842014-07-02 17:42:23 -07007094 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007095
7096 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007097 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7098 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007099 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7100 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007102 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007103 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007104 return null;
7105 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007106
Jordan Liub49b04b2019-05-06 14:45:15 -07007107 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7108 // the process, where TelephonyManager was instantiated.
7109 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007110 final long identity = Binder.clearCallingIdentity();
7111 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007112 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113 final TelephonyManager tele = TelephonyManager.from(context);
7114 final SubscriptionManager sub = SubscriptionManager.from(context);
7115
7116 // Figure out what subscribers are currently active
7117 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118
Jordan Liub49b04b2019-05-06 14:45:15 -07007119 // Only consider subs which match the current subId
7120 // This logic can be simplified. See b/131189269 for progress.
7121 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007122 activeSubscriberIds.add(tele.getSubscriberId(subId));
7123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124
7125 // First pass, find a number override for an active subscriber
7126 String mergeNumber = null;
7127 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7128 for (String key : prefs.keySet()) {
7129 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7130 final String subscriberId = (String) prefs.get(key);
7131 if (activeSubscriberIds.contains(subscriberId)) {
7132 final String iccId = key.substring(
7133 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7134 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7135 mergeNumber = (String) prefs.get(numberKey);
7136 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007137 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 + " for active subscriber " + subscriberId);
7139 }
7140 if (!TextUtils.isEmpty(mergeNumber)) {
7141 break;
7142 }
7143 }
7144 }
7145 }
7146
7147 // Shortcut when no active merged subscribers
7148 if (TextUtils.isEmpty(mergeNumber)) {
7149 return null;
7150 }
7151
7152 // Second pass, find all subscribers under that line override
7153 final ArraySet<String> result = new ArraySet<>();
7154 for (String key : prefs.keySet()) {
7155 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7156 final String number = (String) prefs.get(key);
7157 if (mergeNumber.equals(number)) {
7158 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7159 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7160 final String subscriberId = (String) prefs.get(subscriberKey);
7161 if (!TextUtils.isEmpty(subscriberId)) {
7162 result.add(subscriberId);
7163 }
7164 }
7165 }
7166 }
7167
7168 final String[] resultArray = result.toArray(new String[result.size()]);
7169 Arrays.sort(resultArray);
7170 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007171 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7173 }
7174 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007175 } finally {
7176 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007177 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007178 }
7179
7180 @Override
zoey chen38003472019-12-13 17:16:31 +08007181 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7182 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007183
7184 final long identity = Binder.clearCallingIdentity();
7185 try {
7186 final TelephonyManager telephonyManager = mApp.getSystemService(
7187 TelephonyManager.class);
7188 String subscriberId = telephonyManager.getSubscriberId(subId);
7189 if (subscriberId == null) {
7190 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007191 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007192 + subId);
7193 }
7194 return null;
7195 }
7196
7197 final SubscriptionInfo info = SubscriptionController.getInstance()
7198 .getSubscriptionInfo(subId);
7199 final ParcelUuid groupUuid = info.getGroupUuid();
7200 // If it doesn't belong to any group, return just subscriberId of itself.
7201 if (groupUuid == null) {
7202 return new String[]{subscriberId};
7203 }
7204
7205 // Get all subscriberIds from the group.
7206 final List<String> mergedSubscriberIds = new ArrayList<>();
7207 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007208 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007209 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007210 for (SubscriptionInfo subInfo : groupInfos) {
7211 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7212 if (subscriberId != null) {
7213 mergedSubscriberIds.add(subscriberId);
7214 }
7215 }
7216
7217 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220
7221 }
7222 }
7223
7224 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007225 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007226 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007227 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228
7229 final long identity = Binder.clearCallingIdentity();
7230 try {
7231 final Phone phone = getPhone(subId);
7232 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007236 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007237
7238 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007239 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007240 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7241 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007242 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7243 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244
7245 final long identity = Binder.clearCallingIdentity();
7246 try {
7247 final Phone phone = getPhone(subId);
7248 if (phone == null) {
7249 return false;
7250 }
7251 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7252 cdmaNonRoamingList);
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007255 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007256 }
7257
7258 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007259 @Deprecated
7260 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7261 enforceModifyPermission();
7262
7263 int returnValue = 0;
7264 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007265 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007266 if(result.exception == null) {
7267 if (result.result != null) {
7268 byte[] responseData = (byte[])(result.result);
7269 if(responseData.length > oemResp.length) {
7270 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7271 responseData.length + "bytes. Buffer Size is " +
7272 oemResp.length + "bytes.");
7273 }
7274 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7275 returnValue = responseData.length;
7276 }
7277 } else {
7278 CommandException ex = (CommandException) result.exception;
7279 returnValue = ex.getCommandError().ordinal();
7280 if(returnValue > 0) returnValue *= -1;
7281 }
7282 } catch (RuntimeException e) {
7283 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7284 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7285 if(returnValue > 0) returnValue *= -1;
7286 }
7287
7288 return returnValue;
7289 }
7290
7291 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007292 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007293 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007294 try {
7295 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007296 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007297 mApp, phone.getSubId(), "getRadioAccessFamily");
7298 } catch (SecurityException e) {
7299 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7300 throw e;
7301 }
chen xub97461a2018-10-26 14:17:57 -07007302 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007303 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007304 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306 final long identity = Binder.clearCallingIdentity();
7307 try {
chen xub97461a2018-10-26 14:17:57 -07007308 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007309 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007310 mApp, phone.getSubId(), "getRadioAccessFamily");
7311 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 } finally {
7313 Binder.restoreCallingIdentity(identity);
7314 }
chen xub97461a2018-10-26 14:17:57 -07007315 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007316 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007317
7318 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007319 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007320 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007321 try {
7322 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7323 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007324 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007325 }
7326 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007327 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007328 }
7329 RoleManager rm = mApp.getSystemService(RoleManager.class);
7330 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7331 if (!dialerRoleHolders.contains(callingPackage)) {
7332 throw new SecurityException("App must be the dialer role holder to"
7333 + " upload a call composer pic");
7334 }
7335
7336 Executors.newSingleThreadExecutor().execute(() -> {
7337 ByteArrayOutputStream output = new ByteArrayOutputStream(
7338 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7339 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7340 boolean readUntilEnd = false;
7341 int totalBytesRead = 0;
7342 byte[] buffer = new byte[16 * 1024];
7343 while (true) {
7344 int numRead;
7345 try {
7346 numRead = input.read(buffer);
7347 } catch (IOException e) {
7348 try {
7349 fd.checkError();
7350 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7351 null);
7352 } catch (IOException e1) {
7353 // This means that the other side closed explicitly with an error. If this
7354 // happens, log and ignore.
7355 loge("Remote end of call composer picture pipe closed: " + e1);
7356 }
7357 break;
7358 }
7359 if (numRead == -1) {
7360 readUntilEnd = true;
7361 break;
7362 }
7363 totalBytesRead += numRead;
7364 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7365 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7366 try {
7367 input.close();
7368 } catch (IOException e) {
7369 // ignore
7370 }
7371 break;
7372 }
7373 output.write(buffer, 0, numRead);
7374 }
7375 // Generally, the remote end will close the file descriptors. The only case where we
7376 // close is above, where the picture size is too big.
7377
7378 try {
7379 fd.checkError();
7380 } catch (IOException e) {
7381 loge("Remote end for call composer closed with an error: " + e);
7382 return;
7383 }
7384
Hall Liuaa4211e2021-01-20 15:43:39 -08007385 if (!readUntilEnd) {
7386 loge("Did not finish reading entire image; aborting");
7387 return;
7388 }
Hall Liu82694d52020-12-11 18:22:04 -08007389
Hall Liuaa4211e2021-01-20 15:43:39 -08007390 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7391 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7392 new CallComposerPictureTransfer.Factory() {},
7393 imageData,
7394 (result) -> {
7395 if (result.first != null) {
7396 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7397 Bundle outputResult = new Bundle();
7398 outputResult.putParcelable(
7399 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7400 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7401 outputResult);
7402 } else {
7403 callback.send(result.second, null);
7404 }
7405 }
7406 );
Hall Liu82694d52020-12-11 18:22:04 -08007407 });
7408 }
7409
7410 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007411 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007412 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007413 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414
7415 final long identity = Binder.clearCallingIdentity();
7416 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007417 ImsManager.getInstance(defaultPhone.getContext(),
7418 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 } finally {
7420 Binder.restoreCallingIdentity(identity);
7421 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007422 }
7423
7424 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007425 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007426 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7428 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007429 return false;
7430 }
Svet Ganovb320e182015-04-16 12:30:10 -07007431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 final long identity = Binder.clearCallingIdentity();
7433 try {
7434 // Check the user preference and the system-level IMS setting. Even if the user has
7435 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7436 // In the long run, we may instead need to check if there exists a connection service
7437 // which can support video calling.
7438 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007439 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 return imsManager.isVtEnabledByPlatform()
7441 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7442 && imsManager.isVtEnabledByUser();
7443 } finally {
7444 Binder.restoreCallingIdentity(identity);
7445 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007446 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007447
Andrew Leea1239f22015-03-02 17:44:07 -08007448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007449 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7450 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007452 mApp, subId, callingPackage, callingFeatureId,
7453 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 return false;
7455 }
7456
7457 final long identity = Binder.clearCallingIdentity();
7458 try {
7459 CarrierConfigManager configManager =
7460 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007461 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7463 } finally {
7464 Binder.restoreCallingIdentity(identity);
7465 }
Andrew Leea1239f22015-03-02 17:44:07 -08007466 }
7467
7468 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007469 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007471 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 return false;
7473 }
7474
7475 final long identity = Binder.clearCallingIdentity();
7476 try {
7477 CarrierConfigManager configManager =
7478 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007479 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
7483 }
Andrew Leea1239f22015-03-02 17:44:07 -08007484 }
7485
Andrew Lee9431b832015-03-09 18:46:45 -07007486 @Override
7487 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007488 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007489 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007490 }
7491
7492 @Override
7493 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 final long identity = Binder.clearCallingIdentity();
7495 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007496 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 } finally {
7498 Binder.restoreCallingIdentity(identity);
7499 }
Andrew Lee9431b832015-03-09 18:46:45 -07007500 }
7501
Hall Liuf6668912018-10-31 17:05:23 -07007502 /**
7503 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7504 * support for the feature and device firmware support.
7505 *
7506 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7507 */
7508 @Override
7509 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007511 final Phone phone = getPhone(subscriptionId);
7512 if (phone == null) {
7513 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7514 return false;
7515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007517 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7519 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007520 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 return isCarrierSupported && isDeviceSupported;
7522 } finally {
7523 Binder.restoreCallingIdentity(identity);
7524 }
Hall Liu98187582018-01-22 19:15:32 -08007525 }
7526
Hall Liuf6668912018-10-31 17:05:23 -07007527 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007528 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7529 * RTT setting, will return true if the device and carrier both support RTT.
7530 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007531 */
7532 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 final long identity = Binder.clearCallingIdentity();
7534 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007535 boolean isRttSupported = isRttSupported(subscriptionId);
7536 boolean isUserRttSettingOn = Settings.Secure.getInt(
7537 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7538 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7539 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7540 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007544 }
7545
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007546 @Deprecated
7547 @Override
7548 public String getDeviceId(String callingPackage) {
7549 return getDeviceIdWithFeature(callingPackage, null);
7550 }
7551
Sanket Padawe7310cc72015-01-14 09:53:20 -08007552 /**
7553 * Returns the unique device ID of phone, for example, the IMEI for
7554 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7555 *
7556 * <p>Requires Permission:
7557 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7558 */
7559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007560 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007561 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007562 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007563 return null;
7564 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007565 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007566 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007567 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007568 return null;
7569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570
7571 final long identity = Binder.clearCallingIdentity();
7572 try {
7573 return phone.getDeviceId();
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
7576 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007577 }
7578
Ping Sunc67b7c22016-03-02 19:16:45 +08007579 /**
7580 * {@hide}
7581 * Returns the IMS Registration Status on a particular subid
7582 *
7583 * @param subId
7584 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007585 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007586 Phone phone = getPhone(subId);
7587 if (phone != null) {
7588 return phone.isImsRegistered();
7589 } else {
7590 return false;
7591 }
7592 }
7593
Santos Cordon7a1885b2015-02-03 11:15:19 -08007594 @Override
7595 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
7601 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007602 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007603
Tyler Gunnf70ed162019-04-03 15:28:53 -07007604 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007605 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007606 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007608 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007609 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7610 }
7611 final long identity = Binder.clearCallingIdentity();
7612 try {
7613 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7614 } finally {
7615 Binder.restoreCallingIdentity(identity);
7616 }
7617 }
7618
7619 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007620 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007621 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007622 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007623 mApp,
7624 subscriptionId,
7625 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 Phone phone = getPhone(subscriptionId);
7629 if (phone == null) {
7630 return null;
7631 }
7632 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7633 } finally {
7634 Binder.restoreCallingIdentity(identity);
7635 }
7636 }
7637
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007638 /**
7639 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007640 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007641 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642 final long identity = Binder.clearCallingIdentity();
7643 try {
7644 Phone phone = getPhone(subId);
7645 if (phone != null) {
7646 return phone.isWifiCallingEnabled();
7647 } else {
7648 return false;
7649 }
7650 } finally {
7651 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007652 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007653 }
7654
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007655 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007656 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007657 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007658 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659 final long identity = Binder.clearCallingIdentity();
7660 try {
7661 Phone phone = getPhone(subId);
7662 if (phone != null) {
7663 return phone.isVideoEnabled();
7664 } else {
7665 return false;
7666 }
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007669 }
7670 }
7671
7672 /**
7673 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7674 * defined in {@link ImsRegistrationImplBase}.
7675 */
7676 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 final long identity = Binder.clearCallingIdentity();
7678 try {
7679 Phone phone = getPhone(subId);
7680 if (phone != null) {
7681 return phone.getImsRegistrationTech();
7682 } else {
7683 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7684 }
7685 } finally {
7686 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007687 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007688 }
7689
Stuart Scott8eef64f2015-04-08 15:13:54 -07007690 @Override
7691 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007692 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007693 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7694 return;
7695 }
Kai Shif70f46f2021-03-03 13:59:46 -08007696 Phone defaultPhone = getDefaultPhone();
7697 if (defaultPhone != null) {
7698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7699 mApp, getDefaultPhone().getSubId(), "factoryReset");
7700 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007701 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007702
Svet Ganovcc087f82015-05-12 20:35:54 -07007703 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007704 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7705 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007706 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007707 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007708 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007709 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007710 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007711 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007712 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007713 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007714 // There has been issues when Sms raw table somehow stores orphan
7715 // fragments. They lead to garbled message when new fragments come
7716 // in and combined with those stale ones. In case this happens again,
7717 // user can reset all network settings which will clean up this table.
7718 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007719 // Clean up IMS settings as well here.
7720 int slotId = getSlotIndex(subId);
7721 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7722 ImsManager.getInstance(mApp, slotId).factoryReset();
7723 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007724
Kai Shif70f46f2021-03-03 13:59:46 -08007725 if (defaultPhone == null) {
7726 return;
7727 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007728 // Erase modem config if erase modem on network setting is enabled.
7729 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7730 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7731 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007732 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007733 }
Kai Shif70f46f2021-03-03 13:59:46 -08007734
7735 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007736 } finally {
7737 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007738 }
7739 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007740
SongFerngWangfd89b102021-05-27 22:44:54 +08007741 @VisibleForTesting
7742 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7743 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7744 return;
7745 }
7746 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7747 RILConstants.PREFERRED_NETWORK_MODE);
7748 SubscriptionManager.setSubscriptionProperty(subId,
7749 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7750 "user=" + defaultNetworkType);
7751 phone.loadAllowedNetworksFromSubscriptionDatabase();
7752 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7753 defaultNetworkType, null);
7754 }
7755
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007756 private void cleanUpSmsRawTable(Context context) {
7757 ContentResolver resolver = context.getContentResolver();
7758 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7759 resolver.delete(uri, null, null);
7760 }
7761
Narayan Kamath1c496c22015-04-16 14:40:19 +01007762 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007763 public String getSimLocaleForSubscriber(int subId) {
7764 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7765 final Phone phone = getPhone(subId);
7766 if (phone == null) {
7767 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007768 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770 final long identity = Binder.clearCallingIdentity();
7771 try {
chen xu5d3637b2019-01-21 23:31:38 -08007772 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007773 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007774 if (info == null) {
7775 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7776 return null;
7777 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 // Try and fetch the locale from the carrier properties or from the SIM language
7779 // preferences (EF-PL and EF-LI)...
7780 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007782 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7783 if (localeFromDefaultSim != null) {
7784 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7785 if (DBG) log("Using locale from subId: " + subId + " locale: "
7786 + localeFromDefaultSim);
7787 return localeFromDefaultSim.toLanguageTag();
7788 } else {
7789 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 }
7791 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 // The SIM language preferences only store a language (e.g. fr = French), not an
7794 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7795 // the SIM and carrier preferences does not include a country we add the country
7796 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007797 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007799 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 return mccLocale.toLanguageTag();
7801 }
7802
7803 if (DBG) log("No locale found - returning null");
7804 return null;
7805 } finally {
7806 Binder.restoreCallingIdentity(identity);
7807 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007808 }
7809
7810 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007811 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007812 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007813 }
7814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 /**
7816 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7817 */
7818 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007819 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007820 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007821 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007822
Chenjie Yu1ba97252018-01-11 18:16:20 -08007823 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007824 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007825
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007826 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007827 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7828 * representing the state of the modem.
7829 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007830 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7831 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007832 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007833 */
7834 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007835 public void requestModemActivityInfo(ResultReceiver result) {
7836 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007837 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838
7839 final long identity = Binder.clearCallingIdentity();
7840 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007841 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842 } finally {
7843 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007844 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007845 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007846
Siddharth Rayb8114062018-06-17 15:02:38 -07007847 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7848 // less than total activity duration.
7849 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7850 if (info == null) {
7851 return false;
7852 }
7853 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007854 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7855 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7856
Siddharth Rayb8114062018-06-17 15:02:38 -07007857 return (info.isValid()
7858 && (info.getSleepTimeMillis() <= activityDurationMs)
7859 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007860 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007861 && (totalTxTimeMs <= activityDurationMs));
7862 }
7863
Jack Yu85bd38a2015-11-09 11:34:32 -08007864 /**
7865 * {@hide}
7866 * Returns the service state information on specified subscription.
7867 */
7868 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007869 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7870 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007871 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007872 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007873 return null;
7874 }
7875
Hall Liuf19c44f2018-11-27 14:38:17 -08007876 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7877 LocationAccessPolicy.checkLocationPermission(mApp,
7878 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7879 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007880 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007881 .setCallingPid(Binder.getCallingPid())
7882 .setCallingUid(Binder.getCallingUid())
7883 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007884 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007885 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007886 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7887 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007888 .build());
7889
7890 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7891 LocationAccessPolicy.checkLocationPermission(mApp,
7892 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7893 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007894 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007895 .setCallingPid(Binder.getCallingPid())
7896 .setCallingUid(Binder.getCallingUid())
7897 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007898 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007899 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007900 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7901 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007902 .build());
7903 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7904 boolean hasFinePermission =
7905 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7906 boolean hasCoarsePermission =
7907 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7908
Jack Yu479f40e2020-10-27 21:29:25 -07007909 final Phone phone = getPhone(subId);
7910 if (phone == null) {
7911 return null;
7912 }
7913
Jordan Liu0f2bc442020-11-18 16:47:37 -08007914 final long identity = Binder.clearCallingIdentity();
7915
Jack Yu479f40e2020-10-27 21:29:25 -07007916 boolean isCallingPackageDataService = phone.getDataServicePackages()
7917 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007918 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007919 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7920 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7921 Rlog.d(LOG_TAG,
7922 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7923 return null;
7924 }
7925
Hall Liuf19c44f2018-11-27 14:38:17 -08007926 ServiceState ss = phone.getServiceState();
7927
7928 // Scrub out the location info in ServiceState depending on what level of access
7929 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007930 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007931 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7932 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933 } finally {
7934 Binder.restoreCallingIdentity(identity);
7935 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007936 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007937
7938 /**
7939 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7940 *
7941 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7942 * voicemail ringtone.
7943 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7944 * PhoneAccount.
7945 */
7946 @Override
7947 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 final long identity = Binder.clearCallingIdentity();
7949 try {
7950 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7951 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007952 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
7958 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007959 }
7960
7961 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007962 * Sets the per-account voicemail ringtone.
7963 *
7964 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7965 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7966 *
7967 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7968 * voicemail ringtone.
7969 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7970 * PhoneAccount.
7971 */
7972 @Override
7973 public void setVoicemailRingtoneUri(String callingPackage,
7974 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007975 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007977 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7978 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7980 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7981 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983
7984 final long identity = Binder.clearCallingIdentity();
7985 try {
7986 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7987 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 }
7990 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7991 } finally {
7992 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007993 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007994 }
7995
7996 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007997 * Returns whether vibration is set for voicemail notification in Phone settings.
7998 *
7999 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8000 * voicemail vibration setting.
8001 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8002 */
8003 @Override
8004 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 final long identity = Binder.clearCallingIdentity();
8006 try {
8007 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8008 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008009 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8013 } finally {
8014 Binder.restoreCallingIdentity(identity);
8015 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008016 }
8017
Youhan Wange64578a2016-05-02 15:32:42 -07008018 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 * Sets the per-account voicemail vibration.
8020 *
8021 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8022 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8023 *
8024 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8025 * voicemail vibration setting.
8026 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8027 * specific PhoneAccount.
8028 */
8029 @Override
8030 public void setVoicemailVibrationEnabled(String callingPackage,
8031 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008032 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008034 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8035 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8037 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8038 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008039 }
8040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008041 final long identity = Binder.clearCallingIdentity();
8042 try {
8043 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8044 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008045 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008046 }
8047 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8048 } finally {
8049 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008050 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008051 }
8052
8053 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008054 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8055 *
8056 * @throws SecurityException if the caller does not have the required permission
8057 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008058 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008059 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008060 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008061 }
8062
8063 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008064 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8065 * permission.
8066 *
8067 * @throws SecurityException if the caller does not have the required permission
8068 */
8069 private void enforceSendSmsPermission() {
8070 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8071 }
8072
8073 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008074 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008075 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008076 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008077 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008078 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008082 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 if (componentName == null) {
8084 throw new SecurityException(
8085 "Caller not current active visual voicemail package[null]");
8086 }
8087 String vvmPackage = componentName.getPackageName();
8088 if (!callingPackage.equals(vvmPackage)) {
8089 throw new SecurityException("Caller not current active visual voicemail package["
8090 + vvmPackage + "]");
8091 }
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008094 }
8095 }
8096
8097 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008098 * Return the application ID for the app type.
8099 *
8100 * @param subId the subscription ID that this request applies to.
8101 * @param appType the uicc app type.
8102 * @return Application ID for specificied app type, or null if no uicc.
8103 */
8104 @Override
8105 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008106 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008107 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108
8109 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008110 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 if (phone == null) {
8112 return null;
8113 }
8114 String aid = null;
8115 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008116 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117 .getApplicationByType(appType).getAid();
8118 } catch (Exception e) {
8119 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8120 }
8121 return aid;
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008124 }
Youhan Wange64578a2016-05-02 15:32:42 -07008125 }
8126
Youhan Wang4001d252016-05-11 10:29:41 -07008127 /**
8128 * Return the Electronic Serial Number.
8129 *
8130 * @param subId the subscription ID that this request applies to.
8131 * @return ESN or null if error.
8132 */
8133 @Override
8134 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008135 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008136 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008137
8138 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008139 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008140 if (phone == null) {
8141 return null;
8142 }
8143 String esn = null;
8144 try {
8145 esn = phone.getEsn();
8146 } catch (Exception e) {
8147 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8148 }
8149 return esn;
8150 } finally {
8151 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008152 }
Youhan Wang4001d252016-05-11 10:29:41 -07008153 }
8154
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008155 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008156 * Return the Preferred Roaming List Version.
8157 *
8158 * @param subId the subscription ID that this request applies to.
8159 * @return PRLVersion or null if error.
8160 */
8161 @Override
8162 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008163 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008164 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165
8166 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008167 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008168 if (phone == null) {
8169 return null;
8170 }
8171 String cdmaPrlVersion = null;
8172 try {
8173 cdmaPrlVersion = phone.getCdmaPrlVersion();
8174 } catch (Exception e) {
8175 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8176 }
8177 return cdmaPrlVersion;
8178 } finally {
8179 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008180 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008181 }
8182
8183 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008184 * Get snapshot of Telephony histograms
8185 * @return List of Telephony histograms
8186 * @hide
8187 */
8188 @Override
8189 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8191 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192
8193 final long identity = Binder.clearCallingIdentity();
8194 try {
8195 return RIL.getTelephonyRILTimingHistograms();
8196 } finally {
8197 Binder.restoreCallingIdentity(identity);
8198 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008199 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008200
8201 /**
8202 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008203 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8204 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008205 * Require system privileges. In the future we may add this to carrier APIs.
8206 *
Michele Berionne482f8202018-11-27 18:57:59 -08008207 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008208 */
8209 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008210 @TelephonyManager.SetCarrierRestrictionResult
8211 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008212 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008213 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008214
Michele Berionne482f8202018-11-27 18:57:59 -08008215 if (carrierRestrictionRules == null) {
8216 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008217 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 final long identity = Binder.clearCallingIdentity();
8220 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008221 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008222 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223 } finally {
8224 Binder.restoreCallingIdentity(identity);
8225 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008226 }
8227
8228 /**
8229 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008230 * Get the allowed carrier list and the excluded carrier list, including the priority between
8231 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008232 * Require system privileges. In the future we may add this to carrier APIs.
8233 *
Michele Berionne482f8202018-11-27 18:57:59 -08008234 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008235 */
8236 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008237 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008238 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008239 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008240
8241 final long identity = Binder.clearCallingIdentity();
8242 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008243 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8244 if (response instanceof CarrierRestrictionRules) {
8245 return (CarrierRestrictionRules) response;
8246 }
8247 // Response is an Exception of some kind,
8248 // which is signalled to the user as a NULL retval
8249 return null;
8250 } catch (Exception e) {
8251 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8252 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253 } finally {
8254 Binder.restoreCallingIdentity(identity);
8255 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008256 }
8257
fionaxu59545b42016-05-25 15:53:37 -07008258 /**
fionaxu59545b42016-05-25 15:53:37 -07008259 * Action set from carrier signalling broadcast receivers to enable/disable radio
8260 * @param subId the subscription ID that this action applies to.
8261 * @param enabled control enable or disable radio.
8262 * {@hide}
8263 */
8264 @Override
8265 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8266 enforceModifyPermission();
8267 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268
8269 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008270 if (phone == null) {
8271 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8272 return;
8273 }
8274 try {
8275 phone.carrierActionSetRadioEnabled(enabled);
8276 } catch (Exception e) {
8277 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 } finally {
8279 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008280 }
8281 }
8282
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008283 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008284 * Enable or disable Voice over NR (VoNR)
8285 * @param subId the subscription ID that this action applies to.
8286 * @param enabled enable or disable VoNR.
8287 * @return operation result.
8288 */
8289 @Override
8290 public int setVoNrEnabled(int subId, boolean enabled) {
8291 enforceModifyPermission();
8292 final Phone phone = getPhone(subId);
8293
8294 final long identity = Binder.clearCallingIdentity();
8295 if (phone == null) {
8296 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8297 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8298 }
8299
8300 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8301 try {
8302 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8303 workSource);
8304 if (DBG) log("setVoNrEnabled result: " + result);
8305 return result;
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
8309 }
8310
8311 /**
8312 * Is voice over NR enabled
8313 * @return true if VoNR is enabled else false
8314 */
8315 @Override
8316 public boolean isVoNrEnabled(int subId) {
8317 enforceReadPrivilegedPermission("isVoNrEnabled");
8318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8319 final long identity = Binder.clearCallingIdentity();
8320 try {
8321 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8322 null, subId, workSource);
8323 if (DBG) log("isVoNrEnabled: " + isEnabled);
8324 return isEnabled;
8325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
8328 }
8329
8330 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008331 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8332 * network status based on which carrier apps could apply actions accordingly,
8333 * enable/disable default url handler for example.
8334 *
8335 * @param subId the subscription ID that this action applies to.
8336 * @param report control start/stop reporting the default network status.
8337 * {@hide}
8338 */
8339 @Override
8340 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8341 enforceModifyPermission();
8342 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343
8344 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008345 if (phone == null) {
8346 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8347 return;
8348 }
8349 try {
8350 phone.carrierActionReportDefaultNetworkStatus(report);
8351 } catch (Exception e) {
8352 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353 } finally {
8354 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008355 }
8356 }
8357
8358 /**
fionaxud9622282017-07-17 17:51:30 -07008359 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8360 * @param subId the subscription ID that this action applies to.
8361 * {@hide}
8362 */
8363 @Override
8364 public void carrierActionResetAll(int subId) {
8365 enforceModifyPermission();
8366 final Phone phone = getPhone(subId);
8367 if (phone == null) {
8368 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8369 return;
8370 }
8371 try {
8372 phone.carrierActionResetAll();
8373 } catch (Exception e) {
8374 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8375 }
8376 }
8377
8378 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008379 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8380 * bug report is being generated.
8381 */
8382 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008383 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008384 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8385 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008386 writer.println("Permission Denial: can't dump Phone from pid="
8387 + Binder.getCallingPid()
8388 + ", uid=" + Binder.getCallingUid()
8389 + "without permission "
8390 + android.Manifest.permission.DUMP);
8391 return;
8392 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008393 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008394 }
Jack Yueb89b242016-06-22 13:27:47 -07008395
Brad Ebingerdac2f002018-04-03 15:17:52 -07008396 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008397 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8398 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8399 @NonNull String[] args) {
8400 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8401 this, in.getFileDescriptor(), out.getFileDescriptor(),
8402 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008403 }
8404
Jack Yueb89b242016-06-22 13:27:47 -07008405 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008406 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008407 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008408 * @param reason the reason the data enable change is taking place
8409 * @param enabled True if enabling the data, otherwise disabling.
8410 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008411 */
8412 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008413 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008414 boolean enabled) {
8415 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8416 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8417 try {
8418 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008419 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008420 } catch (SecurityException se) {
8421 enforceModifyPermission();
8422 }
8423 } else {
8424 enforceModifyPermission();
8425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008426
8427 final long identity = Binder.clearCallingIdentity();
8428 try {
8429 Phone phone = getPhone(subId);
8430 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008431 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8432 phone.carrierActionSetMeteredApnsEnabled(enabled);
8433 } else {
8434 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008436 }
8437 } finally {
8438 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008439 }
8440 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008441
8442 /**
8443 * Get Client request stats
8444 * @return List of Client Request Stats
8445 * @hide
8446 */
8447 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008448 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8449 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008451 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008452 return null;
8453 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008454 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456 final long identity = Binder.clearCallingIdentity();
8457 try {
8458 if (phone != null) {
8459 return phone.getClientRequestStats();
8460 }
8461
8462 return null;
8463 } finally {
8464 Binder.restoreCallingIdentity(identity);
8465 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008466 }
8467
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008468 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008469 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008470 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008471 }
Jack Yueb4124c2017-02-16 15:32:43 -08008472
8473 /**
Grace Chen70990072017-03-24 17:21:30 -07008474 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008475 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008476 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008477 * @param state State of SIM (power down, power up, pass through)
8478 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8479 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8480 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008481 *
8482 **/
8483 @Override
Grace Chen70990072017-03-24 17:21:30 -07008484 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008485 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008486 Phone phone = PhoneFactory.getPhone(slotIndex);
8487
vagdeviaf9a5b92018-08-15 16:01:53 -07008488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008493 phone.setSimPowerState(state, null, workSource);
8494 }
8495 } finally {
8496 Binder.restoreCallingIdentity(identity);
8497 }
8498 }
8499
8500 /**
8501 * Set SIM card power state.
8502 *
8503 * @param slotIndex SIM slot id.
8504 * @param state State of SIM (power down, power up, pass through)
8505 * @param callback callback to trigger after success or failure
8506 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8507 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8508 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8509 *
8510 **/
8511 @Override
8512 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8513 IIntegerConsumer callback) {
8514 enforceModifyPermission();
8515 Phone phone = PhoneFactory.getPhone(slotIndex);
8516
8517 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8518
8519 final long identity = Binder.clearCallingIdentity();
8520 try {
8521 if (phone != null) {
8522 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8523 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524 }
8525 } finally {
8526 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008527 }
8528 }
Shuo Qiandd210312017-04-12 22:11:33 +00008529
Tyler Gunn65d45c22017-06-05 11:22:26 -07008530 private boolean isUssdApiAllowed(int subId) {
8531 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008532 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008533 if (configManager == null) {
8534 return false;
8535 }
8536 PersistableBundle pb = configManager.getConfigForSubId(subId);
8537 if (pb == null) {
8538 return false;
8539 }
8540 return pb.getBoolean(
8541 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8542 }
8543
Shuo Qiandd210312017-04-12 22:11:33 +00008544 /**
8545 * Check if phone is in emergency callback mode
8546 * @return true if phone is in emergency callback mode
8547 * @param subId sub id
8548 */
goneil9c5f4872017-12-05 14:07:56 -08008549 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008550 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008551 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008552 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008553
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
8556 if (phone != null) {
8557 return phone.isInEcm();
8558 } else {
8559 return false;
8560 }
8561 } finally {
8562 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008563 }
8564 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008565
8566 /**
8567 * Get the current signal strength information for the given subscription.
8568 * Because this information is not updated when the device is in a low power state
8569 * it should not be relied-upon to be current.
8570 * @param subId Subscription index
8571 * @return the most recent cached signal strength info from the modem
8572 */
8573 @Override
8574 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008575 final long identity = Binder.clearCallingIdentity();
8576 try {
8577 Phone p = getPhone(subId);
8578 if (p == null) {
8579 return null;
8580 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008582 return p.getSignalStrength();
8583 } finally {
8584 Binder.restoreCallingIdentity(identity);
8585 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008586 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008587
Pengquan Meng77b7f132018-08-22 14:49:57 -07008588 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008589 * Get the current modem radio state for the given slot.
8590 * @param slotIndex slot index.
8591 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008592 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008593 * @return the current radio power state from the modem
8594 */
8595 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008596 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008597 Phone phone = PhoneFactory.getPhone(slotIndex);
8598 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8600 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008601 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8602 }
8603
8604 final long identity = Binder.clearCallingIdentity();
8605 try {
8606 return phone.getRadioPowerState();
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
8610 }
8611 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8612 }
8613
8614 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008615 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8616 *
8617 * <p>Requires one of the following permissions:
8618 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008619 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008620 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8621 * privileges.
8622 *
8623 * @param subId subscription id
8624 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8625 * {@code false}.
8626 */
8627 @Override
8628 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008629 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008630 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008631 try {
8632 mApp.enforceCallingOrSelfPermission(
8633 android.Manifest.permission.ACCESS_NETWORK_STATE,
8634 functionName);
8635 } catch (Exception e) {
8636 mApp.enforceCallingOrSelfPermission(
8637 permission.READ_BASIC_PHONE_STATE, functionName);
8638 }
Shuo Qian093013d2020-08-13 15:42:55 -07008639 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008640 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008641 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008642 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008643
Pengquan Menga1bb6272018-09-06 09:59:22 -07008644 boolean isEnabled = false;
8645 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008646 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008647 Phone phone = getPhone(subId);
8648 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008649 } finally {
8650 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008651 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008652 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008653 }
8654
8655
8656 /**
8657 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8658 *
8659 * <p> Requires permission:
8660 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8661 * privileges.
8662 *
8663 * @param subId subscription id
8664 * @param isEnabled {@code true} means enable, {@code false} means disable.
8665 */
8666 @Override
8667 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8669 mApp, subId, "setDataRoamingEnabled");
8670
Pengquan Menga1bb6272018-09-06 09:59:22 -07008671 final long identity = Binder.clearCallingIdentity();
8672 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008673 Phone phone = getPhone(subId);
8674 if (phone != null) {
8675 phone.setDataRoamingEnabled(isEnabled);
8676 }
8677 } finally {
8678 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008679 }
8680 }
8681
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008682 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008683 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008684 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008685 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008686 mApp, subId, "isManualNetworkSelectionAllowed");
8687
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008688 boolean isAllowed = true;
8689 final long identity = Binder.clearCallingIdentity();
8690 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008691 Phone phone = getPhone(subId);
8692 if (phone != null) {
8693 isAllowed = phone.isCspPlmnEnabled();
8694 }
8695 } finally {
8696 Binder.restoreCallingIdentity(identity);
8697 }
8698 return isAllowed;
8699 }
8700
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008701 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8702 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8703 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8704 // Update each UiccPort object based on privilege access
8705 UiccPort[] uiccPorts = card.getUiccPortList();
8706 for (UiccPort port : uiccPorts) {
8707 UiccProfile profile = port.getUiccProfile();
8708 if (profile == null ||
8709 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8710 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8711 return false;
8712 }
8713 }
8714 return true;
8715 }
8716
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008717 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008718 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008719 // Verify that tha callingPackage belongs to the calling UID
8720 mApp.getSystemService(AppOpsManager.class)
8721 .checkPackage(Binder.getCallingUid(), callingPackage);
8722
Jordan Liu1e142fc2019-04-22 15:10:43 -07008723 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008724 try {
8725 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008726 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008727 } catch (SecurityException e) {
8728 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8729 // has carrier privileges on an active UICC
8730 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8731 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008732 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008733 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008734 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008735
8736 final long identity = Binder.clearCallingIdentity();
8737 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008738 UiccController uiccController = UiccController.getInstance();
8739 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008740 if (hasReadPermission) {
8741 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008742 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008743
8744 // Remove private info if the caller doesn't have access
8745 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8746 for (UiccCardInfo cardInfo : cardInfos) {
8747 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8748 // is available
8749 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008750 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8751 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8752 if (card == null || card.getUiccPortList().length == 0) {
8753 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008754 filteredInfos.add(cardInfo.getUnprivileged());
8755 continue;
8756 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008757
8758 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008759 filteredInfos.add(cardInfo);
8760 } else {
8761 filteredInfos.add(cardInfo.getUnprivileged());
8762 }
8763 }
8764 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008765 } finally {
8766 Binder.restoreCallingIdentity(identity);
8767 }
8768 }
8769
8770 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008771 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008772 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008774 final long identity = Binder.clearCallingIdentity();
8775 try {
8776 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8777 if (slots == null) {
8778 Rlog.i(LOG_TAG, "slots is null.");
8779 return null;
8780 }
8781
8782 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8783 for (int i = 0; i < slots.length; i++) {
8784 UiccSlot slot = slots[i];
8785 if (slot == null) {
8786 continue;
8787 }
8788
Jordan Liu7be7e652019-05-06 18:55:02 +00008789 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008790 UiccCard card = slot.getUiccCard();
8791 if (card != null) {
8792 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008793 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008794 cardId = slot.getEid();
8795 if (TextUtils.isEmpty(cardId)) {
8796 cardId = slot.getIccId();
8797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008798 }
8799
Jordan Liu857451f2019-05-09 16:35:35 -07008800 if (cardId != null) {
8801 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8802 // if cardId is an EID, it's all digits so this is fine
8803 cardId = IccUtils.stripTrailingFs(cardId);
8804 }
8805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008806 int cardState = 0;
8807 switch (slot.getCardState()) {
8808 case CARDSTATE_ABSENT:
8809 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8810 break;
8811 case CARDSTATE_PRESENT:
8812 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8813 break;
8814 case CARDSTATE_ERROR:
8815 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8816 break;
8817 case CARDSTATE_RESTRICTED:
8818 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8819 break;
8820 default:
8821 break;
8822
8823 }
8824
8825 infos[i] = new UiccSlotInfo(
8826 slot.isActive(),
8827 slot.isEuicc(),
8828 cardId,
8829 cardState,
8830 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008831 slot.isExtendedApduSupported(),
8832 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008833 }
8834 return infos;
8835 } finally {
8836 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008837 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008838 }
8839
8840 @Override
8841 public boolean switchSlots(int[] physicalSlots) {
8842 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008843
8844 final long identity = Binder.clearCallingIdentity();
8845 try {
8846 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8847 } finally {
8848 Binder.restoreCallingIdentity(identity);
8849 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008850 }
Jack Yu4c988042018-02-27 15:30:01 -08008851
8852 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008853 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008854 final long identity = Binder.clearCallingIdentity();
8855 try {
8856 return UiccController.getInstance().getCardIdForDefaultEuicc();
8857 } finally {
8858 Binder.restoreCallingIdentity(identity);
8859 }
8860 }
8861
Pengquan Meng85728fb2018-03-12 16:31:21 -07008862 /**
goneil47ffb6e2018-04-06 15:40:58 -07008863 * A test API to reload the UICC profile.
8864 *
8865 * <p>Requires that the calling app has permission
8866 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8867 * @hide
8868 */
8869 @Override
8870 public void refreshUiccProfile(int subId) {
8871 enforceModifyPermission();
8872
8873 final long identity = Binder.clearCallingIdentity();
8874 try {
8875 Phone phone = getPhone(subId);
8876 if (phone == null) {
8877 return;
8878 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008879 UiccPort uiccPort = phone.getUiccPort();
8880 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008881 return;
8882 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008883 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008884 if (uiccProfile == null) {
8885 return;
8886 }
8887 uiccProfile.refresh();
8888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
8891 }
8892
8893 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008894 * Returns false if the mobile data is disabled by default, otherwise return true.
8895 */
8896 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008897 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008898 }
8899
8900 /**
8901 * Returns true if the data roaming is enabled by default, i.e the system property
8902 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8903 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8904 */
8905 private boolean getDefaultDataRoamingEnabled(int subId) {
8906 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008907 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008908 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008909 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8910 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8911 return isDataRoamingEnabled;
8912 }
8913
8914 /**
8915 * Returns the default network type for the given {@code subId}, if the default network type is
8916 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8917 */
8918 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008919 List<Integer> list = TelephonyProperties.default_network();
8920 int phoneId = mSubscriptionController.getPhoneId(subId);
8921 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8922 return list.get(phoneId);
8923 }
8924 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008925 }
fionaxua13278b2018-03-21 00:08:13 -07008926
8927 @Override
8928 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008929 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008930 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008931
8932 final long identity = Binder.clearCallingIdentity();
8933 try {
8934 final Phone phone = getPhone(subId);
8935 if (phone == null) {
8936 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8937 return;
8938 }
chen xueaba88a2019-03-15 13:15:10 -07008939 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8940 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008941 if (carrierPrivilegeRules == null) {
8942 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8943 } else {
8944 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008946 } finally {
8947 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008948 }
fionaxua13278b2018-03-21 00:08:13 -07008949 }
8950
8951 @Override
8952 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008953 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008954
8955 final long identity = Binder.clearCallingIdentity();
8956 try {
8957 final Phone phone = getPhone(subId);
8958 if (phone == null) {
8959 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8960 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8961 }
8962 return phone.getCarrierIdListVersion();
8963 } finally {
8964 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008965 }
fionaxua13278b2018-03-21 00:08:13 -07008966 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008967
8968 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008969 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8970 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008972 mApp, subId, callingPackage, callingFeatureId,
8973 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008974 return -1;
8975 }
8976
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
8983 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008984
8985 @Override
8986 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008987 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008988 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008989 mApp, subId, "getCdmaRoamingMode");
8990
8991 final long identity = Binder.clearCallingIdentity();
8992 try {
8993 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
8998
8999 @Override
9000 public boolean setCdmaRoamingMode(int subId, int mode) {
9001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9002 mApp, subId, "setCdmaRoamingMode");
9003
9004 final long identity = Binder.clearCallingIdentity();
9005 try {
9006 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9007 } finally {
9008 Binder.restoreCallingIdentity(identity);
9009 }
9010 }
9011
9012 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009013 public int getCdmaSubscriptionMode(int subId) {
9014 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009015 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009016 mApp, subId, "getCdmaSubscriptionMode");
9017
9018 final long identity = Binder.clearCallingIdentity();
9019 try {
9020 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 }
9025
9026 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009027 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9029 mApp, subId, "setCdmaSubscriptionMode");
9030
9031 final long identity = Binder.clearCallingIdentity();
9032 try {
9033 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9034 } finally {
9035 Binder.restoreCallingIdentity(identity);
9036 }
9037 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009038
sqianc5eccab2018-10-19 18:46:41 -07009039 @Override
sqian8c685422019-02-22 15:55:18 -08009040 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009041 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009043 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9044 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009045 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9046 }
9047 final long identity = Binder.clearCallingIdentity();
9048 try {
sqian854d44b2018-12-12 16:48:18 -08009049 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9050 for (Phone phone: PhoneFactory.getPhones()) {
9051 if (phone.getEmergencyNumberTracker() != null
9052 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9053 emergencyNumberListInternal.put(
9054 phone.getSubId(),
9055 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9056 }
sqian11b7a0e2018-12-05 18:48:28 -08009057 }
sqian854d44b2018-12-12 16:48:18 -08009058 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009059 } finally {
9060 Binder.restoreCallingIdentity(identity);
9061 }
sqianc5eccab2018-10-19 18:46:41 -07009062 }
9063
9064 @Override
sqian8c685422019-02-22 15:55:18 -08009065 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009066 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009067 if (!exactMatch) {
9068 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009069 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009070 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009071 }
9072 final long identity = Binder.clearCallingIdentity();
9073 try {
sqian854d44b2018-12-12 16:48:18 -08009074 for (Phone phone: PhoneFactory.getPhones()) {
9075 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009076 && phone.getEmergencyNumberTracker()
9077 .isEmergencyNumber(number, exactMatch)) {
9078 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009079 }
sqian11b7a0e2018-12-05 18:48:28 -08009080 }
9081 return false;
9082 } finally {
9083 Binder.restoreCallingIdentity(identity);
9084 }
9085 }
9086
sqianf4ca7ed2019-01-15 18:32:07 -08009087 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009088 * Start emergency callback mode for GsmCdmaPhone for testing.
9089 */
9090 @Override
9091 public void startEmergencyCallbackMode() {
9092 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9093 "startEmergencyCallbackMode");
9094 enforceModifyPermission();
9095 final long identity = Binder.clearCallingIdentity();
9096 try {
9097 for (Phone phone : PhoneFactory.getPhones()) {
9098 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9099 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9100 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9101 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9102 gsmCdmaPhone.obtainMessage(
9103 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9104 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9105 }
9106 }
9107 } finally {
9108 Binder.restoreCallingIdentity(identity);
9109 }
9110 }
9111
9112 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009113 * Update emergency number list for test mode.
9114 */
9115 @Override
9116 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9118 "updateEmergencyNumberListTestMode");
9119
9120 final long identity = Binder.clearCallingIdentity();
9121 try {
9122 for (Phone phone: PhoneFactory.getPhones()) {
9123 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9124 if (tracker != null) {
9125 tracker.executeEmergencyNumberTestModeCommand(action, num);
9126 }
9127 }
9128 } finally {
9129 Binder.restoreCallingIdentity(identity);
9130 }
9131 }
9132
9133 /**
9134 * Get the full emergency number list for test mode.
9135 */
9136 @Override
9137 public List<String> getEmergencyNumberListTestMode() {
9138 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9139 "getEmergencyNumberListTestMode");
9140
9141 final long identity = Binder.clearCallingIdentity();
9142 try {
9143 Set<String> emergencyNumbers = new HashSet<>();
9144 for (Phone phone: PhoneFactory.getPhones()) {
9145 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9146 if (tracker != null) {
9147 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9148 emergencyNumbers.add(num.getNumber());
9149 }
9150 }
9151 }
9152 return new ArrayList<>(emergencyNumbers);
9153 } finally {
9154 Binder.restoreCallingIdentity(identity);
9155 }
9156 }
9157
chen xud6b45bd2018-10-30 22:27:10 -07009158 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009159 public int getEmergencyNumberDbVersion(int subId) {
9160 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9161
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
9164 final Phone phone = getPhone(subId);
9165 if (phone == null) {
9166 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9167 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9168 }
9169 return phone.getEmergencyNumberDbVersion();
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
9174
9175 @Override
9176 public void notifyOtaEmergencyNumberDbInstalled() {
9177 enforceModifyPermission();
9178
9179 final long identity = Binder.clearCallingIdentity();
9180 try {
9181 for (Phone phone: PhoneFactory.getPhones()) {
9182 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9183 if (tracker != null) {
9184 tracker.updateOtaEmergencyNumberDatabase();
9185 }
9186 }
9187 } finally {
9188 Binder.restoreCallingIdentity(identity);
9189 }
9190 }
9191
9192 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009193 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009194 enforceActiveEmergencySessionPermission();
9195
9196 final long identity = Binder.clearCallingIdentity();
9197 try {
9198 for (Phone phone: PhoneFactory.getPhones()) {
9199 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9200 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009201 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9202 }
9203 }
9204 } finally {
9205 Binder.restoreCallingIdentity(identity);
9206 }
9207 }
9208
9209 @Override
9210 public void resetOtaEmergencyNumberDbFilePath() {
9211 enforceActiveEmergencySessionPermission();
9212
9213 final long identity = Binder.clearCallingIdentity();
9214 try {
9215 for (Phone phone: PhoneFactory.getPhones()) {
9216 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9217 if (tracker != null) {
9218 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009219 }
9220 }
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 }
9225
9226 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009227 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9228 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9229 Phone phone = getPhone(subId);
9230 if (phone == null) {
9231 return null;
9232 }
9233 final long identity = Binder.clearCallingIdentity();
9234 try {
9235 UiccProfile profile = UiccController.getInstance()
9236 .getUiccProfileForPhone(phone.getPhoneId());
9237 if (profile != null) {
9238 return profile.getCertsFromCarrierPrivilegeAccessRules();
9239 }
9240 } finally {
9241 Binder.restoreCallingIdentity(identity);
9242 }
9243 return null;
9244 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009245
9246 /**
9247 * Enable or disable a modem stack.
9248 */
9249 @Override
9250 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9251 enforceModifyPermission();
9252
9253 final long identity = Binder.clearCallingIdentity();
9254 try {
9255 Phone phone = PhoneFactory.getPhone(slotIndex);
9256 if (phone == null) {
9257 return false;
9258 } else {
9259 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9260 }
9261 } finally {
9262 Binder.restoreCallingIdentity(identity);
9263 }
9264 }
Michelecea4cf22018-12-21 15:00:11 -08009265
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009266 /**
9267 * Whether a modem stack is enabled or not.
9268 */
9269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009270 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9271 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009272 Phone phone = PhoneFactory.getPhone(slotIndex);
9273 if (phone == null) return false;
9274
9275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009276 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9277 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009278 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9279 }
9280
9281 final long identity = Binder.clearCallingIdentity();
9282 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009283 try {
9284 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9285 } catch (NoSuchElementException ex) {
9286 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9287 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009288 } finally {
9289 Binder.restoreCallingIdentity(identity);
9290 }
9291 }
9292
Michelecea4cf22018-12-21 15:00:11 -08009293 @Override
Michele0ea7d782019-03-19 14:58:42 -07009294 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009295 enforceModifyPermission();
9296
9297 final long identity = Binder.clearCallingIdentity();
9298 try {
9299 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009300 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009301 .commit();
9302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
9306
9307 @Override
Michele0ea7d782019-03-19 14:58:42 -07009308 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009309 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009311 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9312 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009313 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009314 }
Michelecea4cf22018-12-21 15:00:11 -08009315
9316 final long identity = Binder.clearCallingIdentity();
9317 try {
Michele0ea7d782019-03-19 14:58:42 -07009318 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009319 } finally {
9320 Binder.restoreCallingIdentity(identity);
9321 }
9322 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009323
Michele0ea7d782019-03-19 14:58:42 -07009324 @TelephonyManager.IsMultiSimSupportedResult
9325 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009326 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9327 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9328 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009329 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9330 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009331 }
9332 // Check if the hardware supports multisim functionality. If usage of multisim is not
9333 // supported by the modem, indicate that it is restricted.
9334 PhoneCapability staticCapability =
9335 mPhoneConfigurationManager.getStaticPhoneCapability();
9336 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009337 loge("isMultiSimSupportedInternal: no static configuration available");
9338 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009339 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009340 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009341 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9342 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009343 }
9344 // Check if support of multiple SIMs is restricted by carrier
9345 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009346 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009347 }
9348
Michele0ea7d782019-03-19 14:58:42 -07009349 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009350 }
9351
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009352 /**
9353 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009354 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9355 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9356 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009357 * @param numOfSims number of active sims we want to switch to
9358 */
9359 @Override
9360 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009361 if (numOfSims == 1) {
9362 enforceModifyPermission();
9363 } else {
9364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9365 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9366 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009367 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009368
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009369 try {
Michele30b57b22019-03-01 12:01:14 -08009370 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009371 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009372 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9373 return;
9374 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009375 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9376 } finally {
9377 Binder.restoreCallingIdentity(identity);
9378 }
9379 }
9380
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009381 @Override
9382 public boolean isApplicationOnUicc(int subId, int appType) {
9383 enforceReadPrivilegedPermission("isApplicationOnUicc");
9384 Phone phone = getPhone(subId);
9385 if (phone == null) {
9386 return false;
9387 }
9388 final long identity = Binder.clearCallingIdentity();
9389 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009390 UiccPort uiccPort = phone.getUiccPort();
9391 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009392 return false;
9393 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009394 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009395 if (uiccProfile == null) {
9396 return false;
9397 }
9398 if (TelephonyManager.APPTYPE_SIM <= appType
9399 && appType <= TelephonyManager.APPTYPE_ISIM) {
9400 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9401 }
9402 return false;
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 }
9407
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009408 /**
chen xub4baa772019-04-03 10:23:41 -07009409 * Get whether making changes to modem configurations will trigger reboot.
9410 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009411 */
9412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009413 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9414 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009415 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009416 mApp, subId, callingPackage, callingFeatureId,
9417 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009418 return false;
9419 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009420 final long identity = Binder.clearCallingIdentity();
9421 try {
9422 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9423 } finally {
9424 Binder.restoreCallingIdentity(identity);
9425 }
9426 }
9427
Nathan Harold29f5f052019-02-15 13:41:57 -08009428 private void updateModemStateMetrics() {
9429 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9430 // TODO: check the state for each modem if the api is ready.
9431 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9432 }
9433
Pengquan Meng3889a572019-01-23 11:16:29 -08009434 @Override
9435 public int[] getSlotsMapping() {
9436 enforceReadPrivilegedPermission("getSlotsMapping");
9437
9438 final long identity = Binder.clearCallingIdentity();
9439 try {
9440 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9441 // All logical slots should have a mapping to a physical slot.
9442 int[] logicalSlotsMapping = new int[phoneCount];
9443 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9444 for (int i = 0; i < slotInfos.length; i++) {
9445 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9446 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9447 }
9448 }
9449 return logicalSlotsMapping;
9450 } finally {
9451 Binder.restoreCallingIdentity(identity);
9452 }
9453 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009454
9455 /**
9456 * Get the IRadio HAL Version
9457 */
9458 @Override
9459 public int getRadioHalVersion() {
9460 Phone phone = getDefaultPhone();
9461 if (phone == null) return -1;
9462 HalVersion hv = phone.getHalVersion();
9463 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9464 return hv.major * 100 + hv.minor;
9465 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009466
9467 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009468 * Get the current calling package name.
9469 * @return the current calling package name
9470 */
9471 @Override
9472 public String getCurrentPackageName() {
9473 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9474 }
9475
9476 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009477 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9478 * corresponding network requests on a subId.
9479 *
9480 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009481 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009482 * 2) APN is un-metered for this subscription, or
9483 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009484 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009485 *
9486 * @return whether data is allowed for a apn type.
9487 *
9488 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009489 */
9490 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009491 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009492 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9493 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009494
9495 // Now that all security checks passes, perform the operation as ourselves.
9496 final long identity = Binder.clearCallingIdentity();
9497 try {
9498 Phone phone = getPhone(subId);
9499 if (phone == null) return false;
9500
Jack Yu41407ee2019-05-13 16:54:09 -07009501 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009502 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9503 } finally {
9504 Binder.restoreCallingIdentity(identity);
9505 }
9506 }
9507
9508 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009509 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009510 enforceReadPrivilegedPermission("isApnMetered");
9511
9512 // Now that all security checks passes, perform the operation as ourselves.
9513 final long identity = Binder.clearCallingIdentity();
9514 try {
9515 Phone phone = getPhone(subId);
9516 if (phone == null) return true; // By default return true.
9517
Jack Yu41407ee2019-05-13 16:54:09 -07009518 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009519 } finally {
9520 Binder.restoreCallingIdentity(identity);
9521 }
9522 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009523
9524 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009525 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9526 int subscriptionId, IBooleanConsumer resultCallback) {
9527 enforceModifyPermission();
9528 long token = Binder.clearCallingIdentity();
9529 try {
9530 Phone phone = getPhone(subscriptionId);
9531 if (phone == null) {
9532 try {
9533 if (resultCallback != null) {
9534 resultCallback.accept(false);
9535 }
9536 } catch (RemoteException e) {
9537 // ignore
9538 }
9539 return;
9540 }
9541 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9542 Pair.create(specifiers, (x) -> {
9543 try {
9544 if (resultCallback != null) {
9545 resultCallback.accept(x);
9546 }
9547 } catch (RemoteException e) {
9548 // ignore
9549 }
9550 });
9551 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9552 } finally {
9553 Binder.restoreCallingIdentity(token);
9554 }
9555 }
9556
9557 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009558 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9559 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009560 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009561 mApp, subId, "getSystemSelectionChannels");
9562 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9563 final long identity = Binder.clearCallingIdentity();
9564 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009565 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9566 if (result instanceof IllegalStateException) {
9567 throw (IllegalStateException) result;
9568 }
9569 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009570 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9571 return specifiers;
9572 } finally {
9573 Binder.restoreCallingIdentity(identity);
9574 }
9575 }
9576
9577 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009578 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009579 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009580 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9581 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9582 if (iccRecords == null) {
9583 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9584 return false;
9585 }
9586 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9587 }
9588
9589 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009590 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9591 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009592 if (callingPackage == null) {
9593 callingPackage = getCurrentPackageName();
9594 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009595 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9596 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009597 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9598 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009599 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9600 }
9601 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9602 Intent intent = new Intent();
9603 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9604 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9605 // Bring up choose default SMS subscription dialog right now
9606 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9607 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9608 mApp.startActivity(intent);
9609 }
chen xud5ca2d52019-05-28 15:20:57 -07009610
9611 @Override
9612 public String getMmsUAProfUrl(int subId) {
9613 //TODO investigate if this API should require proper permission check in R b/133791609
9614 final long identity = Binder.clearCallingIdentity();
9615 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009616 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9617 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9618 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9619 return carrierUAProfUrl;
9620 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009621 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9622 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009623 } finally {
9624 Binder.restoreCallingIdentity(identity);
9625 }
9626 }
9627
9628 @Override
9629 public String getMmsUserAgent(int subId) {
9630 //TODO investigate if this API should require proper permission check in R b/133791609
9631 final long identity = Binder.clearCallingIdentity();
9632 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009633 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9634 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9635 if (!TextUtils.isEmpty(carrierUserAgent)) {
9636 return carrierUserAgent;
9637 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009638 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9639 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 }
Jack Yub07d4972019-05-28 16:12:25 -07009644
9645 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009646 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9647 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009648
Jack Yub07d4972019-05-28 16:12:25 -07009649 final long identity = Binder.clearCallingIdentity();
9650 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009651 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009652 if (phone == null) return false;
9653
Hall Liua62f5da2020-09-25 10:42:19 -07009654 switch (policy) {
9655 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9656 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9657 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9658 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9659 default:
9660 throw new IllegalArgumentException(policy + " is not a valid policy");
9661 }
Jack Yub07d4972019-05-28 16:12:25 -07009662 } finally {
9663 Binder.restoreCallingIdentity(identity);
9664 }
9665 }
9666
9667 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009668 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009669 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009670 enforceModifyPermission();
9671
changbettyd5c246e2019-12-24 15:40:37 +08009672 final long identity = Binder.clearCallingIdentity();
9673 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009674 Phone phone = getPhone(subscriptionId);
9675 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009676
Hall Liua62f5da2020-09-25 10:42:19 -07009677 switch (policy) {
9678 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9679 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9680 break;
9681 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9682 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9683 break;
9684 default:
9685 throw new IllegalArgumentException(policy + " is not a valid policy");
9686 }
changbettyd5c246e2019-12-24 15:40:37 +08009687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690 }
9691
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009692 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009693 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009694 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9695 * otherwise.
9696 */
9697 @Override
9698 public void setCepEnabled(boolean isCepEnabled) {
9699 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9700
9701 final long identity = Binder.clearCallingIdentity();
9702 try {
9703 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9704 for (Phone phone : PhoneFactory.getPhones()) {
9705 Phone defaultPhone = phone.getImsPhone();
9706 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9707 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9708 ImsPhoneCallTracker imsPhoneCallTracker =
9709 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9710 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9711 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9712 + imsPhone.getMsisdn());
9713 }
9714 }
9715 } finally {
9716 Binder.restoreCallingIdentity(identity);
9717 }
9718 }
allenwtsu46dcc572020-01-08 18:24:03 +08009719
9720 /**
9721 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9722 *
9723 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9724 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9725 * before being read.
9726 */
9727 @Override
9728 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9729 isCompressed) {
9730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9731 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009732 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9733 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9734 }
9735 if (!isImsAvailableOnDevice()) {
9736 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9737 "IMS not available on device.");
9738 }
9739
9740 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009741 try {
Hui Wang761a6682020-10-31 05:12:53 +00009742 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9743 } finally {
9744 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009745 }
9746 }
zoey chene02881a2019-12-30 16:11:23 +08009747
9748 @Override
9749 public boolean isIccLockEnabled(int subId) {
9750 enforceReadPrivilegedPermission("isIccLockEnabled");
9751
9752 // Now that all security checks passes, perform the operation as ourselves.
9753 final long identity = Binder.clearCallingIdentity();
9754 try {
9755 Phone phone = getPhone(subId);
9756 if (phone != null && phone.getIccCard() != null) {
9757 return phone.getIccCard().getIccLockEnabled();
9758 } else {
9759 return false;
9760 }
9761 } finally {
9762 Binder.restoreCallingIdentity(identity);
9763 }
9764 }
9765
9766 /**
9767 * Set the ICC pin lock enabled or disabled.
9768 *
9769 * @return an integer representing the status of IccLock enabled or disabled in the following
9770 * three cases:
9771 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9772 * successfully.
9773 * - Positive number and zero for remaining password attempts.
9774 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9775 *
9776 */
9777 @Override
9778 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9779 enforceModifyPermission();
9780
9781 Phone phone = getPhone(subId);
9782 if (phone == null) {
9783 return 0;
9784 }
9785 // Now that all security checks passes, perform the operation as ourselves.
9786 final long identity = Binder.clearCallingIdentity();
9787 try {
9788 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9789 new Pair<Boolean, String>(enabled, password), phone, null);
9790 return attemptsRemaining;
9791
9792 } catch (Exception e) {
9793 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9794 } finally {
9795 Binder.restoreCallingIdentity(identity);
9796 }
9797 return 0;
9798 }
9799
9800 /**
9801 * Change the ICC password used in ICC pin lock.
9802 *
9803 * @return an integer representing the status of IccLock changed in the following three cases:
9804 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9805 * - Positive number and zero for remaining password attempts.
9806 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9807 *
9808 */
9809 @Override
9810 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9811 enforceModifyPermission();
9812
9813 Phone phone = getPhone(subId);
9814 if (phone == null) {
9815 return 0;
9816 }
9817 // Now that all security checks passes, perform the operation as ourselves.
9818 final long identity = Binder.clearCallingIdentity();
9819 try {
9820 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9821 new Pair<String, String>(oldPassword, newPassword), phone, null);
9822 return attemptsRemaining;
9823
9824 } catch (Exception e) {
9825 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9826 } finally {
9827 Binder.restoreCallingIdentity(identity);
9828 }
9829 return 0;
9830 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009831
9832 /**
9833 * Request for receiving user activity notification
9834 */
9835 @Override
9836 public void requestUserActivityNotification() {
9837 if (!mNotifyUserActivity.get()
9838 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9839 mNotifyUserActivity.set(true);
9840 }
9841 }
9842
9843 /**
9844 * Called when userActivity is signalled in the power manager.
9845 * This is safe to call from any thread, with any window manager locks held or not.
9846 */
9847 @Override
9848 public void userActivity() {
9849 // ***************************************
9850 // * Inherited from PhoneWindowManager *
9851 // ***************************************
9852 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9853 // WITH ITS LOCKS HELD.
9854 //
9855 // This code must be VERY careful about the locks
9856 // it acquires.
9857 // In fact, the current code acquires way too many,
9858 // and probably has lurking deadlocks.
9859
9860 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9861 throw new SecurityException("Only the OS may call notifyUserActivity()");
9862 }
9863
9864 if (mNotifyUserActivity.getAndSet(false)) {
9865 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9866 USER_ACTIVITY_NOTIFICATION_DELAY);
9867 }
9868 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009869
9870 @Override
9871 public boolean canConnectTo5GInDsdsMode() {
9872 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9873 }
Jack Yud10cdd42020-09-28 20:28:01 -07009874
9875 @Override
9876 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9877 String callingFeatureId) {
9878 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9879 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9880 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9881 }
9882
9883 Phone phone = getPhone(subId);
9884 if (phone == null) {
9885 throw new RuntimeException("phone is not available");
9886 }
9887 // Now that all security checks passes, perform the operation as ourselves.
9888 final long identity = Binder.clearCallingIdentity();
9889 try {
9890 return phone.getEquivalentHomePlmns();
9891 } finally {
9892 Binder.restoreCallingIdentity(identity);
9893 }
9894 }
Daniel Bright59e67312020-11-13 11:49:37 -08009895
9896 @Override
9897 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009898 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9899 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009900 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009901 if (radioInterfaceCapabilities == null) {
9902 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009903 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009904 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009905 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009906
Hui Wang641e81c2020-10-12 12:14:23 -07009907 @Override
9908 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9909 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009910 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9911 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9912 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9913 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9914 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009915 if (DBG) {
9916 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9917 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9918 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9919 }
9920
9921 if (!SubscriptionManager.isValidSubscriptionId(subId)
9922 || appType < TelephonyManager.APPTYPE_UNKNOWN
9923 || appType > TelephonyManager.APPTYPE_ISIM
9924 || nafUrl == null || securityProtocol == null || callback == null) {
9925 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9926 if (callback != null) {
9927 try {
9928 callback.onAuthenticationFailure(
9929 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9930 } catch (RemoteException exception) {
9931 log("Fail to notify onAuthenticationFailure due to " + exception);
9932 }
9933 return;
9934 }
9935 }
9936
9937 final long token = Binder.clearCallingIdentity();
9938 try {
9939 getGbaManager(subId).bootstrapAuthenticationRequest(
9940 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9941 forceBootStrapping, callback));
9942 } finally {
9943 Binder.restoreCallingIdentity(token);
9944 }
9945 }
9946
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009947 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009948 * Attempts to set the radio power state for all phones for thermal reason.
9949 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009950 * requested radio power state will actually be set. See {@link
9951 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9952 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009953 * @param enable {@code true} if trying to turn radio on.
9954 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9955 * false}.
9956 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009957 private boolean setRadioPowerForThermal(boolean enable) {
9958 boolean isPhoneAvailable = false;
9959 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9960 Phone phone = PhoneFactory.getPhone(i);
9961 if (phone != null) {
9962 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9963 isPhoneAvailable = true;
9964 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009965 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009966
9967 // return true if successfully informed the phone object about the thermal radio power
9968 // request.
9969 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009970 }
9971
9972 private int handleDataThrottlingRequest(int subId,
9973 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009974 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9975 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9976 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9977 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9978 throw new IllegalArgumentException("modem does not support data throttling");
9979 }
9980
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009981 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9982 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009983 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009984 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9985 }
9986
9987 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9988
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009989 if (isDataThrottlingSupported) {
9990 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009991 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009992 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9993 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9994 } else if (thermalMitigationResult
9995 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009996 log("Modem likely does not support data throttling on secondary carrier. Data " +
9997 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9998 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009999 }
10000 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010001 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010002
10003 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010004 }
10005
Jack Nudelman644b91a2021-03-12 14:09:48 -080010006 private static List<String> getThermalMitigationAllowlist(Context context) {
10007 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10008 for (String pckg : context.getResources()
10009 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10010 sThermalMitigationAllowlistedPackages.add(pckg);
10011 }
10012 }
10013
10014 return sThermalMitigationAllowlistedPackages;
10015 }
10016
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010017 private boolean isAnyPhoneInEmergencyState() {
10018 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10019 if (tm.isInEmergencyCall()) {
10020 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10021 return true;
10022 }
10023 for (Phone phone : PhoneFactory.getPhones()) {
10024 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10025 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10026 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10027 + phone.isInEcm());
10028 return true;
10029 }
10030 }
10031
10032 return false;
10033 }
10034
Jack Nudelman644b91a2021-03-12 14:09:48 -080010035 /**
10036 * Used by shell commands to add an authorized package name for thermal mitigation.
10037 * @param packageName name of package to be allowlisted
10038 * @param context
10039 */
10040 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10041 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10042 sThermalMitigationAllowlistedPackages.add(packageName);
10043 }
10044
10045 /**
10046 * Used by shell commands to remove an authorized package name for thermal mitigation.
10047 * @param packageName name of package to remove from allowlist
10048 * @param context
10049 */
10050 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10051 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10052 sThermalMitigationAllowlistedPackages.remove(packageName);
10053 }
10054
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010055 /**
10056 * Thermal mitigation request to control functionalities at modem.
10057 *
10058 * @param subId the id of the subscription.
10059 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010060 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010061 *
10062 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10063 */
10064 @Override
10065 @ThermalMitigationResult
10066 public int sendThermalMitigationRequest(
10067 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010068 ThermalMitigationRequest thermalMitigationRequest,
10069 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010070 enforceModifyPermission();
10071
Jack Nudelman644b91a2021-03-12 14:09:48 -080010072 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10073 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10074 .contains(callingPackage)) {
10075 throw new SecurityException("Calling package must be configured in the device config. "
10076 + "calling package: " + callingPackage);
10077 }
10078
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010079 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10080 final long identity = Binder.clearCallingIdentity();
10081
10082 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10083 try {
10084 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10085 switch (thermalMitigationAction) {
10086 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10087 thermalMitigationResult =
10088 handleDataThrottlingRequest(subId,
10089 thermalMitigationRequest.getDataThrottlingRequest());
10090 break;
10091 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10092 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10093 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10094 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10095 }
10096
10097 // Ensure that radio is on. If not able to power on due to phone being
10098 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010099 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010100 thermalMitigationResult =
10101 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10102 break;
10103 }
10104
10105 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10106 false);
10107 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10108 break;
10109 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10110 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10111 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10112 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10113 }
10114
10115 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10116 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010117 Phone phone = getPhone(subId);
10118 if (phone == null) {
10119 thermalMitigationResult =
10120 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10121 break;
10122 }
10123
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010124 TelephonyConnectionService service =
10125 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010126 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010127 Log.e(LOG_TAG, "An emergency call is pending");
10128 thermalMitigationResult =
10129 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10130 break;
10131 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010132 thermalMitigationResult =
10133 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10134 break;
10135 }
10136 } else {
10137 thermalMitigationResult =
10138 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10139 break;
10140 }
10141
10142 // Turn radio off. If not able to power off due to phone being unavailable,
10143 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010144 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010145 thermalMitigationResult =
10146 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10147 break;
10148 }
10149 thermalMitigationResult =
10150 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10151 break;
10152 default:
10153 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10154 + "not exist. Requested action: " + thermalMitigationAction);
10155 }
10156 } catch (IllegalArgumentException e) {
10157 throw e;
10158 } catch (Exception e) {
10159 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10160 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10161 } finally {
10162 Binder.restoreCallingIdentity(identity);
10163 }
10164
10165 if (DBG) {
10166 log("thermalMitigationRequest returning with thermalMitigationResult: "
10167 + thermalMitigationResult);
10168 }
10169
10170 return thermalMitigationResult;
10171 }
Hui Wang641e81c2020-10-12 12:14:23 -070010172
10173 /**
10174 * Set the GbaService Package Name that Telephony will bind to.
10175 *
10176 * @param subId The sim that the GbaService is associated with.
10177 * @param packageName The name of the package to be replaced with.
10178 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10179 */
10180 @Override
10181 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10182 enforceModifyPermission();
10183
10184 final long identity = Binder.clearCallingIdentity();
10185 try {
10186 return getGbaManager(subId).overrideServicePackage(packageName);
10187 } finally {
10188 Binder.restoreCallingIdentity(identity);
10189 }
10190 }
10191
10192 /**
10193 * Return the package name of the currently bound GbaService.
10194 *
10195 * @param subId The sim that the GbaService is associated with.
10196 * @return the package name of the GbaService configuration, null if GBA is not supported.
10197 */
10198 @Override
10199 public String getBoundGbaService(int subId) {
10200 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10201
10202 final long identity = Binder.clearCallingIdentity();
10203 try {
10204 return getGbaManager(subId).getServicePackage();
10205 } finally {
10206 Binder.restoreCallingIdentity(identity);
10207 }
10208 }
10209
10210 /**
10211 * Set the release time for telephony to unbind GbaService.
10212 *
10213 * @param subId The sim that the GbaService is associated with.
10214 * @param interval The release time to unbind GbaService by millisecond.
10215 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10216 */
10217 @Override
10218 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10219 enforceModifyPermission();
10220
10221 final long identity = Binder.clearCallingIdentity();
10222 try {
10223 return getGbaManager(subId).overrideReleaseTime(interval);
10224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
10228
10229 /**
10230 * Return the release time for telephony to unbind GbaService.
10231 *
10232 * @param subId The sim that the GbaService is associated with.
10233 * @return The release time to unbind GbaService by millisecond.
10234 */
10235 @Override
10236 public int getGbaReleaseTime(int subId) {
10237 enforceReadPrivilegedPermission("getGbaReleaseTime");
10238
10239 final long identity = Binder.clearCallingIdentity();
10240 try {
10241 return getGbaManager(subId).getReleaseTime();
10242 } finally {
10243 Binder.restoreCallingIdentity(identity);
10244 }
10245 }
10246
10247 private GbaManager getGbaManager(int subId) {
10248 GbaManager instance = GbaManager.getInstance(subId);
10249 if (instance == null) {
10250 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10251 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10252 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10253 }
10254 return instance;
10255 }
Hui Wang761a6682020-10-31 05:12:53 +000010256
10257 /**
10258 * indicate whether the device and the carrier can support
10259 * RCS VoLTE single registration.
10260 */
10261 @Override
10262 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010263 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10264 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10265 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10266 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010267
10268 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10269 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10270 }
10271
10272 final long identity = Binder.clearCallingIdentity();
10273 try {
10274 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10275 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010276 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10277 if (isCapable != null) {
10278 return isCapable;
10279 }
Hui Wang761a6682020-10-31 05:12:53 +000010280 }
Hui Wang67af90e2021-06-04 16:57:15 -070010281 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10282 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010283 } finally {
10284 Binder.restoreCallingIdentity(identity);
10285 }
10286 }
10287
10288 /**
10289 * Register RCS provisioning callback.
10290 */
10291 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010292 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010293 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010294 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010295 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010296 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10297 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010298
10299 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10300 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10301 }
10302 if (!isImsAvailableOnDevice()) {
10303 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10304 "IMS not available on device.");
10305 }
10306
10307 final long identity = Binder.clearCallingIdentity();
10308 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010309 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010310 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010311 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10312 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010313 }
Hui Wang761a6682020-10-31 05:12:53 +000010314 } finally {
10315 Binder.restoreCallingIdentity(identity);
10316 }
10317 }
10318
10319 /**
10320 * Unregister RCS provisioning callback.
10321 */
10322 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010323 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010324 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010325 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010326 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010327 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10328 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010329
10330 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10331 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10332 }
10333 if (!isImsAvailableOnDevice()) {
10334 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10335 "IMS not available on device.");
10336 }
10337
10338 final long identity = Binder.clearCallingIdentity();
10339 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010340 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010341 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010342 } finally {
10343 Binder.restoreCallingIdentity(identity);
10344 }
10345 }
10346
10347 /**
10348 * trigger RCS reconfiguration.
10349 */
10350 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010351 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10352 "triggerRcsReconfiguration",
10353 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010354
10355 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10356 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10357 }
10358 if (!isImsAvailableOnDevice()) {
10359 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10360 "IMS not available on device.");
10361 }
10362
10363 final long identity = Binder.clearCallingIdentity();
10364 try {
10365 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369 }
10370
10371 /**
10372 * Provide the client configuration parameters of the RCS application.
10373 */
10374 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010375 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10376 "setRcsClientConfiguration",
10377 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010378
10379 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10380 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10381 }
10382 if (!isImsAvailableOnDevice()) {
10383 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10384 "IMS not available on device.");
10385 }
10386
10387 final long identity = Binder.clearCallingIdentity();
10388
10389 try {
10390 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10391 if (configBinder == null) {
10392 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010393 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10394 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010395 } else {
10396 configBinder.setRcsClientConfiguration(rcc);
10397 }
10398 } catch (RemoteException e) {
10399 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010400 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10401 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405 }
10406
10407 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010408 * Enables or disables the test mode for RCS VoLTE single registration.
10409 */
10410 @Override
10411 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10412 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10413 "setRcsSingleRegistrationTestModeEnabled");
10414
10415 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10416 }
10417
10418 /**
10419 * Gets the test mode for RCS VoLTE single registration.
10420 */
10421 @Override
10422 public boolean getRcsSingleRegistrationTestModeEnabled() {
10423 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10424 "getRcsSingleRegistrationTestModeEnabled");
10425
10426 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10427 }
10428
10429 /**
Hui Wang761a6682020-10-31 05:12:53 +000010430 * Overrides the config of RCS VoLTE single registration enabled for the device.
10431 */
10432 @Override
10433 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10434 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10435 "setDeviceSingleRegistrationEnabledOverride");
10436 enforceModifyPermission();
10437
10438 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10439 : Boolean.parseBoolean(enabledStr);
10440 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010441 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010442 }
10443
10444 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010445 * Sends a device to device communication message. Only usable via shell.
10446 * @param message message to send.
10447 * @param value message value.
10448 */
10449 @Override
10450 public void sendDeviceToDeviceMessage(int message, int value) {
10451 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010452 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010453 enforceModifyPermission();
10454
10455 final long identity = Binder.clearCallingIdentity();
10456 try {
10457 TelephonyConnectionService service =
10458 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10459 if (service == null) {
10460 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10461 return;
10462 }
10463 service.sendTestDeviceToDeviceMessage(message, value);
10464 } finally {
10465 Binder.restoreCallingIdentity(identity);
10466 }
10467 }
10468
Tyler Gunnbabbda02021-02-10 11:05:02 -080010469 /**
10470 * Sets the specified device to device transport active.
10471 * @param transport The transport to set active.
10472 */
10473 @Override
10474 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10475 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10476 "setActiveDeviceToDeviceTransport");
10477 enforceModifyPermission();
10478
10479 final long identity = Binder.clearCallingIdentity();
10480 try {
10481 TelephonyConnectionService service =
10482 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10483 if (service == null) {
10484 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10485 return;
10486 }
10487 service.setActiveDeviceToDeviceTransport(transport);
10488 } finally {
10489 Binder.restoreCallingIdentity(identity);
10490 }
10491 }
Tyler Gunn92479152021-01-20 16:30:10 -080010492
Tyler Gunnd4575212021-05-03 14:46:49 -070010493 @Override
10494 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10495 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10496 "setDeviceToDeviceForceEnabled");
10497
10498 final long identity = Binder.clearCallingIdentity();
10499 try {
10500 Arrays.stream(PhoneFactory.getPhones()).forEach(
10501 p -> {
10502 Phone thePhone = p.getImsPhone();
10503 if (thePhone != null && thePhone instanceof ImsPhone) {
10504 ImsPhone imsPhone = (ImsPhone) thePhone;
10505 CallTracker tracker = imsPhone.getCallTracker();
10506 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10507 ImsPhoneCallTracker imsPhoneCallTracker =
10508 (ImsPhoneCallTracker) tracker;
10509 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10510 }
10511 }
10512 }
10513 );
10514 } finally {
10515 Binder.restoreCallingIdentity(identity);
10516 }
10517 }
10518
Tyler Gunn92479152021-01-20 16:30:10 -080010519 /**
Hui Wang761a6682020-10-31 05:12:53 +000010520 * Gets the config of RCS VoLTE single registration enabled for the device.
10521 */
10522 @Override
10523 public boolean getDeviceSingleRegistrationEnabled() {
10524 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10525 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10526 }
10527
10528 /**
10529 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10530 */
10531 @Override
10532 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10533 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10534 "setCarrierSingleRegistrationEnabledOverride");
10535 enforceModifyPermission();
10536
10537 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10538 : Boolean.parseBoolean(enabledStr);
10539 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10540 subId, enabled);
10541 }
10542
10543 /**
10544 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10545 */
10546 @Override
10547 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10548 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10549 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10550 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010551
10552 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010553 * Overrides the ims feature validation result
10554 */
10555 @Override
10556 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10557 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10558 "setImsFeatureValidationOverride");
10559
10560 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10561 : Boolean.parseBoolean(enabledStr);
10562 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10563 subId, enabled);
10564 }
10565
10566 /**
10567 * Gets the ims feature validation override value
10568 */
10569 @Override
10570 public boolean getImsFeatureValidationOverride(int subId) {
10571 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10572 "getImsFeatureValidationOverride");
10573 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10574 }
10575
10576 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010577 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10578 * their mobile plan.
10579 */
10580 @Override
10581 public String getMobileProvisioningUrl() {
10582 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10583 final long identity = Binder.clearCallingIdentity();
10584 try {
10585 return getDefaultPhone().getMobileProvisioningUrl();
10586 } finally {
10587 Binder.restoreCallingIdentity(identity);
10588 }
10589 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010590
James.cf Linbcdf8b32021-01-14 16:44:13 +080010591 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010592 * Get the EAB contact from the EAB database.
10593 */
10594 @Override
10595 public String getContactFromEab(String contact) {
10596 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10597 enforceModifyPermission();
10598 final long identity = Binder.clearCallingIdentity();
10599 try {
10600 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10601 } finally {
10602 Binder.restoreCallingIdentity(identity);
10603 }
10604 }
10605
10606 /**
Calvin Pana1434322021-07-01 19:27:01 +080010607 * Get the EAB capability from the EAB database.
10608 */
10609 @Override
10610 public String getCapabilityFromEab(String contact) {
10611 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10612 enforceModifyPermission();
10613 final long identity = Binder.clearCallingIdentity();
10614 try {
10615 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10616 } finally {
10617 Binder.restoreCallingIdentity(identity);
10618 }
10619 }
10620
10621 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010622 * Remove the EAB contacts from the EAB database.
10623 */
10624 @Override
10625 public int removeContactFromEab(int subId, String contacts) {
10626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10627 enforceModifyPermission();
10628 final long identity = Binder.clearCallingIdentity();
10629 try {
10630 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10631 } finally {
10632 Binder.restoreCallingIdentity(identity);
10633 }
10634 }
10635
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010636 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010637 public boolean getDeviceUceEnabled() {
10638 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10639 final long identity = Binder.clearCallingIdentity();
10640 try {
10641 return mApp.getDeviceUceEnabled();
10642 } finally {
10643 Binder.restoreCallingIdentity(identity);
10644 }
10645 }
10646
10647 @Override
10648 public void setDeviceUceEnabled(boolean isEnabled) {
10649 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10650 final long identity = Binder.clearCallingIdentity();
10651 try {
10652 mApp.setDeviceUceEnabled(isEnabled);
10653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
10657
Brad Ebinger14d467f2021-02-12 06:18:28 +000010658 /**
10659 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10660 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10661 */
10662 // Used for SHELL command only right now.
10663 @Override
10664 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10665 List<String> featureTags) {
10666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10667 "addUceRegistrationOverrideShell");
10668 final long identity = Binder.clearCallingIdentity();
10669 try {
10670 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10671 new ArraySet<>(featureTags));
10672 } catch (ImsException e) {
10673 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10674 } finally {
10675 Binder.restoreCallingIdentity(identity);
10676 }
10677 }
10678
10679 /**
10680 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10681 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10682 */
10683 // Used for SHELL command only right now.
10684 @Override
10685 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10686 List<String> featureTags) {
10687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10688 "removeUceRegistrationOverrideShell");
10689 final long identity = Binder.clearCallingIdentity();
10690 try {
10691 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10692 new ArraySet<>(featureTags));
10693 } catch (ImsException e) {
10694 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10695 } finally {
10696 Binder.restoreCallingIdentity(identity);
10697 }
10698 }
10699
10700 /**
10701 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10702 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10703 */
10704 // Used for SHELL command only right now.
10705 @Override
10706 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10707 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10708 "clearUceRegistrationOverrideShell");
10709 final long identity = Binder.clearCallingIdentity();
10710 try {
10711 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10712 } catch (ImsException e) {
10713 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10714 } finally {
10715 Binder.restoreCallingIdentity(identity);
10716 }
10717 }
10718
10719 /**
10720 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10721 */
10722 // Used for SHELL command only right now.
10723 @Override
10724 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10725 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10726 "getLatestRcsContactUceCapabilityShell");
10727 final long identity = Binder.clearCallingIdentity();
10728 try {
10729 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10730 } catch (ImsException e) {
10731 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10732 } finally {
10733 Binder.restoreCallingIdentity(identity);
10734 }
10735 }
10736
10737 /**
10738 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10739 * device does not have an active PUBLISH.
10740 */
10741 // Used for SHELL command only right now.
10742 @Override
10743 public String getLastUcePidfXmlShell(int subId) {
10744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10745 final long identity = Binder.clearCallingIdentity();
10746 try {
10747 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10748 } catch (ImsException e) {
10749 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10750 } finally {
10751 Binder.restoreCallingIdentity(identity);
10752 }
10753 }
10754
James.cf Line8713a42021-04-29 16:04:26 +080010755 /**
10756 * Remove UCE requests cannot be sent to the network status.
10757 */
10758 // Used for SHELL command only right now.
10759 @Override
10760 public boolean removeUceRequestDisallowedStatus(int subId) {
10761 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10762 final long identity = Binder.clearCallingIdentity();
10763 try {
10764 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10765 } catch (ImsException e) {
10766 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10767 } finally {
10768 Binder.restoreCallingIdentity(identity);
10769 }
10770 }
10771
James.cf Lin0fc71b02021-05-25 01:37:38 +080010772 /**
10773 * Remove UCE requests cannot be sent to the network status.
10774 */
10775 // Used for SHELL command only.
10776 @Override
10777 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10779 final long identity = Binder.clearCallingIdentity();
10780 try {
10781 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10782 } catch (ImsException e) {
10783 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10784 } finally {
10785 Binder.restoreCallingIdentity(identity);
10786 }
10787 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010788
James.cf Lin4b784aa2021-01-31 03:25:15 +080010789 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010790 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10791 String callingPackage) {
10792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10793 mApp, subId, "setSignalStrengthUpdateRequest");
10794
10795 final int callingUid = Binder.getCallingUid();
10796 // Verify that tha callingPackage belongs to the calling UID
10797 mApp.getSystemService(AppOpsManager.class)
10798 .checkPackage(callingUid, callingPackage);
10799
Rambo Wang3607f502021-02-01 21:51:40 -080010800 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010801
10802 final long identity = Binder.clearCallingIdentity();
10803 try {
10804 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10805 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10806
10807 if (result instanceof IllegalStateException) {
10808 throw (IllegalStateException) result;
10809 }
10810 } finally {
10811 Binder.restoreCallingIdentity(identity);
10812 }
10813 }
10814
10815 @Override
10816 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10817 String callingPackage) {
10818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10819 mApp, subId, "clearSignalStrengthUpdateRequest");
10820
10821 final int callingUid = Binder.getCallingUid();
10822 // Verify that tha callingPackage belongs to the calling UID
10823 mApp.getSystemService(AppOpsManager.class)
10824 .checkPackage(callingUid, callingPackage);
10825
10826 final long identity = Binder.clearCallingIdentity();
10827 try {
10828 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10829 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10830
10831 if (result instanceof IllegalStateException) {
10832 throw (IllegalStateException) result;
10833 }
10834 } finally {
10835 Binder.restoreCallingIdentity(identity);
10836 }
10837 }
10838
Rambo Wang3607f502021-02-01 21:51:40 -080010839 private static void validateSignalStrengthUpdateRequest(Context context,
10840 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010841 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10842 // phone/system process do not have further restriction on request
10843 return;
10844 }
10845
10846 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010847 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010848 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010849 context.enforceCallingOrSelfPermission(
10850 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10851 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010852 }
10853
10854 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10855 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10856 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10857 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10858 || info.isEnabled()) {
10859 throw new IllegalArgumentException(
10860 "Only system can set hide fields in SignalThresholdInfo");
10861 }
10862
10863 // Thresholds length for each RAN need in range. This has been validated in
10864 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10865 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10866 final int[] thresholds = info.getThresholds();
10867 Objects.requireNonNull(thresholds);
10868 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10869 || thresholds.length
10870 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10871 throw new IllegalArgumentException(
10872 "thresholds length is out of range: " + thresholds.length);
10873 }
10874 }
10875 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010876
10877 /**
10878 * Gets the current phone capability.
10879 *
10880 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10881 * @return the PhoneCapability which describes the data connection capability of modem.
10882 * It's used to evaluate possible phone config change, for example from single
10883 * SIM device to multi-SIM device.
10884 */
10885 @Override
10886 public PhoneCapability getPhoneCapability() {
10887 enforceReadPrivilegedPermission("getPhoneCapability");
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
10890 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10891 } finally {
10892 Binder.restoreCallingIdentity(identity);
10893 }
10894 }
Michele Berionne5e411512020-11-13 02:36:59 +000010895
10896 /**
10897 * Prepare TelephonyManager for an unattended reboot. The reboot is
10898 * required to be done shortly after the API is invoked.
10899 */
10900 @Override
10901 @TelephonyManager.PrepareUnattendedRebootResult
10902 public int prepareForUnattendedReboot() {
10903 enforceRebootPermission();
10904
10905 final long identity = Binder.clearCallingIdentity();
10906 try {
10907 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10908 } finally {
10909 Binder.restoreCallingIdentity(identity);
10910 }
10911 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010912
10913 /**
10914 * Request to get the current slicing configuration including URSP rules and
10915 * NSSAIs (configured, allowed and rejected).
10916 *
10917 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10918 */
10919 @Override
10920 public void getSlicingConfig(ResultReceiver callback) {
10921 enforceReadPrivilegedPermission("getSlicingConfig");
10922
10923 final long identity = Binder.clearCallingIdentity();
10924 try {
10925 Phone phone = getDefaultPhone();
10926 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10927 } finally {
10928 Binder.restoreCallingIdentity(identity);
10929 }
10930 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000010931
10932 /**
10933 * Register an IMS connection state callback
10934 */
10935 @Override
10936 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
10937 String callingPackage) {
10938 if (feature == ImsFeature.FEATURE_MMTEL) {
10939 // ImsMmTelManager
10940 // The following also checks READ_PRIVILEGED_PHONE_STATE.
10941 TelephonyPermissions
10942 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
10943 mApp, subId, "registerImsStateCallback");
10944 } else if (feature == ImsFeature.FEATURE_RCS) {
10945 // ImsRcsManager or SipDelegateManager
10946 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10947 Binder.getCallingUid(), "registerImsStateCallback",
10948 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
10949 Manifest.permission.READ_PRECISE_PHONE_STATE,
10950 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
10951 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
10952 }
10953
10954 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
10955 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10956 "IMS not available on device.");
10957 }
10958
10959 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
10960 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
10961 }
10962
10963 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
10964 if (controller == null) {
10965 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10966 "IMS not available on device.");
10967 }
10968
10969 if (callingPackage == null) {
10970 callingPackage = getCurrentPackageName();
10971 }
10972
10973 final long token = Binder.clearCallingIdentity();
10974 try {
10975 int slotId = getSlotIndexOrException(subId);
10976 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
10977 } catch (ImsException e) {
10978 throw new ServiceSpecificException(e.getCode());
10979 } finally {
10980 Binder.restoreCallingIdentity(token);
10981 }
10982 }
10983
10984 /**
10985 * Unregister an IMS connection state callback
10986 */
10987 @Override
10988 public void unregisterImsStateCallback(IImsStateCallback cb) {
10989 final long token = Binder.clearCallingIdentity();
10990 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
10991 if (controller == null) {
10992 return;
10993 }
10994 try {
10995 controller.unregisterImsStateCallback(cb);
10996 } finally {
10997 Binder.restoreCallingIdentity(token);
10998 }
10999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011000}