blob: f9cc52eaeb6ca53025841d9199f1165a991f02f0 [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;
sandeepjs0a502c42021-09-27 15:34:44 +000030import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080032import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000033import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080034import android.app.role.RoleManager;
sandeepjs0a502c42021-09-27 15:34:44 +000035import android.compat.annotation.ChangeId;
36import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070037import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070038import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.content.Context;
40import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070041import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070042import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080043import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070044import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.net.Uri;
46import android.os.AsyncResult;
47import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080048import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Bundle;
50import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Looper;
53import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080055import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070056import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070057import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080058import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080059import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070060import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070061import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080062import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070064import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070066import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070067import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080068import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070069import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090070import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080071import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080072import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070073import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070074import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080075import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080076import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070077import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080078import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070079import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080080import android.telephony.CellIdentityCdma;
81import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070083import android.telephony.CellInfoGsm;
84import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070085import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070087import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070088import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070089import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080090import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070091import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080092import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070093import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080094import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080095import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070096import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080097import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080099import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800100import android.telephony.SignalStrengthUpdateRequest;
101import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800102import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800104import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700105import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800107import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800109import android.telephony.UiccCardInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000110import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000111import android.telephony.UiccSlotInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000112import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700113import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700114import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800115import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800116import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800117import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700118import android.telephony.gba.GbaAuthRequest;
119import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700120import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000122import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000123import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700124import android.telephony.ims.RegistrationManager;
joonhunshin2c3e4232021-11-28 07:32:01 +0000125import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700126import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800127import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700128import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000131import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700132import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800133import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800134import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800136import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700139import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800141import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142
Andrew Lee312e8172014-10-23 17:01:36 -0700143import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800144import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800145import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800146import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800147import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700149import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700150import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800151import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700152import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800154import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700156import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800157import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800158import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800159import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700160import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +0000161import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800163import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800165import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700166import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700167import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700168import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700170import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800171import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700172import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700173import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700174import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700175import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800176import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800177import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700178import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700179import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700180import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800181import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800182import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700184import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700186import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800187import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700188import com.android.internal.telephony.imsphone.ImsPhone;
189import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800190import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700191import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700192import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800193import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700194import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800195import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700196import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000199import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800200import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000201import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800202import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700203import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700204import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800205import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800206import com.android.phone.callcomposer.CallComposerPictureManager;
207import com.android.phone.callcomposer.CallComposerPictureTransfer;
208import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700209import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700210import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800211import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700212import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700213import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800214import com.android.services.telephony.TelecomAccountRegistry;
215import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800216import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800217
Hall Liu82694d52020-12-11 18:22:04 -0800218import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700219import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800220import java.io.IOException;
221import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700222import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800224import java.util.Arrays;
sandeepjs0a502c42021-09-27 15:34:44 +0000225import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800226import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800227import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800228import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100229import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800230import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700231import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800232import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800233import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800235import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800236import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238/**
239 * Implementation of the ITelephony interface.
240 */
Santos Cordon117fee72014-05-16 17:56:12 -0700241public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242 private static final String LOG_TAG = "PhoneInterfaceManager";
243 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
244 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800245 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246
247 // Message codes used with mMainThreadHandler
248 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700249 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
250 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700251 private static final int CMD_OPEN_CHANNEL = 9;
252 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
253 private static final int CMD_CLOSE_CHANNEL = 11;
254 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800255 private static final int CMD_NV_READ_ITEM = 13;
256 private static final int EVENT_NV_READ_ITEM_DONE = 14;
257 private static final int CMD_NV_WRITE_ITEM = 15;
258 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
259 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
260 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700261 private static final int CMD_RESET_MODEM_CONFIG = 19;
262 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800263 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
264 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800265 private static final int CMD_SEND_ENVELOPE = 25;
266 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000267 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
268 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700269 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
270 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
271 private static final int CMD_EXCHANGE_SIM_IO = 31;
272 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800273 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
274 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700275 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
276 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700277 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
278 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700279 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
280 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
281 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
282 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700283 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
284 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
285 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
286 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700287 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800288 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
289 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000290 private static final int CMD_SWITCH_SLOTS = 50;
291 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700292 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
293 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
294 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
295 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
296 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
297 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
298 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
299 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700300 private static final int CMD_GET_ALL_CELL_INFO = 60;
301 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
302 private static final int CMD_GET_CELL_LOCATION = 62;
303 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700304 private static final int CMD_MODEM_REBOOT = 64;
305 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700306 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
307 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800308 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
309 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700310 private static final int CMD_GET_MODEM_STATUS = 70;
311 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700312 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
313 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700314 private static final int CMD_ERASE_MODEM_CONFIG = 74;
315 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800316 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
317 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
318 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
319 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800320 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
321 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800322 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800323 private static final int CMD_GET_CALL_FORWARDING = 83;
324 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
325 private static final int CMD_SET_CALL_FORWARDING = 85;
326 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
327 private static final int CMD_GET_CALL_WAITING = 87;
328 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
329 private static final int CMD_SET_CALL_WAITING = 89;
330 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700331 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
332 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
333 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
334 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700335 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
336 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800337 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
338 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800339 private static final int CMD_SET_DATA_THROTTLING = 99;
340 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800341 private static final int CMD_SET_SIM_POWER = 101;
342 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800343 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
344 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
345 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
346 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800347 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
348 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000349 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800350 private static final int CMD_GET_SLICING_CONFIG = 110;
351 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800352 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700353 private static final int CMD_ENABLE_VONR = 113;
354 private static final int EVENT_ENABLE_VONR_DONE = 114;
355 private static final int CMD_IS_VONR_ENABLED = 115;
356 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800358 // Parameters of select command.
359 private static final int SELECT_COMMAND = 0xA4;
360 private static final int SELECT_P1 = 0x04;
361 private static final int SELECT_P2 = 0;
362 private static final int SELECT_P3 = 0x10;
363
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 /** The singleton instance. */
365 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800366 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367
Wink Saville3ab207e2014-11-20 13:07:20 -0800368 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800370 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700371 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700373 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800375 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700377 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800378 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379
Peter Wangdafb9ac2020-01-15 14:13:38 -0800380 /** User Activity */
381 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800382 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
383
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700384 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
385
Derek Tan97ebb422014-09-05 16:55:38 -0700386 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
387 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800388 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800389 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700390
Michelecea4cf22018-12-21 15:00:11 -0800391 // String to store multi SIM allowed
392 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
393
Derek Tan740e1672017-06-27 14:56:27 -0700394 // The AID of ISD-R.
395 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
396
yinxub1bed742017-04-17 11:45:04 -0700397 private NetworkScanRequestTracker mNetworkScanRequestTracker;
398
David Kelly5e06a7f2018-03-12 14:10:59 +0000399 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
400 private static final int MANUFACTURER_CODE_LENGTH = 8;
401
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800402 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800403 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800404
Derek Tan89e89d42014-07-08 17:00:10 -0700405 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700406 * Experiment flag to enable erase modem config on reset network, default value is false
407 */
408 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
409 "reset_network_erase_modem_config_enabled";
410
Rambo Wang0f050d82021-02-12 11:43:36 -0800411 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjs0a502c42021-09-27 15:34:44 +0000412 /**
413 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
414 * one ICCID active at the same time.
415 * Apps should use below API signatures if targeting SDK is T and beyond.
416 *
417 * @hide
418 */
419 @ChangeId
420 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
421 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800422
Naina Nallurid63128d2019-09-17 14:10:30 -0700423 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 * A request object to use for transmitting data to an ICC.
425 */
426 private static final class IccAPDUArgument {
427 public int channel, cla, command, p1, p2, p3;
428 public String data;
429
430 public IccAPDUArgument(int channel, int cla, int command,
431 int p1, int p2, int p3, String data) {
432 this.channel = channel;
433 this.cla = cla;
434 this.command = command;
435 this.p1 = p1;
436 this.p2 = p2;
437 this.p3 = p3;
438 this.data = data;
439 }
440 }
441
442 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700443 * A request object to use for transmitting data to an ICC.
444 */
445 private static final class ManualNetworkSelectionArgument {
446 public OperatorInfo operatorInfo;
447 public boolean persistSelection;
448
449 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
450 this.operatorInfo = operatorInfo;
451 this.persistSelection = persistSelection;
452 }
453 }
454
455 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
457 * request after sending. The main thread will notify the request when it is complete.
458 */
459 private static final class MainThreadRequest {
460 /** The argument to use for the request */
461 public Object argument;
462 /** The result of the request that is run on the main thread */
463 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800464 // The subscriber id that this request applies to. Defaults to
465 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
466 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467
Nathan Harold92bed182018-10-12 18:16:49 -0700468 // In cases where subId is unavailable, the caller needs to specify the phone.
469 public Phone phone;
470
vagdeviaf9a5b92018-08-15 16:01:53 -0700471 public WorkSource workSource;
472
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 public MainThreadRequest(Object argument) {
474 this.argument = argument;
475 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800476
Nathan Harold92bed182018-10-12 18:16:49 -0700477 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
478 this.argument = argument;
479 if (phone != null) {
480 this.phone = phone;
481 }
482 this.workSource = workSource;
483 }
484
vagdeviaf9a5b92018-08-15 16:01:53 -0700485 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800486 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800487 if (subId != null) {
488 this.subId = subId;
489 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700490 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 }
493
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800494 private static final class IncomingThirdPartyCallArgs {
495 public final ComponentName component;
496 public final String callId;
497 public final String callerDisplayName;
498
499 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
500 String callerDisplayName) {
501 this.component = component;
502 this.callId = callId;
503 this.callerDisplayName = callerDisplayName;
504 }
505 }
506
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 /**
508 * A handler that processes messages on the main thread in the phone process. Since many
509 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
510 * inbound binder threads to the main thread in the phone process. The Binder thread
511 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
512 * on, which will be notified when the operation completes and will contain the result of the
513 * request.
514 *
515 * <p>If a MainThreadRequest object is provided in the msg.obj field,
516 * note that request.result must be set to something non-null for the calling thread to
517 * unblock.
518 */
519 private final class MainThreadHandler extends Handler {
520 @Override
521 public void handleMessage(Message msg) {
522 MainThreadRequest request;
523 Message onCompleted;
524 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000525 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800527 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528
529 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 case CMD_HANDLE_USSD_REQUEST: {
531 request = (MainThreadRequest) msg.obj;
532 final Phone phone = getPhoneFromRequest(request);
533 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
534 String ussdRequest = ussdObject.first;
535 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700536
Pengquan Menga1bb6272018-09-06 09:59:22 -0700537 if (!isUssdApiAllowed(request.subId)) {
538 // Carrier does not support use of this API, return failure.
539 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
540 UssdResponse response = new UssdResponse(ussdRequest, null);
541 Bundle returnData = new Bundle();
542 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
543 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700544
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 request.result = true;
546 notifyRequester(request);
547 return;
548 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700549
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 try {
551 request.result = phone != null
552 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
553 } catch (CallStateException cse) {
554 request.result = false;
555 }
556 // Wake up the requesting thread
557 notifyRequester(request);
558 break;
pkanwar32d516d2016-10-14 19:37:38 -0700559 }
560
Yorke Lee716f67e2015-06-17 15:39:16 -0700561 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700563 final Phone phone = getPhoneFromRequest(request);
564 request.result = phone != null ?
565 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
566 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000575 uiccPort = getUiccPortFromRequest(request);
576 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 loge("iccTransmitApduLogicalChannel: No UICC");
578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
582 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000583 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 iccArgument.channel, iccArgument.cla, iccArgument.command,
585 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 ar = (AsyncResult) msg.obj;
592 request = (MainThreadRequest) ar.userObj;
593 if (ar.exception == null && ar.result != null) {
594 request.result = ar.result;
595 } else {
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
597 if (ar.result == null) {
598 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800599 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800601 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 } else {
603 loge("iccTransmitApduLogicalChannel: Unknown exception");
604 }
605 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 break;
608
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
610 request = (MainThreadRequest) msg.obj;
611 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000612 uiccPort = getUiccPortFromRequest(request);
613 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 loge("iccTransmitApduBasicChannel: No UICC");
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 } else {
618 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
619 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000620 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
622 iccArgument.p3, iccArgument.data, onCompleted);
623 }
624 break;
625
626 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
627 ar = (AsyncResult) msg.obj;
628 request = (MainThreadRequest) ar.userObj;
629 if (ar.exception == null && ar.result != null) {
630 request.result = ar.result;
631 } else {
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
633 if (ar.result == null) {
634 loge("iccTransmitApduBasicChannel: Empty response");
635 } else if (ar.exception instanceof CommandException) {
636 loge("iccTransmitApduBasicChannel: CommandException: " +
637 ar.exception);
638 } else {
639 loge("iccTransmitApduBasicChannel: Unknown exception");
640 }
641 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 break;
644
645 case CMD_EXCHANGE_SIM_IO:
646 request = (MainThreadRequest) msg.obj;
647 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000648 uiccPort = getUiccPortFromRequest(request);
649 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 loge("iccExchangeSimIO: No UICC");
651 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 } else {
654 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
655 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000656 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
658 iccArgument.data, onCompleted);
659 }
660 break;
661
662 case EVENT_EXCHANGE_SIM_IO_DONE:
663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result;
667 } else {
668 request.result = new IccIoResult(0x6f, 0, (byte[])null);
669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 break;
672
Derek Tan4d5e5c12014-02-04 11:54:58 -0800673 case CMD_SEND_ENVELOPE:
674 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000675 uiccPort = getUiccPortFromRequest(request);
676 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 loge("sendEnvelopeWithStatus: No UICC");
678 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 } else {
681 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000682 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 break;
685
686 case EVENT_SEND_ENVELOPE_DONE:
687 ar = (AsyncResult) msg.obj;
688 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700689 if (ar.exception == null && ar.result != null) {
690 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800691 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700692 request.result = new IccIoResult(0x6F, 0, (byte[])null);
693 if (ar.result == null) {
694 loge("sendEnvelopeWithStatus: Empty response");
695 } else if (ar.exception instanceof CommandException) {
696 loge("sendEnvelopeWithStatus: CommandException: " +
697 ar.exception);
698 } else {
699 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
700 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800701 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700702 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 break;
704
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 case CMD_OPEN_CHANNEL:
706 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000707 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800708 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000709 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700710 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800711 request.result = new IccOpenLogicalChannelResponse(-1,
712 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700714 } else {
715 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000716 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800717 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 break;
720
721 case EVENT_OPEN_CHANNEL_DONE:
722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 int[] result = (int[]) ar.result;
727 int channelId = result[0];
728 byte[] selectResponse = null;
729 if (result.length > 1) {
730 selectResponse = new byte[result.length - 1];
731 for (int i = 1; i < result.length; ++i) {
732 selectResponse[i - 1] = (byte) result[i];
733 }
734 }
735 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700736 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 if (ar.result == null) {
739 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 if (ar.exception != null) {
742 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
743 }
744
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700745 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700746 if (ar.exception instanceof CommandException) {
747 CommandException.Error error =
748 ((CommandException) (ar.exception)).getCommandError();
749 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700750 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700751 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700752 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700753 }
754 }
755 openChannelResp = new IccOpenLogicalChannelResponse(
756 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700758 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 break;
761
762 case CMD_CLOSE_CHANNEL:
763 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000764 uiccPort = getUiccPortFromRequest(request);
765 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700766 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900767 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700768 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 } else {
770 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000771 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 break;
774
775 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800776 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
777 break;
778
779 case CMD_NV_READ_ITEM:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
783 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800784 break;
785
786 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800789 if (ar.exception == null && ar.result != null) {
790 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800792 request.result = "";
793 if (ar.result == null) {
794 loge("nvReadItem: Empty response");
795 } else if (ar.exception instanceof CommandException) {
796 loge("nvReadItem: CommandException: " +
797 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800799 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 }
801 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700802 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 break;
804
Jake Hambye994d462014-02-03 13:10:13 -0800805 case CMD_NV_WRITE_ITEM:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
808 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800809 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700810 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800811 break;
812
813 case EVENT_NV_WRITE_ITEM_DONE:
814 handleNullReturnEvent(msg, "nvWriteItem");
815 break;
816
817 case CMD_NV_WRITE_CDMA_PRL:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800820 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800821 break;
822
823 case EVENT_NV_WRITE_CDMA_PRL_DONE:
824 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
825 break;
826
chen xu6dac5ab2018-10-26 17:39:23 -0700827 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800828 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700829 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800830 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800831 break;
832
chen xu6dac5ab2018-10-26 17:39:23 -0700833 case EVENT_RESET_MODEM_CONFIG_DONE:
834 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800835 break;
836
Sooraj Sasindran37444802020-08-11 10:40:43 -0700837 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
838 request = (MainThreadRequest) msg.obj;
839 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
840 request);
841 Phone phone = getPhoneFromRequest(request);
842 if (phone != null) {
843 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
844 } else {
845 loge("isNRDualConnectivityEnabled: No phone object");
846 request.result = false;
847 notifyRequester(request);
848 }
849 break;
850 }
851
852 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 // request.result must be set to something non-null
859 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700860 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700861 request.result = ar.result;
862 } else {
863 request.result = false;
864 }
865 if (ar.result == null) {
866 loge("isNRDualConnectivityEnabled: Empty response");
867 } else if (ar.exception instanceof CommandException) {
868 loge("isNRDualConnectivityEnabled: CommandException: "
869 + ar.exception);
870 } else {
871 loge("isNRDualConnectivityEnabled: Unknown exception");
872 }
873 }
874 notifyRequester(request);
875 break;
876
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700877 case CMD_IS_VONR_ENABLED: {
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
880 request);
881 Phone phone = getPhoneFromRequest(request);
882 if (phone != null) {
883 phone.isVoNrEnabled(onCompleted, request.workSource);
884 } else {
885 loge("isVoNrEnabled: No phone object");
886 request.result = false;
887 notifyRequester(request);
888 }
889 break;
890 }
891
892 case EVENT_IS_VONR_ENABLED_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result;
897 } else {
898 // request.result must be set to something non-null
899 // for the calling thread to unblock
900 if (ar.result != null) {
901 request.result = ar.result;
902 } else {
903 request.result = false;
904 }
905 if (ar.result == null) {
906 loge("isVoNrEnabled: Empty response");
907 } else if (ar.exception instanceof CommandException) {
908 loge("isVoNrEnabled: CommandException: "
909 + ar.exception);
910 } else {
911 loge("isVoNrEnabled: Unknown exception");
912 }
913 }
914 notifyRequester(request);
915 break;
916
Sooraj Sasindran37444802020-08-11 10:40:43 -0700917 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
920 Phone phone = getPhoneFromRequest(request);
921 if (phone != null) {
922 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
923 request.workSource);
924 } else {
925 loge("enableNrDualConnectivity: No phone object");
926 request.result =
927 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
928 notifyRequester(request);
929 }
930 break;
931 }
932
933 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 if (ar.exception == null) {
937 request.result =
938 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
939 } else {
940 request.result =
941 TelephonyManager
942 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
943 if (ar.exception instanceof CommandException) {
944 CommandException.Error error =
945 ((CommandException) (ar.exception)).getCommandError();
946 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
947 request.result =
948 TelephonyManager
949 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000950 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
951 request.result =
952 TelephonyManager
953 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700954 }
955 loge("enableNrDualConnectivity" + ": CommandException: "
956 + ar.exception);
957 } else {
958 loge("enableNrDualConnectivity" + ": Unknown exception");
959 }
960 }
961 notifyRequester(request);
962 break;
963 }
964
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700965 case CMD_ENABLE_VONR: {
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
971 request.workSource);
972 } else {
973 loge("setVoNrEnabled: No phone object");
974 request.result =
975 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
976 notifyRequester(request);
977 }
978 break;
979 }
980
981 case EVENT_ENABLE_VONR_DONE: {
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception == null) {
985 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
986 } else {
987 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
988 if (ar.exception instanceof CommandException) {
989 CommandException.Error error =
990 ((CommandException) (ar.exception)).getCommandError();
991 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
992 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
993 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
994 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
995 } else {
996 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
997 }
998 loge("setVoNrEnabled" + ": CommandException: "
999 + ar.exception);
1000 } else {
1001 loge("setVoNrEnabled" + ": Unknown exception");
1002 }
1003 }
1004 notifyRequester(request);
1005 break;
1006 }
1007
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001009 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1011 request);
1012 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001013 break;
1014
SongFerngWang3ef3e072020-12-21 16:41:52 +08001015 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception == null && ar.result != null) {
1019 request.result = ar.result; // Integer
1020 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301021 // request.result must be set to something non-null
1022 // for the calling thread to unblock
1023 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001024 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001025 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001026 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001027 loge("getAllowedNetworkTypesBitmask: CommandException: "
1028 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 }
1032 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001033 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001034 break;
1035
SongFerngWang3ef3e072020-12-21 16:41:52 +08001036 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001037 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001038 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1039 request);
1040 Pair<Integer, Long> reasonWithNetworkTypes =
1041 (Pair<Integer, Long>) request.argument;
1042 getPhoneFromRequest(request).setAllowedNetworkTypes(
1043 reasonWithNetworkTypes.first,
1044 reasonWithNetworkTypes.second,
1045 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001046 break;
1047
SongFerngWang3ef3e072020-12-21 16:41:52 +08001048 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1049 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001050 break;
1051
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001052 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1053 request = (MainThreadRequest)msg.obj;
1054 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001055 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001056 break;
1057
1058 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1059 ar = (AsyncResult)msg.obj;
1060 request = (MainThreadRequest)ar.userObj;
1061 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001062 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001063 break;
1064
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001065 case CMD_SET_VOICEMAIL_NUMBER:
1066 request = (MainThreadRequest) msg.obj;
1067 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1068 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001069 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1070 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001071 break;
1072
1073 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1074 handleNullReturnEvent(msg, "setVoicemailNumber");
1075 break;
1076
Stuart Scott54788802015-03-30 13:18:01 -07001077 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1080 request);
1081 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1082 break;
1083
1084 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1085 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1086 break;
1087
Shishir Agrawal302c8692015-06-19 13:49:39 -07001088 case CMD_PERFORM_NETWORK_SCAN:
1089 request = (MainThreadRequest) msg.obj;
1090 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1091 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1092 break;
1093
Hall Liu27d24262020-09-18 19:04:59 -07001094 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001095 request = (MainThreadRequest) msg.obj;
1096 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001097 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1098 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1099 request.argument;
1100 int callForwardingReason = args.first;
1101 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001102 break;
Hall Liu27d24262020-09-18 19:04:59 -07001103 }
1104 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001107 TelephonyManager.CallForwardingInfoCallback callback =
1108 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1109 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001110 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001111 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001112 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1113 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1114 // Service Class is a bit mask per 3gpp 27.007. Search for
1115 // any service for voice call.
1116 if ((callForwardInfo.serviceClass
1117 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001118 callForwardingInfo = new CallForwardingInfo(
1119 callForwardInfo.status
1120 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001121 callForwardInfo.reason,
1122 callForwardInfo.number,
1123 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001124 break;
1125 }
1126 }
1127 // Didn't find a call forward info for voice call.
1128 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001129 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1130 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001131 }
Hall Liu27d24262020-09-18 19:04:59 -07001132 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 } else {
1134 if (ar.result == null) {
1135 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1136 }
1137 if (ar.exception != null) {
1138 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1139 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001140 int errorCode = TelephonyManager
1141 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001142 if (ar.exception instanceof CommandException) {
1143 CommandException.Error error =
1144 ((CommandException) (ar.exception)).getCommandError();
1145 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001146 errorCode = TelephonyManager
1147 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001148 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001149 errorCode = TelephonyManager
1150 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001151 }
1152 }
Hall Liu27d24262020-09-18 19:04:59 -07001153 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001154 }
Shuo Qian4a594052020-01-23 11:59:30 -08001155 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 CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001161 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001162 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001163 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1164 request.argument).first;
1165 request.phone.setCallForwardingOption(
1166 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001167 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001168 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001169 callForwardingInfoToSet.getReason(),
1170 callForwardingInfoToSet.getNumber(),
1171 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1172 break;
Hall Liu27d24262020-09-18 19:04:59 -07001173 }
Shuo Qian4a594052020-01-23 11:59:30 -08001174
Hall Liu27d24262020-09-18 19:04:59 -07001175 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001176 ar = (AsyncResult) msg.obj;
1177 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001178 Consumer<Integer> callback =
1179 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1180 request.argument).second;
1181 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001182 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001183 int errorCode = TelephonyManager.CallForwardingInfoCallback
1184 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001185 if (ar.exception instanceof CommandException) {
1186 CommandException.Error error =
1187 ((CommandException) (ar.exception)).getCommandError();
1188 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001189 errorCode = TelephonyManager.CallForwardingInfoCallback
1190 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001191 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001192 errorCode = TelephonyManager.CallForwardingInfoCallback
1193 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001194 }
1195 }
1196 callback.accept(errorCode);
1197 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001198 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001199 }
Shuo Qian4a594052020-01-23 11:59:30 -08001200 break;
Hall Liu27d24262020-09-18 19:04:59 -07001201 }
Shuo Qian4a594052020-01-23 11:59:30 -08001202
Hall Liu27d24262020-09-18 19:04:59 -07001203 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1206 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1207 break;
Hall Liu27d24262020-09-18 19:04:59 -07001208 }
Shuo Qian4a594052020-01-23 11:59:30 -08001209
Hall Liu27d24262020-09-18 19:04:59 -07001210 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001213 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001214 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1215 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001216 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001217 // Service Class is a bit mask per 3gpp 27.007.
1218 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001219 if (callForwardResults.length > 1
1220 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001221 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001222 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001223 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1224 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001226 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 }
1228 } else {
1229 if (ar.result == null) {
1230 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1231 }
1232 if (ar.exception != null) {
1233 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1234 }
1235 if (ar.exception instanceof CommandException) {
1236 CommandException.Error error =
1237 ((CommandException) (ar.exception)).getCommandError();
1238 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1239 callForwardingStatus =
1240 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1241 }
1242 }
1243 }
Hall Liu27d24262020-09-18 19:04:59 -07001244 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 break;
Hall Liu27d24262020-09-18 19:04:59 -07001246 }
Shuo Qian4a594052020-01-23 11:59:30 -08001247
Hall Liu27d24262020-09-18 19:04:59 -07001248 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001249 request = (MainThreadRequest) msg.obj;
1250 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001251 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1252 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001253 break;
Hall Liu27d24262020-09-18 19:04:59 -07001254 }
Shuo Qian4a594052020-01-23 11:59:30 -08001255
Hall Liu27d24262020-09-18 19:04:59 -07001256 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001257 ar = (AsyncResult) msg.obj;
1258 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001259 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1260 Consumer<Integer> callback =
1261 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1262 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001263 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001264 if (ar.exception instanceof CommandException) {
1265 CommandException.Error error =
1266 ((CommandException) (ar.exception)).getCommandError();
1267 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1268 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1269 } else {
1270 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1271 }
1272 } else {
1273 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1274 }
1275 } else {
1276 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1277 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279 break;
Hall Liu27d24262020-09-18 19:04:59 -07001280 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001281 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 CellNetworkScanResult cellScanResult;
1285 if (ar.exception == null && ar.result != null) {
1286 cellScanResult = new CellNetworkScanResult(
1287 CellNetworkScanResult.STATUS_SUCCESS,
1288 (List<OperatorInfo>) ar.result);
1289 } else {
1290 if (ar.result == null) {
1291 loge("getCellNetworkScanResults: Empty response");
1292 }
1293 if (ar.exception != null) {
1294 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1295 }
1296 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1297 if (ar.exception instanceof CommandException) {
1298 CommandException.Error error =
1299 ((CommandException) (ar.exception)).getCommandError();
1300 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1301 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1302 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1303 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1304 }
1305 }
1306 cellScanResult = new CellNetworkScanResult(errorCode, null);
1307 }
1308 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001309 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001310 break;
1311
1312 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1313 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001314 ManualNetworkSelectionArgument selArg =
1315 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001316 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1317 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001318 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1319 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001320 break;
1321
1322 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001323 ar = (AsyncResult) msg.obj;
1324 request = (MainThreadRequest) ar.userObj;
1325 if (ar.exception == null) {
1326 request.result = true;
1327 } else {
1328 request.result = false;
1329 loge("setNetworkSelectionModeManual " + ar.exception);
1330 }
1331 notifyRequester(request);
1332 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001333 break;
1334
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001335 case CMD_GET_MODEM_ACTIVITY_INFO:
1336 request = (MainThreadRequest) msg.obj;
1337 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001338 if (defaultPhone != null) {
1339 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001340 } else {
1341 ResultReceiver result = (ResultReceiver) request.argument;
1342 Bundle bundle = new Bundle();
1343 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001344 new ModemActivityInfo(0, 0, 0,
1345 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001346 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001347 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001348 break;
1349
Hall Liud0f208c2020-10-14 16:54:44 -07001350 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001351 ar = (AsyncResult) msg.obj;
1352 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001353 ResultReceiver result = (ResultReceiver) request.argument;
1354
Hall Liud0f208c2020-10-14 16:54:44 -07001355 ModemActivityInfo ret = null;
1356 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001357 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001358 // Update the last modem activity info and the result of the request.
1359 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1360 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001361 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001362 int[] txTimeMs = info.getTransmitTimeMillis();
1363 int[] lastModemTxTimeMs = mLastModemActivityInfo
1364 .getTransmitTimeMillis();
1365 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1366 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1367 }
Hall Liu49656c02020-10-09 19:00:11 -07001368 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001369 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1370 + mLastModemActivityInfo.getSleepTimeMillis());
1371 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1372 + mLastModemActivityInfo.getIdleTimeMillis());
1373 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1374 mLastModemActivityInfo.setReceiveTimeMillis(
1375 info.getReceiveTimeMillis()
1376 + mLastModemActivityInfo.getReceiveTimeMillis());
1377 }
Hall Liu49656c02020-10-09 19:00:11 -07001378 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001379 mLastModemActivityInfo.getSleepTimeMillis(),
1380 mLastModemActivityInfo.getIdleTimeMillis(),
1381 mLastModemActivityInfo.getTransmitTimeMillis(),
1382 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001383 } else {
1384 if (ar.result == null) {
1385 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001386 error = TelephonyManager.ModemActivityInfoException
1387 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388 } else if (ar.exception instanceof CommandException) {
1389 loge("queryModemActivityInfo: CommandException: " +
1390 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001391 error = TelephonyManager.ModemActivityInfoException
1392 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001393 } else {
1394 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001395 error = TelephonyManager.ModemActivityInfoException
1396 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001397 }
1398 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001399 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001400 if (ret != null) {
1401 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1402 } else {
1403 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1404 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001405 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001406 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001407 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001408 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001409
Meng Wang1a7c35a2016-05-05 20:56:15 -07001410 case CMD_SET_ALLOWED_CARRIERS:
1411 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001412 CarrierRestrictionRules argument =
1413 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001414 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001415 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001416 break;
1417
1418 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception == null && ar.result != null) {
1422 request.result = ar.result;
1423 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001424 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1425 if (ar.exception instanceof CommandException) {
1426 loge("setAllowedCarriers: CommandException: " + ar.exception);
1427 CommandException.Error error =
1428 ((CommandException) (ar.exception)).getCommandError();
1429 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1430 request.result =
1431 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1432 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001433 } else {
1434 loge("setAllowedCarriers: Unknown exception");
1435 }
1436 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001437 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001438 break;
1439
1440 case CMD_GET_ALLOWED_CARRIERS:
1441 request = (MainThreadRequest) msg.obj;
1442 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001443 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001444 break;
1445
1446 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 if (ar.exception == null && ar.result != null) {
1450 request.result = ar.result;
1451 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001452 request.result = new IllegalStateException(
1453 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001454 if (ar.result == null) {
1455 loge("getAllowedCarriers: Empty response");
1456 } else if (ar.exception instanceof CommandException) {
1457 loge("getAllowedCarriers: CommandException: " +
1458 ar.exception);
1459 } else {
1460 loge("getAllowedCarriers: Unknown exception");
1461 }
1462 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001463 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001464 break;
1465
Nathan Haroldb3014052017-01-25 15:57:32 -08001466 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 if (ar.exception == null && ar.result != null) {
1470 request.result = ar.result;
1471 } else {
1472 request.result = new IllegalArgumentException(
1473 "Failed to retrieve Forbidden Plmns");
1474 if (ar.result == null) {
1475 loge("getForbiddenPlmns: Empty response");
1476 } else {
1477 loge("getForbiddenPlmns: Unknown exception");
1478 }
1479 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001481 break;
1482
1483 case CMD_GET_FORBIDDEN_PLMNS:
1484 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001485 uiccPort = getUiccPortFromRequest(request);
1486 if (uiccPort == null) {
1487 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001488 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001489 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001490 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001491 break;
1492 }
1493 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001494 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001495 if (uiccApp == null) {
1496 loge("getForbiddenPlmns() no app with specified type -- "
1497 + appType);
1498 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001499 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001500 break;
1501 } else {
1502 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1503 + " specified type -- " + appType);
1504 }
1505 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1506 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1507 onCompleted);
1508 break;
1509
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001510 case CMD_SWITCH_SLOTS:
1511 request = (MainThreadRequest) msg.obj;
1512 int[] physicalSlots = (int[]) request.argument;
1513 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1514 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1515 break;
1516
1517 case EVENT_SWITCH_SLOTS_DONE:
1518 ar = (AsyncResult) msg.obj;
1519 request = (MainThreadRequest) ar.userObj;
1520 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
1522 break;
1523 case CMD_GET_NETWORK_SELECTION_MODE:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1526 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1527 break;
1528
1529 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 if (ar.exception != null) {
1533 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1534 } else {
1535 int mode = ((int[]) ar.result)[0];
1536 if (mode == 0) {
1537 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1538 } else {
1539 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1540 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001541 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001542 notifyRequester(request);
1543 break;
1544 case CMD_GET_CDMA_ROAMING_MODE:
1545 request = (MainThreadRequest) msg.obj;
1546 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1547 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1548 break;
1549 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception != null) {
1553 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1554 } else {
1555 request.result = ((int[]) ar.result)[0];
1556 }
1557 notifyRequester(request);
1558 break;
1559 case CMD_SET_CDMA_ROAMING_MODE:
1560 request = (MainThreadRequest) msg.obj;
1561 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1562 int mode = (int) request.argument;
1563 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1564 break;
1565 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 request.result = ar.exception == null;
1569 notifyRequester(request);
1570 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001571 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1574 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1575 break;
1576 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 if (ar.exception != null) {
1580 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1581 } else {
1582 request.result = ((int[]) ar.result)[0];
1583 }
1584 notifyRequester(request);
1585 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001586 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1587 request = (MainThreadRequest) msg.obj;
1588 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1589 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001590 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1591 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001592 break;
1593 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1594 ar = (AsyncResult) msg.obj;
1595 request = (MainThreadRequest) ar.userObj;
1596 request.result = ar.exception == null;
1597 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001598 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001599 case CMD_GET_ALL_CELL_INFO:
1600 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001601 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001602 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001603 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 case EVENT_GET_ALL_CELL_INFO_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001607 // If a timeout occurs, the response will be null
1608 request.result = (ar.exception == null && ar.result != null)
1609 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001610 synchronized (request) {
1611 request.notifyAll();
1612 }
1613 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001614 case CMD_REQUEST_CELL_INFO_UPDATE:
1615 request = (MainThreadRequest) msg.obj;
1616 request.phone.requestCellInfoUpdate(request.workSource,
1617 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1618 break;
1619 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1623 try {
1624 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001625 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001626 cb.onError(
1627 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1628 ar.exception.getClass().getName(),
1629 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001630 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001631 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001632 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001633 } else {
1634 // use the result as returned
1635 cb.onCellInfo((List<CellInfo>) ar.result);
1636 }
1637 } catch (RemoteException re) {
1638 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1639 }
1640 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001641 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001642 request = (MainThreadRequest) msg.obj;
1643 WorkSource ws = (WorkSource) request.argument;
1644 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001645 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001646 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001647 }
1648 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 ar = (AsyncResult) msg.obj;
1650 request = (MainThreadRequest) ar.userObj;
1651 if (ar.exception == null) {
1652 request.result = ar.result;
1653 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001654 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001655 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001656 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001657 }
1658
1659 synchronized (request) {
1660 request.notifyAll();
1661 }
1662 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001663 }
chen xu6dac5ab2018-10-26 17:39:23 -07001664 case CMD_MODEM_REBOOT:
1665 request = (MainThreadRequest) msg.obj;
1666 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001667 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001668 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001669 case EVENT_CMD_MODEM_REBOOT_DONE:
1670 handleNullReturnEvent(msg, "rebootModem");
1671 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001672 case CMD_REQUEST_ENABLE_MODEM:
1673 request = (MainThreadRequest) msg.obj;
1674 boolean enable = (boolean) request.argument;
1675 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001676 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001677 PhoneConfigurationManager.getInstance()
1678 .enablePhone(request.phone, enable, onCompleted);
1679 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001680 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001684 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001685 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001686 if ((boolean) request.result) {
1687 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1688 updateModemStateMetrics();
1689 } else {
1690 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1691 + ar.exception);
1692 }
1693 notifyRequester(request);
1694 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001695 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001696 case CMD_GET_MODEM_STATUS:
1697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1699 PhoneConfigurationManager.getInstance()
1700 .getPhoneStatusFromModem(request.phone, onCompleted);
1701 break;
1702 case EVENT_GET_MODEM_STATUS_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 int id = request.phone.getPhoneId();
1706 if (ar.exception == null && ar.result != null) {
1707 request.result = ar.result;
1708 //update the cache as modem status has changed
1709 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1710 (boolean) request.result);
1711 } else {
1712 // Return true if modem status cannot be retrieved. For most cases,
1713 // modem status is on. And for older version modems, GET_MODEM_STATUS
1714 // and disable modem are not supported. Modem is always on.
1715 // TODO: this should be fixed in R to support a third
1716 // status UNKNOWN b/131631629
1717 request.result = true;
1718 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1719 + ar.exception);
1720 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001721 notifyRequester(request);
1722 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001723 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1726 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1727 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1728 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1729 break;
1730 }
1731 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1732 ar = (AsyncResult) msg.obj;
1733 request = (MainThreadRequest) ar.userObj;
1734 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1735 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1736 args.second.accept(ar.exception == null);
1737 notifyRequester(request);
1738 break;
1739 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001740 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1741 request = (MainThreadRequest) msg.obj;
1742 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1743 Phone phone = getPhoneFromRequest(request);
1744 if (phone != null) {
1745 phone.getSystemSelectionChannels(onCompleted);
1746 } else {
1747 loge("getSystemSelectionChannels: No phone object");
1748 request.result = new ArrayList<RadioAccessSpecifier>();
1749 notifyRequester(request);
1750 }
1751 break;
1752 }
1753 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756 if (ar.exception == null && ar.result != null) {
1757 request.result = ar.result;
1758 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001759 request.result = new IllegalStateException(
1760 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001761 if (ar.result == null) {
1762 loge("getSystemSelectionChannels: Empty response");
1763 } else {
1764 loge("getSystemSelectionChannels: Unknown exception");
1765 }
1766 }
1767 notifyRequester(request);
1768 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001769 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1770 ar = (AsyncResult) msg.obj;
1771 request = (MainThreadRequest) ar.userObj;
1772 if (ar.exception == null && ar.result != null) {
1773 request.result = ar.result;
1774 } else {
1775 request.result = -1;
1776 loge("Failed to set Forbidden Plmns");
1777 if (ar.result == null) {
1778 loge("setForbidenPlmns: Empty response");
1779 } else if (ar.exception != null) {
1780 loge("setForbiddenPlmns: Exception: " + ar.exception);
1781 request.result = -1;
1782 } else {
1783 loge("setForbiddenPlmns: Unknown exception");
1784 }
1785 }
1786 notifyRequester(request);
1787 break;
1788 case CMD_SET_FORBIDDEN_PLMNS:
1789 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001790 uiccPort = getUiccPortFromRequest(request);
1791 if (uiccPort == null) {
1792 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001793 request.result = -1;
1794 notifyRequester(request);
1795 break;
1796 }
1797 Pair<Integer, List<String>> setFplmnsArgs =
1798 (Pair<Integer, List<String>>) request.argument;
1799 appType = setFplmnsArgs.first;
1800 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001801 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001802 if (uiccApp == null) {
1803 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1804 request.result = -1;
1805 loge("Failed to get UICC App");
1806 notifyRequester(request);
1807 } else {
1808 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1809 ((SIMRecords) uiccApp.getIccRecords())
1810 .setForbiddenPlmns(onCompleted, fplmns);
1811 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001812 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001813 case CMD_ERASE_MODEM_CONFIG:
1814 request = (MainThreadRequest) msg.obj;
1815 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1816 defaultPhone.eraseModemConfig(onCompleted);
1817 break;
1818 case EVENT_ERASE_MODEM_CONFIG_DONE:
1819 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001820 break;
zoey chene02881a2019-12-30 16:11:23 +08001821
Kai Shif70f46f2021-03-03 13:59:46 -08001822 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1823 request = (MainThreadRequest) msg.obj;
1824 request.result = defaultPhone.eraseDataInSharedPreferences();
1825 notifyRequester(request);
1826 break;
1827
zoey chene02881a2019-12-30 16:11:23 +08001828 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1829 request = (MainThreadRequest) msg.obj;
1830 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1831 Pair<String, String> changed = (Pair<String, String>) request.argument;
1832 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1833 changed.first, changed.second, onCompleted);
1834 break;
1835 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 if (ar.exception == null) {
1839 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001840 // If the operation is successful, update the PIN storage
1841 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1842 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001843 UiccController.getInstance().getPinStorage()
1844 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001845 } else {
1846 request.result = msg.arg1;
1847 }
1848 notifyRequester(request);
1849 break;
1850
Michele Berionne5e411512020-11-13 02:36:59 +00001851 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001852 request = (MainThreadRequest) msg.obj;
1853 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1854 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1855 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1856 enabled.first, enabled.second, onCompleted);
1857 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001858 }
zoey chene02881a2019-12-30 16:11:23 +08001859 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1860 ar = (AsyncResult) msg.obj;
1861 request = (MainThreadRequest) ar.userObj;
1862 if (ar.exception == null) {
1863 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001864 // If the operation is successful, update the PIN storage
1865 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1866 int phoneId = getPhoneFromRequest(request).getPhoneId();
1867 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001868 UiccController.getInstance().getPinStorage()
1869 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001870 } else {
1871 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1872 }
zoey chene02881a2019-12-30 16:11:23 +08001873 } else {
1874 request.result = msg.arg1;
1875 }
Michele Berionne5e411512020-11-13 02:36:59 +00001876
1877
zoey chene02881a2019-12-30 16:11:23 +08001878 notifyRequester(request);
1879 break;
1880
Peter Wangdafb9ac2020-01-15 14:13:38 -08001881 case MSG_NOTIFY_USER_ACTIVITY:
1882 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001883 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001884 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1885 getDefaultPhone().getContext().sendBroadcastAsUser(
1886 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1887 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001888
1889 case CMD_SET_DATA_THROTTLING: {
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1892 DataThrottlingRequest dataThrottlingRequest =
1893 (DataThrottlingRequest) request.argument;
1894 Phone phone = getPhoneFromRequest(request);
1895 if (phone != null) {
1896 phone.setDataThrottling(onCompleted,
1897 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1898 dataThrottlingRequest.getCompletionDurationMillis());
1899 } else {
1900 loge("setDataThrottling: No phone object");
1901 request.result =
1902 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1903 notifyRequester(request);
1904 }
1905
1906 break;
1907 }
1908 case EVENT_SET_DATA_THROTTLING_DONE:
1909 ar = (AsyncResult) msg.obj;
1910 request = (MainThreadRequest) ar.userObj;
1911
1912 if (ar.exception == null) {
1913 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1914 } else if (ar.exception instanceof CommandException) {
1915 loge("setDataThrottling: CommandException: " + ar.exception);
1916 CommandException.Error error =
1917 ((CommandException) (ar.exception)).getCommandError();
1918
1919 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1920 request.result = TelephonyManager
1921 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1922 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1923 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001924 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1925 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001926 } else {
1927 request.result =
1928 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1929 }
1930 } else {
1931 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1932 }
1933 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1934 notifyRequester(request);
1935 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001936
1937 case CMD_SET_SIM_POWER: {
1938 request = (MainThreadRequest) msg.obj;
1939 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1940 request = (MainThreadRequest) msg.obj;
1941 int stateToSet =
1942 ((Pair<Integer, IIntegerConsumer>)
1943 request.argument).first;
1944 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1945 break;
1946 }
1947 case EVENT_SET_SIM_POWER_DONE: {
1948 ar = (AsyncResult) msg.obj;
1949 request = (MainThreadRequest) ar.userObj;
1950 IIntegerConsumer callback =
1951 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1952 if (ar.exception != null) {
1953 loge("setSimPower exception: " + ar.exception);
1954 int errorCode = TelephonyManager.CallForwardingInfoCallback
1955 .RESULT_ERROR_UNKNOWN;
1956 if (ar.exception instanceof CommandException) {
1957 CommandException.Error error =
1958 ((CommandException) (ar.exception)).getCommandError();
1959 if (error == CommandException.Error.SIM_ERR) {
1960 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1961 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1962 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1963 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1964 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1965 } else {
1966 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1967 }
1968 }
1969 try {
1970 callback.accept(errorCode);
1971 } catch (RemoteException e) {
1972 // Ignore if the remote process is no longer available to call back.
1973 Log.w(LOG_TAG, "setSimPower: callback not available.");
1974 }
1975 } else {
1976 try {
1977 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1978 } catch (RemoteException e) {
1979 // Ignore if the remote process is no longer available to call back.
1980 Log.w(LOG_TAG, "setSimPower: callback not available.");
1981 }
1982 }
1983 break;
1984 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001985 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1986 request = (MainThreadRequest) msg.obj;
1987
1988 final Phone phone = getPhoneFromRequest(request);
1989 if (phone == null || phone.getServiceStateTracker() == null) {
1990 request.result = new IllegalStateException("Phone or SST is null");
1991 notifyRequester(request);
1992 break;
1993 }
1994
1995 Pair<Integer, SignalStrengthUpdateRequest> pair =
1996 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1997 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1998 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001999 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002000 request.subId, pair.first /*callingUid*/,
2001 pair.second /*request*/, onCompleted);
2002 break;
2003 }
2004 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2005 ar = (AsyncResult) msg.obj;
2006 request = (MainThreadRequest) ar.userObj;
2007 // request.result will be the exception of ar if present, true otherwise.
2008 // Be cautious not to leave result null which will wait() forever
2009 request.result = ar.exception != null ? ar.exception : true;
2010 notifyRequester(request);
2011 break;
2012 }
2013 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2014 request = (MainThreadRequest) msg.obj;
2015
2016 Phone phone = getPhoneFromRequest(request);
2017 if (phone == null || phone.getServiceStateTracker() == null) {
2018 request.result = new IllegalStateException("Phone or SST is null");
2019 notifyRequester(request);
2020 break;
2021 }
2022
2023 Pair<Integer, SignalStrengthUpdateRequest> pair =
2024 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2025 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2026 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002027 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002028 request.subId, pair.first /*callingUid*/,
2029 pair.second /*request*/, onCompleted);
2030 break;
2031 }
2032 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2033 ar = (AsyncResult) msg.obj;
2034 request = (MainThreadRequest) ar.userObj;
2035 request.result = ar.exception != null ? ar.exception : true;
2036 notifyRequester(request);
2037 break;
2038 }
Jordan Liu109698e2020-11-24 14:50:34 -08002039
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002040 case CMD_GET_SLICING_CONFIG: {
2041 request = (MainThreadRequest) msg.obj;
2042 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2043 request.phone.getSlicingConfig(onCompleted);
2044 break;
2045 }
2046 case EVENT_GET_SLICING_CONFIG_DONE: {
2047 ar = (AsyncResult) msg.obj;
2048 request = (MainThreadRequest) ar.userObj;
2049 ResultReceiver result = (ResultReceiver) request.argument;
2050
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002051 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002052 Bundle bundle = new Bundle();
2053 int resultCode = 0;
2054 if (ar.exception != null) {
2055 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2056 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002057 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002058 } else if (ar.result == null) {
2059 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002060 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002061 } else {
2062 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002063 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2064 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002065 }
2066
2067 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002068 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002069 }
2070 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2071 result.send(resultCode, bundle);
2072 notifyRequester(request);
2073 break;
2074 }
2075
Michele Berionne5e411512020-11-13 02:36:59 +00002076 case CMD_PREPARE_UNATTENDED_REBOOT:
2077 request = (MainThreadRequest) msg.obj;
2078 request.result =
2079 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2080 notifyRequester(request);
2081 break;
2082
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 default:
2084 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2085 break;
2086 }
2087 }
Jake Hambye994d462014-02-03 13:10:13 -08002088
Pengquan Menga1bb6272018-09-06 09:59:22 -07002089 private void notifyRequester(MainThreadRequest request) {
2090 synchronized (request) {
2091 request.notifyAll();
2092 }
2093 }
2094
Jake Hambye994d462014-02-03 13:10:13 -08002095 private void handleNullReturnEvent(Message msg, String command) {
2096 AsyncResult ar = (AsyncResult) msg.obj;
2097 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2098 if (ar.exception == null) {
2099 request.result = true;
2100 } else {
2101 request.result = false;
2102 if (ar.exception instanceof CommandException) {
2103 loge(command + ": CommandException: " + ar.exception);
2104 } else {
2105 loge(command + ": Unknown exception");
2106 }
2107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002108 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111
2112 /**
2113 * Posts the specified command to be executed on the main thread,
2114 * waits for the request to complete, and returns the result.
2115 * @see #sendRequestAsync
2116 */
2117 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002118 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2119 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002120 }
2121
2122 /**
2123 * Posts the specified command to be executed on the main thread,
2124 * waits for the request to complete, and returns the result.
2125 * @see #sendRequestAsync
2126 */
2127 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2128 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002129 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002130 }
2131
2132 /**
2133 * Posts the specified command to be executed on the main thread,
2134 * waits for the request to complete, and returns the result.
2135 * @see #sendRequestAsync
2136 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002137 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002138 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2139 }
2140
2141 /**
2142 * Posts the specified command to be executed on the main thread,
2143 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2144 * if not timeout or null otherwise.
2145 * @see #sendRequestAsync
2146 */
2147 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2148 long timeoutInMs) {
2149 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002150 }
2151
2152 /**
2153 * Posts the specified command to be executed on the main thread,
2154 * waits for the request to complete, and returns the result.
2155 * @see #sendRequestAsync
2156 */
Nathan Harold92bed182018-10-12 18:16:49 -07002157 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002158 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002159 }
2160
2161 /**
2162 * Posts the specified command to be executed on the main thread,
2163 * waits for the request to complete, and returns the result.
2164 * @see #sendRequestAsync
2165 */
2166 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002167 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2168 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002169 }
2170
2171 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002172 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2173 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2174 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002175 * @see #sendRequestAsync
2176 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002177 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2178 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2180 throw new RuntimeException("This method will deadlock if called from the main thread.");
2181 }
2182
Nathan Harold92bed182018-10-12 18:16:49 -07002183 MainThreadRequest request = null;
2184 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2185 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2186 } else if (phone != null) {
2187 request = new MainThreadRequest(argument, phone, workSource);
2188 } else {
2189 request = new MainThreadRequest(argument, subId, workSource);
2190 }
2191
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 Message msg = mMainThreadHandler.obtainMessage(command, request);
2193 msg.sendToTarget();
2194
Rambo Wang0f050d82021-02-12 11:43:36 -08002195
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002197 if (timeoutInMs >= 0) {
2198 // Wait for at least timeoutInMs before returning null request result
2199 long now = SystemClock.elapsedRealtime();
2200 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002201 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002202 try {
2203 request.wait(deadline - now);
2204 } catch (InterruptedException e) {
2205 // Do nothing, go back and check if request is completed or timeout
2206 } finally {
2207 now = SystemClock.elapsedRealtime();
2208 }
2209 }
2210 } else {
2211 // Wait for the request to complete
2212 while (request.result == null) {
2213 try {
2214 request.wait();
2215 } catch (InterruptedException e) {
2216 // Do nothing, go back and wait until the request is complete
2217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219 }
2220 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002221 if (request.result == null) {
2222 Log.wtf(LOG_TAG,
2223 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 return request.result;
2226 }
2227
2228 /**
2229 * Asynchronous ("fire and forget") version of sendRequest():
2230 * Posts the specified command to be executed on the main thread, and
2231 * returns immediately.
2232 * @see #sendRequest
2233 */
2234 private void sendRequestAsync(int command) {
2235 mMainThreadHandler.sendEmptyMessage(command);
2236 }
2237
2238 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002239 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002240 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002241 */
2242 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 sendRequestAsync(command, argument, null, null);
2244 }
2245
2246 /**
2247 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2248 * @see {@link #sendRequest(int,Object)}
2249 */
2250 private void sendRequestAsync(
2251 int command, Object argument, Phone phone, WorkSource workSource) {
2252 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002253 Message msg = mMainThreadHandler.obtainMessage(command, request);
2254 msg.sendToTarget();
2255 }
2256
2257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 * Initialize the singleton PhoneInterfaceManager instance.
2259 * This is only done once, at startup, from PhoneApp.onCreate().
2260 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002261 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 synchronized (PhoneInterfaceManager.class) {
2263 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002264 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 } else {
2266 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2267 }
2268 return sInstance;
2269 }
2270 }
2271
2272 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002273 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002276 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002277 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002279 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002281 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002282 mTelephonySharedPreferences =
2283 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002284 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002285 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002286 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002287 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002288
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 publish();
2290 }
2291
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002292 private Phone getDefaultPhone() {
2293 Phone thePhone = getPhone(getDefaultSubscription());
2294 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2295 }
2296
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 private void publish() {
2298 if (DBG) log("publish: " + this);
2299
Peter Wangc035ce42020-01-08 21:00:22 -08002300 TelephonyFrameworkInitializer
2301 .getTelephonyServiceManager()
2302 .getTelephonyServiceRegisterer()
2303 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 }
2305
Stuart Scott584921c2015-01-15 17:10:34 -08002306 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002307 if (request.phone != null) {
2308 return request.phone;
2309 } else {
2310 return getPhoneFromSubId(request.subId);
2311 }
2312 }
2313
2314 private Phone getPhoneFromSubId(int subId) {
2315 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2316 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002317 }
2318
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002319 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002320 Phone phone = getPhoneFromRequest(request);
2321 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002322 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002323 }
2324
Wink Saville36469e72014-06-11 15:17:00 -07002325 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002326 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002327 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329
Kai Shif70f46f2021-03-03 13:59:46 -08002330 private void sendEraseModemConfig(@NonNull Phone phone) {
2331 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2332 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2333 }
2334
2335 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2336 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2337 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002338 }
2339
Peter Wang44b186e2020-01-13 23:33:09 -08002340 private boolean isImsAvailableOnDevice() {
2341 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2342 if (pm == null) {
2343 // For some reason package manger is not available.. This will fail internally anyway,
2344 // so do not throw error and allow.
2345 return true;
2346 }
2347 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2348 }
2349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002351 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002352 }
2353
Wink Savilleb564aae2014-10-23 10:18:09 -07002354 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 if (DBG) log("dial: " + number);
2356 // No permission check needed here: This is just a wrapper around the
2357 // ACTION_DIAL intent, which is available to any app since it puts up
2358 // the UI before it does anything.
2359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 String url = createTelUrl(number);
2363 if (url == null) {
2364 return;
2365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367 // PENDING: should we just silently fail if phone is offhook or ringing?
2368 PhoneConstants.State state = mCM.getState(subId);
2369 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2370 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2371 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2372 mApp.startActivity(intent);
2373 }
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 }
2377 }
2378
2379 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002380 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
2382
Wink Savilleb564aae2014-10-23 10:18:09 -07002383 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 if (DBG) log("call: " + number);
2385
2386 // This is just a wrapper around the ACTION_CALL intent, but we still
2387 // need to do a permission check since we're calling startActivity()
2388 // from the context of the phone app.
2389 enforceCallPermission();
2390
Jordan Liu1617b712019-07-10 15:06:26 -07002391 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 != AppOpsManager.MODE_ALLOWED) {
2393 return;
2394 }
2395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 String url = createTelUrl(number);
2399 if (url == null) {
2400 return;
2401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002403 boolean isValid = false;
2404 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2405 if (slist != null) {
2406 for (SubscriptionInfo subInfoRecord : slist) {
2407 if (subInfoRecord.getSubscriptionId() == subId) {
2408 isValid = true;
2409 break;
2410 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002411 }
Wink Saville08874612014-08-31 19:19:58 -07002412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002413 if (!isValid) {
2414 return;
2415 }
Wink Saville08874612014-08-31 19:19:58 -07002416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2418 intent.putExtra(SUBSCRIPTION_KEY, subId);
2419 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2420 mApp.startActivity(intent);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
2423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
2425
Wink Savilleb564aae2014-10-23 10:18:09 -07002426 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002427 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002428 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2429 }
2430
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002432 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002433 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2434 }
2435
Wink Savilleb564aae2014-10-23 10:18:09 -07002436 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438
2439 final long identity = Binder.clearCallingIdentity();
2440 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002441 Phone phone = getPhone(subId);
2442 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443 checkSimPin.start();
2444 return checkSimPin.unlockSim(null, pin);
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
2447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
2449
Wink Savilleb564aae2014-10-23 10:18:09 -07002450 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002455 Phone phone = getPhone(subId);
2456 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 checkSimPuk.start();
2458 return checkSimPuk.unlockSim(puk, pin);
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
2461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463
2464 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002465 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 * a synchronous one.
2467 */
2468 private static class UnlockSim extends Thread {
2469
2470 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002471 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472
2473 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002474 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2475 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476
2477 // For replies from SimCard interface
2478 private Handler mHandler;
2479
2480 // For async handler to identify request type
2481 private static final int SUPPLY_PIN_COMPLETE = 100;
2482
Michele Berionne5e411512020-11-13 02:36:59 +00002483 UnlockSim(int phoneId, IccCard simCard) {
2484 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 mSimCard = simCard;
2486 }
2487
2488 @Override
2489 public void run() {
2490 Looper.prepare();
2491 synchronized (UnlockSim.this) {
2492 mHandler = new Handler() {
2493 @Override
2494 public void handleMessage(Message msg) {
2495 AsyncResult ar = (AsyncResult) msg.obj;
2496 switch (msg.what) {
2497 case SUPPLY_PIN_COMPLETE:
2498 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2499 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002500 mRetryCount = msg.arg1;
2501 if (ar.exception != null) {
2502 if (ar.exception instanceof CommandException &&
2503 ((CommandException)(ar.exception)).getCommandError()
2504 == CommandException.Error.PASSWORD_INCORRECT) {
2505 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002506 } //When UiccCardApp dispose,handle message and return exception
2507 else if (ar.exception instanceof CommandException &&
2508 ((CommandException) (ar.exception)).getCommandError()
2509 == CommandException.Error.ABORTED) {
2510 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002511 } else {
2512 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2513 }
2514 } else {
2515 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 mDone = true;
2518 UnlockSim.this.notifyAll();
2519 }
2520 break;
2521 }
2522 }
2523 };
2524 UnlockSim.this.notifyAll();
2525 }
2526 Looper.loop();
2527 }
2528
2529 /*
2530 * Use PIN or PUK to unlock SIM card
2531 *
2532 * If PUK is null, unlock SIM card with PIN
2533 *
2534 * If PUK is not null, unlock SIM card with PUK and set PIN code
2535 */
Wink Saville9de0f752013-10-22 19:04:03 -07002536 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537
2538 while (mHandler == null) {
2539 try {
2540 wait();
2541 } catch (InterruptedException e) {
2542 Thread.currentThread().interrupt();
2543 }
2544 }
2545 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2546
2547 if (puk == null) {
2548 mSimCard.supplyPin(pin, callback);
2549 } else {
2550 mSimCard.supplyPuk(puk, pin, callback);
2551 }
2552
2553 while (!mDone) {
2554 try {
2555 Log.d(LOG_TAG, "wait for done");
2556 wait();
2557 } catch (InterruptedException e) {
2558 // Restore the interrupted status
2559 Thread.currentThread().interrupt();
2560 }
2561 }
2562 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002563 int[] resultArray = new int[2];
2564 resultArray[0] = mResult;
2565 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002566
2567 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002568 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002569 }
2570
Wink Saville9de0f752013-10-22 19:04:03 -07002571 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
2573 }
2574
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002575 /**
2576 * This method has been removed due to privacy and stability concerns.
2577 */
2578 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002580 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2581 return;
Wink Saville36469e72014-06-11 15:17:00 -07002582 }
2583
Nathan Harold1f889d82020-06-04 17:05:26 -07002584 @Override
2585 public void updateServiceLocationWithPackageName(String callingPackage) {
2586 mApp.getSystemService(AppOpsManager.class)
2587 .checkPackage(Binder.getCallingUid(), callingPackage);
2588
Nathan Haroldf096d982020-11-18 17:18:06 -08002589 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002590 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2591 // Callers targeting S have no business invoking this method.
2592 return;
2593 }
2594
2595 LocationAccessPolicy.LocationPermissionResult locationResult =
2596 LocationAccessPolicy.checkLocationPermission(mApp,
2597 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2598 .setCallingPackage(callingPackage)
2599 .setCallingFeatureId(null)
2600 .setCallingPid(Binder.getCallingPid())
2601 .setCallingUid(Binder.getCallingUid())
2602 .setMethod("updateServiceLocation")
2603 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2604 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2605 .build());
2606 // Apps that lack location permission have no business calling this method;
2607 // however, because no permission was declared in the public API, denials must
2608 // all be "soft".
2609 switch (locationResult) {
2610 case DENIED_HARD: /* fall through */
2611 case DENIED_SOFT:
2612 return;
2613 }
2614
2615 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002618 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002620 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002627 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 @Override
2629 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002630 return isRadioOnWithFeature(callingPackage, null);
2631 }
2632
2633
2634 @Override
2635 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2636 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2637 callingFeatureId);
2638 }
2639
2640 @Deprecated
2641 @Override
2642 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2643 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002644 }
2645
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002646 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002647 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2648 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002650 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002651 return false;
2652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 return isRadioOnForSubscriber(subId);
2657 } finally {
2658 Binder.restoreCallingIdentity(identity);
2659 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002660 }
2661
2662 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 if (phone != null) {
2667 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2668 } else {
2669 return false;
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
Wink Saville36469e72014-06-11 15:17:00 -07002679
Wink Savilleb564aae2014-10-23 10:18:09 -07002680 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 final Phone phone = getPhone(subId);
2686 if (phone != null) {
2687 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002691 }
Wink Saville36469e72014-06-11 15:17:00 -07002692 }
2693
2694 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002695 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002696 }
2697
Wink Savilleb564aae2014-10-23 10:18:09 -07002698 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 final Phone phone = getPhone(subId);
2704 if (phone == null) {
2705 return false;
2706 }
2707 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2708 toggleRadioOnOffForSubscriber(subId);
2709 }
2710 return true;
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
Wink Saville36469e72014-06-11 15:17:00 -07002715
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002716 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002717 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 /*
2719 * If any of the Radios are available, it will need to be
2720 * shutdown. So return true if any Radio is available.
2721 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2725 Phone phone = PhoneFactory.getPhone(i);
2726 if (phone != null && phone.isRadioAvailable()) return true;
2727 }
2728 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2729 return false;
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002733 }
2734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 enforceModifyPermission();
2738
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2742 logv("Shutting down Phone " + i);
2743 shutdownRadioUsingPhoneId(i);
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002747 }
2748 }
2749
2750 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002751 Phone phone = PhoneFactory.getPhone(phoneId);
2752 if (phone != null && phone.isRadioAvailable()) {
2753 phone.shutdownRadio();
2754 }
2755 }
2756
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759
2760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2763 if (defaultPhone != null) {
2764 defaultPhone.setRadioPower(turnOn);
2765 return true;
2766 } else {
2767 loge("There's no default phone.");
2768 return false;
2769 }
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002772 }
Wink Saville36469e72014-06-11 15:17:00 -07002773 }
2774
Wink Savilleb564aae2014-10-23 10:18:09 -07002775 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 final Phone phone = getPhone(subId);
2781 if (phone != null) {
2782 phone.setRadioPower(turnOn);
2783 return true;
2784 } else {
2785 return false;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
Wink Saville36469e72014-06-11 15:17:00 -07002792 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 public boolean enableDataConnectivity() {
2795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 int subId = mSubscriptionController.getDefaultDataSubId();
2800 final Phone phone = getPhone(subId);
2801 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002802 phone.getDataEnabledSettings().setDataEnabled(
2803 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 return true;
2805 } else {
2806 return false;
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
Wink Saville36469e72014-06-11 15:17:00 -07002813 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 public boolean disableDataConnectivity() {
2816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817
2818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 int subId = mSubscriptionController.getDefaultDataSubId();
2821 final Phone phone = getPhone(subId);
2822 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002823 phone.getDataEnabledSettings().setDataEnabled(
2824 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 return true;
2826 } else {
2827 return false;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 }
2833
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002835 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 final Phone phone = getPhone(subId);
2839 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002840 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002841 } else {
2842 return false;
2843 }
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
2849 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002850 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002851 }
2852
pkanwarae03a6b2016-11-06 20:37:09 -08002853 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 enforceCallPermission();
2855
2856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2859 return;
2860 }
2861 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2862 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
2865 }
pkanwar32d516d2016-10-14 19:37:38 -07002866 };
2867
Wink Savilleb564aae2014-10-23 10:18:09 -07002868 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 return false;
2875 }
2876 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2877 } finally {
2878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002882 /**
2883 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2884 * tag on getCallState Binder call.
2885 */
2886 @Deprecated
2887 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002889 if (CompatChanges.isChangeEnabled(
2890 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2891 Binder.getCallingUid())) {
2892 // Do not allow this API to be called on API version 31+, it should only be
2893 // called on old apps using this Binder call directly.
2894 throw new SecurityException("This method can only be used for applications "
2895 + "targeting API version 30 or less.");
2896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 final long identity = Binder.clearCallingIdentity();
2898 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002899 Phone phone = getPhone(getDefaultSubscription());
2900 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2901 PhoneConstantConversions.convertCallState(phone.getState());
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
2904 }
2905 }
2906
2907 @Override
2908 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2909 if (CompatChanges.isChangeEnabled(
2910 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2911 Binder.getCallingUid())) {
2912 // Check READ_PHONE_STATE for API version 31+
2913 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2914 featureId, "getCallStateForSubscription")) {
2915 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2916 + "targeting API level 31+.");
2917 }
2918 }
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2923 PhoneConstantConversions.convertCallState(phone.getState());
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002930 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002931 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2932 }
2933
2934 @Override
2935 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002938 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 if (phone != null) {
Jack Yu4accbd92021-11-29 11:36:17 -08002940 if (phone.isUsingNewDataStack()) {
2941 return phone.getDataNetworkController().getInternetDataNetworkState();
2942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2944 } else {
2945 return PhoneConstantConversions.convertDataState(
2946 PhoneConstants.DataState.DISCONNECTED);
2947 }
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002951 }
2952
Sanket Padawe356d7632015-06-22 14:03:32 -07002953 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002954 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002955 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2956 }
2957
2958 @Override
2959 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 final long identity = Binder.clearCallingIdentity();
2961 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002962 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963 if (phone != null) {
2964 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2965 } else {
2966 return TelephonyManager.DATA_ACTIVITY_NONE;
2967 }
2968 } finally {
2969 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
2972
2973 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002974 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002975 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002976 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002977
2978 LocationAccessPolicy.LocationPermissionResult locationResult =
2979 LocationAccessPolicy.checkLocationPermission(mApp,
2980 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2981 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002982 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002983 .setCallingPid(Binder.getCallingPid())
2984 .setCallingUid(Binder.getCallingUid())
2985 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002986 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002987 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2988 .build());
2989 switch (locationResult) {
2990 case DENIED_HARD:
2991 throw new SecurityException("Not allowed to access cell location");
2992 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002993 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2994 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002995 }
2996
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002997 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003001 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003002 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 } finally {
3004 Binder.restoreCallingIdentity(identity);
3005 }
Svetoslav64fad262015-04-14 14:35:21 -07003006 }
3007
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003008 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003009 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003010 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3011 // registered cell info, so return a NULL country instead.
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003014 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3015 // Get default phone in this case.
3016 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3017 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003018 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003020 if (phone == null) return "";
3021 ServiceStateTracker sst = phone.getServiceStateTracker();
3022 if (sst == null) return "";
3023 LocaleTracker lt = sst.getLocaleTracker();
3024 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003025 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003026 } finally {
3027 Binder.restoreCallingIdentity(identity);
3028 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003029 }
3030
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003031 /**
3032 * This method was removed due to potential issues caused by performing partial
3033 * updates of service state, and lack of a credible use case.
3034 *
3035 * This has the ability to break the telephony implementation by disabling notification of
3036 * changes in device connectivity. DO NOT USE THIS!
3037 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003038 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003039 public void enableLocationUpdates() {
3040 mApp.enforceCallingOrSelfPermission(
3041 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 }
3043
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003044 /**
3045 * This method was removed due to potential issues caused by performing partial
3046 * updates of service state, and lack of a credible use case.
3047 *
3048 * This has the ability to break the telephony implementation by disabling notification of
3049 * changes in device connectivity. DO NOT USE THIS!
3050 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 @Override
3052 public void disableLocationUpdates() {
3053 mApp.enforceCallingOrSelfPermission(
3054 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055 }
3056
3057 @Override
3058 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003059 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3060 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003061 try {
3062 mApp.getSystemService(AppOpsManager.class)
3063 .checkPackage(Binder.getCallingUid(), callingPackage);
3064 } catch (SecurityException e) {
3065 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3066 throw e;
3067 }
3068
Nathan Haroldf096d982020-11-18 17:18:06 -08003069 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003070 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3071 throw new SecurityException(
3072 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3073 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003074
Jordan Liu1617b712019-07-10 15:06:26 -07003075 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003076 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3077 return null;
3078 }
Svetoslav64fad262015-04-14 14:35:21 -07003079
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003080 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003082 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003083 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084
Nathan Haroldf180aac2018-06-01 18:43:55 -07003085 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3086 for (CellInfo ci : info) {
3087 if (ci instanceof CellInfoGsm) {
3088 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3089 } else if (ci instanceof CellInfoWcdma) {
3090 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003092 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003093 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 }
3095
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003096 private List<CellInfo> getCachedCellInfo() {
3097 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3098 for (Phone phone : PhoneFactory.getPhones()) {
3099 List<CellInfo> info = phone.getAllCellInfo();
3100 if (info != null) cellInfos.addAll(info);
3101 }
3102 return cellInfos;
3103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104
3105 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003106 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003107 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003108 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003109
3110 LocationAccessPolicy.LocationPermissionResult locationResult =
3111 LocationAccessPolicy.checkLocationPermission(mApp,
3112 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3113 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003114 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003115 .setCallingPid(Binder.getCallingPid())
3116 .setCallingUid(Binder.getCallingUid())
3117 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003118 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003119 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3120 .build());
3121 switch (locationResult) {
3122 case DENIED_HARD:
3123 throw new SecurityException("Not allowed to access cell info");
3124 case DENIED_SOFT:
3125 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 }
3127
Nathan Haroldf096d982020-11-18 17:18:06 -08003128 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003129 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3130 return getCachedCellInfo();
3131 }
3132
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003133 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003134 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3138 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003139 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003140 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141 if (info != null) cellInfos.addAll(info);
3142 }
3143 return cellInfos;
3144 } finally {
3145 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146 }
3147 }
3148
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003149 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003150 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3151 String callingFeatureId) {
3152 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3153 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003154 }
3155
3156 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003157 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3158 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003159 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003160 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003161 }
3162
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003163 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3164 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003165 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003166 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003167
3168 LocationAccessPolicy.LocationPermissionResult locationResult =
3169 LocationAccessPolicy.checkLocationPermission(mApp,
3170 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3171 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003172 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003173 .setCallingPid(Binder.getCallingPid())
3174 .setCallingUid(Binder.getCallingUid())
3175 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003176 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3177 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003178 .build());
3179 switch (locationResult) {
3180 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003181 if (TelephonyPermissions
3182 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003183 // Safetynet logging for b/154934934
3184 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3185 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003186 throw new SecurityException("Not allowed to access cell info");
3187 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003188 if (TelephonyPermissions
3189 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003190 // Safetynet logging for b/154934934
3191 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3192 }
Nathan Harold5320c422019-05-09 10:26:08 -07003193 try {
3194 cb.onCellInfo(new ArrayList<CellInfo>());
3195 } catch (RemoteException re) {
3196 // Drop without consequences
3197 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003198 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003199 }
3200
Nathan Harolda939a962019-05-09 10:13:47 -07003201
3202 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003203 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3204
3205 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3206 }
3207
3208 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003210 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003211 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003215 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 }
3220
Shishir Agrawala9f32182016-04-12 12:00:16 -07003221 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003222 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003223 Phone phone = PhoneFactory.getPhone(slotIndex);
3224 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003225 return null;
3226 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003227 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003228 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003229 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003230 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003231 return null;
3232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233
3234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 return phone.getImei();
3237 } finally {
3238 Binder.restoreCallingIdentity(identity);
3239 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003240 }
3241
3242 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003243 public String getTypeAllocationCodeForSlot(int slotIndex) {
3244 Phone phone = PhoneFactory.getPhone(slotIndex);
3245 String tac = null;
3246 if (phone != null) {
3247 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003248 try {
3249 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3250 } catch (IndexOutOfBoundsException e) {
3251 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3252 return null;
3253 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003254 }
3255 return tac;
3256 }
3257
3258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003259 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003260 try {
3261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3262 } catch (SecurityException se) {
3263 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3264 throw new SecurityException("Package " + callingPackage + " does not belong to "
3265 + Binder.getCallingUid());
3266 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003267 Phone phone = PhoneFactory.getPhone(slotIndex);
3268 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003269 return null;
3270 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271
Jeff Davidson913390f2018-02-23 17:11:49 -08003272 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003273 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003274 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003275 return null;
3276 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 return phone.getMeid();
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
Jack Yu2af8d712017-03-15 17:14:14 -07003284 }
3285
3286 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003287 public String getManufacturerCodeForSlot(int slotIndex) {
3288 Phone phone = PhoneFactory.getPhone(slotIndex);
3289 String manufacturerCode = null;
3290 if (phone != null) {
3291 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003292 try {
3293 manufacturerCode =
3294 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3295 } catch (IndexOutOfBoundsException e) {
3296 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3297 return null;
3298 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003299 }
3300 return manufacturerCode;
3301 }
3302
3303 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003304 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3305 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003306 Phone phone = PhoneFactory.getPhone(slotIndex);
3307 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003308 return null;
3309 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003310 int subId = phone.getSubId();
3311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003312 mApp, subId, callingPackage, callingFeatureId,
3313 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003314 return null;
3315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316
3317 final long identity = Binder.clearCallingIdentity();
3318 try {
3319 return phone.getDeviceSvn();
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
3322 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003323 }
3324
fionaxu43304da2017-11-27 22:51:16 -08003325 @Override
3326 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 final Phone phone = getPhone(subId);
3330 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
fionaxu43304da2017-11-27 22:51:16 -08003334 }
3335
3336 @Override
3337 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 final long identity = Binder.clearCallingIdentity();
3339 try {
3340 final Phone phone = getPhone(subId);
3341 return phone == null ? null : phone.getCarrierName();
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
fionaxu43304da2017-11-27 22:51:16 -08003345 }
3346
calvinpanffe225e2018-11-01 19:43:06 +08003347 @Override
chen xu0026ca62019-03-06 15:28:50 -08003348 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 final Phone phone = getPhone(subId);
3352 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003353 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
3357 }
3358
3359 @Override
chen xu0026ca62019-03-06 15:28:50 -08003360 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003364 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
3368 }
3369
chen xu651eec72018-11-11 19:03:44 -08003370 @Override
chen xu864e11c2018-12-06 22:10:03 -08003371 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3372 if (!isSubscriptionMccMnc) {
3373 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3374 }
chen xu651eec72018-11-11 19:03:44 -08003375 final Phone phone = PhoneFactory.getPhone(slotIndex);
3376 if (phone == null) {
3377 return TelephonyManager.UNKNOWN_CARRIER_ID;
3378 }
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3382 } finally {
3383 Binder.restoreCallingIdentity(identity);
3384 }
3385 }
3386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387 //
3388 // Internal helper methods.
3389 //
3390
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003391 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003392 * Make sure the caller is the calling package itself
3393 *
3394 * @throws SecurityException if the caller is not the calling package
3395 */
3396 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3397 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003398 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3399 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003400 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003401 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003402 } catch (PackageManager.NameNotFoundException e) {
3403 // packageUid is -1
3404 }
3405 if (packageUid != callingUid) {
3406 throw new SecurityException(message + ": Package " + callingPackage
3407 + " does not belong to " + callingUid);
3408 }
3409 }
3410
3411 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003412 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3413 *
3414 * @throws SecurityException if the caller does not have the required permission
3415 */
3416 private void enforceModifyPermission() {
3417 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3418 }
3419
Shuo Qian3b6ee772019-11-13 17:43:31 -08003420 private void enforceActiveEmergencySessionPermission() {
3421 mApp.enforceCallingOrSelfPermission(
3422 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3423 }
3424
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003425 /**
3426 * Make sure the caller has the CALL_PHONE permission.
3427 *
3428 * @throws SecurityException if the caller does not have the required permission
3429 */
3430 private void enforceCallPermission() {
3431 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3432 }
3433
paulhu5a773602019-08-23 19:17:33 +08003434 private void enforceSettingsPermission() {
3435 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003436 }
3437
Michele Berionne5e411512020-11-13 02:36:59 +00003438 private void enforceRebootPermission() {
3439 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3440 }
3441
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003442 private String createTelUrl(String number) {
3443 if (TextUtils.isEmpty(number)) {
3444 return null;
3445 }
3446
Jake Hambye994d462014-02-03 13:10:13 -08003447 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 }
3449
Ihab Awadf9e92732013-12-05 18:02:52 -08003450 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3452 }
3453
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003454 private static void logv(String msg) {
3455 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3456 }
3457
Ihab Awadf9e92732013-12-05 18:02:52 -08003458 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003459 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3460 }
3461
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003462 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003464 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003465 }
3466
Sanket Padawe356d7632015-06-22 14:03:32 -07003467 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003468 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469 final long identity = Binder.clearCallingIdentity();
3470 try {
3471 final Phone phone = PhoneFactory.getPhone(slotIndex);
3472 if (phone == null) {
3473 return PhoneConstants.PHONE_TYPE_NONE;
3474 } else {
3475 return phone.getPhoneType();
3476 }
3477 } finally {
3478 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003480 }
3481
3482 /**
3483 * Returns the CDMA ERI icon index to display
3484 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003485 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003486 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3487 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3488 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003489 }
3490
Sanket Padawe356d7632015-06-22 14:03:32 -07003491 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003492 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3493 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003495 mApp, subId, callingPackage, callingFeatureId,
3496 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003497 return -1;
3498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003499
3500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 final Phone phone = getPhone(subId);
3503 if (phone != null) {
3504 return phone.getCdmaEriIconIndex();
3505 } else {
3506 return -1;
3507 }
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511 }
3512
3513 /**
3514 * Returns the CDMA ERI icon mode,
3515 * 0 - ON
3516 * 1 - FLASHING
3517 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003518 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003519 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3520 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3521 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003522 }
3523
Sanket Padawe356d7632015-06-22 14:03:32 -07003524 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003525 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3526 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003528 mApp, subId, callingPackage, callingFeatureId,
3529 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003530 return -1;
3531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532
3533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 final Phone phone = getPhone(subId);
3536 if (phone != null) {
3537 return phone.getCdmaEriIconMode();
3538 } else {
3539 return -1;
3540 }
3541 } finally {
3542 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003544 }
3545
3546 /**
3547 * Returns the CDMA ERI text,
3548 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003550 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3551 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3552 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003553 }
3554
Sanket Padawe356d7632015-06-22 14:03:32 -07003555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3557 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003559 mApp, subId, callingPackage, callingFeatureId,
3560 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003561 return null;
3562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003563
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 final Phone phone = getPhone(subId);
3567 if (phone != null) {
3568 return phone.getCdmaEriText();
3569 } else {
3570 return null;
3571 }
3572 } finally {
3573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003575 }
3576
3577 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003578 * Returns the CDMA MDN.
3579 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003580 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003581 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3583 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584
3585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003588 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589 return phone.getLine1Number();
3590 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592 return null;
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003596 }
3597 }
3598
3599 /**
3600 * Returns the CDMA MIN.
3601 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003602 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003603 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3605 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606
3607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 final Phone phone = getPhone(subId);
3610 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3611 return phone.getCdmaMin();
3612 } else {
3613 return null;
3614 }
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003617 }
3618 }
3619
Hall Liud892bec2018-11-30 14:51:45 -08003620 @Override
3621 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3622 INumberVerificationCallback callback, String callingPackage) {
3623 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3624 != PERMISSION_GRANTED) {
3625 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3626 }
3627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3628
3629 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3630 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003631 throw new SecurityException("Calling package must be configured in the device config: "
3632 + "calling package: " + callingPackage
3633 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003634 }
3635
3636 if (range == null) {
3637 throw new NullPointerException("Range must be non-null");
3638 }
3639
3640 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003641 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003642
3643 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3644 }
3645
Junda Liuca05d5d2014-08-14 22:36:34 -07003646 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003647 * Returns true if CDMA provisioning needs to run.
3648 */
3649 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650 final long identity = Binder.clearCallingIdentity();
3651 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003656 }
3657
3658 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003659 * Sets the voice mail number of a given subId.
3660 */
3661 @Override
3662 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003663 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3664 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3669 new Pair<String, String>(alphaTag, number), new Integer(subId));
3670 return success;
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
3673 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003674 }
3675
Ta-wei Yen87c49842016-05-13 21:19:52 -07003676 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003677 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003679 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3680 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003681 if (!TextUtils.equals(callingPackage, systemDialer)) {
3682 throw new SecurityException("caller must be system dialer");
3683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684
3685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3688 if (phoneAccountHandle == null) {
3689 return null;
3690 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003691 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003694 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003695 }
3696
3697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003698 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3699 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003700 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003702 mApp, subId, callingPackage, callingFeatureId,
3703 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003704 return null;
3705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003707 final long identity = Binder.clearCallingIdentity();
3708 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003709 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003713 }
3714
3715 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003716 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3717 VisualVoicemailSmsFilterSettings settings) {
3718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003727 }
3728
3729 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003730 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3731 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732
3733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003736 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003740 }
3741
3742 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003743 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3744 String callingPackage, int subId) {
3745 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
3747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003750 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 } finally {
3752 Binder.restoreCallingIdentity(identity);
3753 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003754 }
3755
3756 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003757 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759
3760 final long identity = Binder.clearCallingIdentity();
3761 try {
3762 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003763 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003767 }
3768
3769 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003770 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3771 String callingAttributionTag, int subId, String number, int port, String text,
3772 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003774 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003775 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003776 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003777 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3778 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003779 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003780
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003781 /**
fionaxu0152e512016-11-14 13:36:14 -08003782 * Sets the voice activation state of a given subId.
3783 */
3784 @Override
3785 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3787 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788
3789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 final Phone phone = getPhone(subId);
3792 if (phone != null) {
3793 phone.setVoiceActivationState(activationState);
3794 } else {
3795 loge("setVoiceActivationState fails with invalid subId: " + subId);
3796 }
3797 } finally {
3798 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003799 }
3800 }
3801
3802 /**
3803 * Sets the data activation state of a given subId.
3804 */
3805 @Override
3806 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3808 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809
3810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 final Phone phone = getPhone(subId);
3813 if (phone != null) {
3814 phone.setDataActivationState(activationState);
3815 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003816 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 }
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003820 }
3821 }
3822
3823 /**
3824 * Returns the voice activation state of a given subId.
3825 */
3826 @Override
3827 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829
fionaxu0152e512016-11-14 13:36:14 -08003830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 if (phone != null) {
3834 return phone.getVoiceActivationState();
3835 } else {
3836 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3837 }
3838 } finally {
3839 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003840 }
3841 }
3842
3843 /**
3844 * Returns the data activation state of a given subId.
3845 */
3846 @Override
3847 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003848 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849
fionaxu0152e512016-11-14 13:36:14 -08003850 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 if (phone != null) {
3854 return phone.getDataActivationState();
3855 } else {
3856 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3857 }
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003860 }
3861 }
3862
3863 /**
Wink Saville36469e72014-06-11 15:17:00 -07003864 * Returns the unread count of voicemails for a subId
3865 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003866 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003867 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3868 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003870 mApp, subId, callingPackage, callingFeatureId,
3871 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003872 return 0;
3873 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874 final long identity = Binder.clearCallingIdentity();
3875 try {
3876 final Phone phone = getPhone(subId);
3877 if (phone != null) {
3878 return phone.getVoiceMessageCount();
3879 } else {
3880 return 0;
3881 }
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003885 }
3886
3887 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003888 * returns true, if the device is in a state where both voice and data
3889 * are supported simultaneously. This can change based on location or network condition.
3890 */
3891 @Override
3892 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 final Phone phone = getPhone(subId);
3896 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
3899 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003900 }
3901
3902 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003903 * Send the dialer code if called from the current default dialer or the caller has
3904 * carrier privilege.
3905 * @param inputCode The dialer code to send
3906 */
3907 @Override
3908 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003911 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3912 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003913 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003914 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003915 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917
3918 final long identity = Binder.clearCallingIdentity();
3919 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003920 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
fionaxu235cc5e2017-03-06 22:25:57 -08003924 }
3925
Pengquan Menga1bb6272018-09-06 09:59:22 -07003926 @Override
3927 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003928 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003929 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003930 mApp, subId, "getNetworkSelectionMode");
3931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 if (!isActiveSubscription(subId)) {
3934 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3935 }
3936 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003939 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003940 }
3941
Brad Ebinger35c841c2018-10-01 10:40:55 -07003942 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003943 public boolean isInEmergencySmsMode() {
3944 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3945 final long identity = Binder.clearCallingIdentity();
3946 try {
3947 for (Phone phone : PhoneFactory.getPhones()) {
3948 if (phone.isInEmergencySmsMode()) {
3949 return true;
3950 }
3951 }
3952 } finally {
3953 Binder.restoreCallingIdentity(identity);
3954 }
3955 return false;
3956 }
3957
shilu366312e2019-12-17 09:28:10 -08003958 /**
3959 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3960 * @param subId The subscription to use to check the configuration.
3961 * @param c The callback that will be used to send the result.
3962 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003963 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003964 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3965 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003966 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003967 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003968
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003969 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3970 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3971 "IMS not available on device.");
3972 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 final long token = Binder.clearCallingIdentity();
3974 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003975 int slotId = getSlotIndexOrException(subId);
3976 verifyImsMmTelConfiguredOrThrow(slotId);
3977 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003978 } catch (ImsException e) {
3979 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 } finally {
3981 Binder.restoreCallingIdentity(token);
3982 }
3983 }
3984
shilu366312e2019-12-17 09:28:10 -08003985 /**
3986 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3987 * @param subId The subscription to use to check the configuration.
3988 * @param c The callback that will be used to send the result.
3989 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003991 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003992 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003993 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003994 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3995 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3996 }
Meng Wangafbc5852019-09-19 17:37:13 -07003997 final long token = Binder.clearCallingIdentity();
3998 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003999 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4000 .removeRegistrationCallbackForSubscription(c, subId);
4001 } catch (ImsException e) {
4002 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4003 + "is inactive, ignoring unregister.");
4004 // If the subscription is no longer active, just return, since the callback
4005 // will already have been removed internally.
4006 } finally {
4007 Binder.restoreCallingIdentity(token);
4008 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 }
4010
Brad Ebingera34a6c22019-10-22 17:36:18 -07004011 /**
4012 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4013 */
4014 @Override
4015 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4016 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4017 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4018 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4019 "IMS not available on device.");
4020 }
4021 final long token = Binder.clearCallingIdentity();
4022 try {
4023 Phone phone = getPhone(subId);
4024 if (phone == null) {
4025 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4026 + subId + "'");
4027 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4028 }
4029 phone.getImsRegistrationState(regState -> {
4030 try {
4031 consumer.accept((regState == null)
4032 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4033 } catch (RemoteException e) {
4034 // Ignore if the remote process is no longer available to call back.
4035 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4036 }
4037 });
4038 } finally {
4039 Binder.restoreCallingIdentity(token);
4040 }
4041 }
4042
4043 /**
4044 * Get the transport type for the IMS service registration state.
4045 */
4046 @Override
4047 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004048 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004049 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004050 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4051 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4052 "IMS not available on device.");
4053 }
4054 final long token = Binder.clearCallingIdentity();
4055 try {
4056 Phone phone = getPhone(subId);
4057 if (phone == null) {
4058 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4059 + subId + "'");
4060 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4061 }
4062 phone.getImsRegistrationTech(regTech -> {
4063 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4064 int regTechConverted = (regTech == null)
4065 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4066 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4067 regTechConverted);
4068 try {
4069 consumer.accept(regTechConverted);
4070 } catch (RemoteException e) {
4071 // Ignore if the remote process is no longer available to call back.
4072 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4073 }
4074 });
4075 } finally {
4076 Binder.restoreCallingIdentity(token);
4077 }
4078 }
4079
shilu366312e2019-12-17 09:28:10 -08004080 /**
4081 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4082 * @param subId The subscription to use to check the configuration.
4083 * @param c The callback that will be used to send the result.
4084 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004086 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4087 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004088 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004089 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004090 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4091 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4092 "IMS not available on device.");
4093 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 final long token = Binder.clearCallingIdentity();
4095 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004096 int slotId = getSlotIndexOrException(subId);
4097 verifyImsMmTelConfiguredOrThrow(slotId);
4098 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (ImsException e) {
4100 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 } finally {
4102 Binder.restoreCallingIdentity(token);
4103 }
4104 }
4105
shilu366312e2019-12-17 09:28:10 -08004106 /**
4107 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4108 * @param subId The subscription to use to check the configuration.
4109 * @param c The callback that will be used to send the result.
4110 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004112 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004113 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004114 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004115 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4116 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4117 }
Meng Wangafbc5852019-09-19 17:37:13 -07004118
4119 final long token = Binder.clearCallingIdentity();
4120 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004121 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004122 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004123 } catch (ImsException e) {
4124 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4125 + "is inactive, ignoring unregister.");
4126 // If the subscription is no longer active, just return, since the callback
4127 // will already have been removed internally.
4128 } finally {
4129 Binder.restoreCallingIdentity(token);
4130 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 }
4132
4133 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004134 public boolean isCapable(int subId, int capability, int regTech) {
4135 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 final long token = Binder.clearCallingIdentity();
4137 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004138 int slotId = getSlotIndexOrException(subId);
4139 verifyImsMmTelConfiguredOrThrow(slotId);
4140 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004141 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4143 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004144 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004145 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4146 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 } finally {
4148 Binder.restoreCallingIdentity(token);
4149 }
4150 }
4151
4152 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004153 public boolean isAvailable(int subId, int capability, int regTech) {
4154 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 final long token = Binder.clearCallingIdentity();
4156 try {
4157 Phone phone = getPhone(subId);
4158 if (phone == null) return false;
4159 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004160 } catch (com.android.ims.ImsException e) {
4161 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4162 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 } finally {
4164 Binder.restoreCallingIdentity(token);
4165 }
4166 }
4167
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004168 /**
4169 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4170 * subscription.
4171 * @param subId The subscription to use to check the configuration.
4172 * @param callback The callback that will be used to send the result.
4173 * @param capability The MmTelFeature capability that will be used to send the result.
4174 * @param transportType The transport type of the MmTelFeature capability.
4175 */
4176 @Override
4177 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4178 int transportType) {
4179 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4180 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4181 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4182 "IMS not available on device.");
4183 }
4184 final long token = Binder.clearCallingIdentity();
4185 try {
4186 int slotId = getSlotIndex(subId);
4187 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4188 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4189 + subId + "'");
4190 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4191 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004192 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004193 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4194 transportType, aBoolean -> {
4195 try {
4196 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4197 } catch (RemoteException e) {
4198 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4199 + "running. Ignore");
4200 }
4201 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004202 } catch (ImsException e) {
4203 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004204 } finally {
4205 Binder.restoreCallingIdentity(token);
4206 }
4207 }
4208
shilu366312e2019-12-17 09:28:10 -08004209 /**
4210 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4211 * @param subId The subscription to use to check the configuration.
4212 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 @Override
4214 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004215 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004216 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004217
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 final long token = Binder.clearCallingIdentity();
4219 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004220 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004221 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004222 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 } catch (ImsException e) {
4224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 } finally {
4226 Binder.restoreCallingIdentity(token);
4227 }
4228 }
4229
4230 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004231 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004233 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 final long identity = Binder.clearCallingIdentity();
4235 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004236 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004237 // This setting doesn't require an active ImsService connection, so do not verify. The
4238 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004239 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004240 } catch (ImsException e) {
4241 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
4245 }
4246
shilu366312e2019-12-17 09:28:10 -08004247 /**
4248 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4249 * @param subId The subscription to use to check the configuration.
4250 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004252 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004253 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004254 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 final long identity = Binder.clearCallingIdentity();
4256 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004257 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004258 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004260 } catch (ImsException e) {
4261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
4265 }
4266
4267 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004268 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004270 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 final long identity = Binder.clearCallingIdentity();
4272 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004273 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004274 // This setting doesn't require an active ImsService connection, so do not verify. The
4275 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004276 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004277 } catch (ImsException e) {
4278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
4282 }
4283
shilu366312e2019-12-17 09:28:10 -08004284 /**
4285 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4286 * @param subId The subscription to use to check the configuration.
4287 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 @Override
4289 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004290 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004291 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 final long identity = Binder.clearCallingIdentity();
4293 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004294 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004295 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004297 } catch (ImsException e) {
4298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
4302 }
4303
4304 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004305 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004307 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 final long identity = Binder.clearCallingIdentity();
4309 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004310 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004311 // This setting doesn't require an active ImsService connection, so do not verify. The
4312 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004313 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004314 } catch (ImsException e) {
4315 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
4319 }
4320
shilu366312e2019-12-17 09:28:10 -08004321 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004322 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4323 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4324 * @param subId The subscription to use to check the configuration.
4325 */
4326 @Override
4327 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004328 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004329 mApp, subId, "isCrossSimCallingEnabledByUser");
4330 final long identity = Binder.clearCallingIdentity();
4331 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004332 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004333 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004335 } catch (ImsException e) {
4336 throw new ServiceSpecificException(e.getCode());
4337 } finally {
4338 Binder.restoreCallingIdentity(identity);
4339 }
4340 }
4341
4342 /**
4343 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4344 * Requires MODIFY_PHONE_STATE permission.
4345 * @param subId The subscription to use to check the configuration.
4346 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4347 * false otherwise
4348 */
4349 @Override
4350 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4352 "setCrossSimCallingEnabled");
4353 final long identity = Binder.clearCallingIdentity();
4354 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004355 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004356 // This setting doesn't require an active ImsService connection, so do not verify. The
4357 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004359 } catch (ImsException e) {
4360 throw new ServiceSpecificException(e.getCode());
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
4364 }
4365
4366 /**
shilu366312e2019-12-17 09:28:10 -08004367 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4368 * @param subId The subscription to use to check the configuration.
4369 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004371
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004373 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004374 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 final long identity = Binder.clearCallingIdentity();
4376 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004377 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004378 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (ImsException e) {
4381 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
4385 }
4386
4387 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004388 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004390 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 final long identity = Binder.clearCallingIdentity();
4392 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004394 // This setting doesn't require an active ImsService connection, so do not verify. The
4395 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004396 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004397 } catch (ImsException e) {
4398 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004399 } finally {
4400 Binder.restoreCallingIdentity(identity);
4401 }
4402 }
4403
4404 @Override
4405 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4407 "setVoWiFiNonPersistent");
4408 final long identity = Binder.clearCallingIdentity();
4409 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004410 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004411 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004413 } catch (ImsException e) {
4414 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
4418 }
4419
shilu366312e2019-12-17 09:28:10 -08004420 /**
4421 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4422 * @param subId The subscription to use to check the configuration.
4423 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004424 @Override
4425 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004426 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004427 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004428 final long identity = Binder.clearCallingIdentity();
4429 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004430 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004431 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004432 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004433 } catch (ImsException e) {
4434 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
4438 }
4439
4440 @Override
4441 public void setVoWiFiModeSetting(int subId, int mode) {
4442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4443 "setVoWiFiModeSetting");
4444 final long identity = Binder.clearCallingIdentity();
4445 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004446 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004447 // This setting doesn't require an active ImsService connection, so do not verify. The
4448 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004449 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004450 } catch (ImsException e) {
4451 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
4455 }
4456
4457 @Override
4458 public int getVoWiFiRoamingModeSetting(int subId) {
4459 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4460 final long identity = Binder.clearCallingIdentity();
4461 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004462 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004463 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004465 } catch (ImsException e) {
4466 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 } finally {
4468 Binder.restoreCallingIdentity(identity);
4469 }
4470 }
4471
4472 @Override
4473 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4475 "setVoWiFiRoamingModeSetting");
4476 final long identity = Binder.clearCallingIdentity();
4477 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004479 // This setting doesn't require an active ImsService connection, so do not verify. The
4480 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004482 } catch (ImsException e) {
4483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
4487 }
4488
4489 @Override
4490 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4492 "setRttCapabilityEnabled");
4493 final long identity = Binder.clearCallingIdentity();
4494 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004496 // This setting doesn't require an active ImsService connection, so do not verify. The
4497 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004499 } catch (ImsException e) {
4500 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504 }
4505
shilu366312e2019-12-17 09:28:10 -08004506 /**
4507 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4508 * @param subId The subscription to use to check the configuration.
4509 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 @Override
4511 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004512 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004513 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004514 final long identity = Binder.clearCallingIdentity();
4515 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004516 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004517 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004519 } catch (ImsException e) {
4520 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
4524 }
4525
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004526 @Override
4527 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4528 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004529
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004530 final long identity = Binder.clearCallingIdentity();
4531 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004532 if (!isImsAvailableOnDevice()) {
4533 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4534 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004535 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004536 int slotId = getSlotIndexOrException(subId);
4537 verifyImsMmTelConfiguredOrThrow(slotId);
4538 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004539 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004540 } catch (ImsException e) {
4541 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004542 } finally {
4543 Binder.restoreCallingIdentity(identity);
4544 }
4545 }
4546
4547 @Override
4548 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4549 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004550
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004551 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4553 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4554 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004555 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004556 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004557 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004559 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4560 + "is inactive, ignoring unregister.");
4561 // If the subscription is no longer active, just return, since the callback will already
4562 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
4566 }
4567
joonhunshin2c3e4232021-11-28 07:32:01 +00004568 @Override
4569 public void registerFeatureProvisioningChangedCallback(int subId,
4570 IFeatureProvisioningCallback callback) {
4571 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4572 mApp, subId, "registerFeatureProvisioningChangedCallback");
4573
4574 final long identity = Binder.clearCallingIdentity();
4575 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4576 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4577 }
4578
4579 ImsProvisioningController.getInstance()
4580 .addFeatureProvisioningChangedCallback(subId, callback);
4581
4582 Binder.restoreCallingIdentity(identity);
4583 }
4584
4585 @Override
4586 public void unregisterFeatureProvisioningChangedCallback(int subId,
4587 IFeatureProvisioningCallback callback) {
4588 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4589 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4590
4591 final long identity = Binder.clearCallingIdentity();
4592 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4593 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4594 }
4595
4596 ImsProvisioningController.getInstance()
4597 .removeFeatureProvisioningChangedCallback(subId, callback);
4598
4599 Binder.restoreCallingIdentity(identity);
4600 }
allenwtsu99c623b2020-01-03 18:24:23 +08004601
4602 private void checkModifyPhoneStatePermission(int subId, String message) {
4603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4604 message);
4605 }
4606
4607 private boolean isImsProvisioningRequired(int subId, int capability,
4608 boolean isMmtelCapability) {
4609 Phone phone = getPhone(subId);
4610 if (phone == null) {
4611 loge("phone instance null for subid " + subId);
4612 return false;
4613 }
4614 if (isMmtelCapability) {
4615 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4616 return false;
4617 }
4618 } else {
4619 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4620 return false;
4621 }
4622 }
4623 return true;
4624 }
4625
4626 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004627 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004628 boolean isProvisioned) {
4629 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4630
4631 final long identity = Binder.clearCallingIdentity();
4632 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004633 ImsProvisioningController.getInstance()
4634 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4635 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004636 } finally {
4637 Binder.restoreCallingIdentity(identity);
4638 }
allenwtsu99c623b2020-01-03 18:24:23 +08004639 }
4640
4641
4642 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004643 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4644 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4645 mApp, subId, "getRcsProvisioningStatusForCapability");
4646
allenwtsu99c623b2020-01-03 18:24:23 +08004647 final long identity = Binder.clearCallingIdentity();
4648 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004649 return ImsProvisioningController.getInstance()
4650 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
4654 }
4655
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004656 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4658 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004659 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshin2c3e4232021-11-28 07:32:01 +00004660
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004661 final long identity = Binder.clearCallingIdentity();
4662 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004663 ImsProvisioningController.getInstance()
4664 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
4668 }
4669
4670 @Override
4671 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshin2c3e4232021-11-28 07:32:01 +00004672 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4673 mApp, subId, "getProvisioningStatusForCapability");
4674
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675 final long identity = Binder.clearCallingIdentity();
4676 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004677 return ImsProvisioningController.getInstance()
4678 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004679
4680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
4683 }
4684
4685 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004686 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4687 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4688 mApp, subId, "isProvisioningRequiredForCapability");
4689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 return ImsProvisioningController.getInstance()
4693 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4694 } finally {
4695 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004696 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004697 }
4698
4699 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004700 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4701 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4702 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004703
joonhunshin2c3e4232021-11-28 07:32:01 +00004704 final long identity = Binder.clearCallingIdentity();
4705 try {
4706 return ImsProvisioningController.getInstance()
4707 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4708 } finally {
4709 Binder.restoreCallingIdentity(identity);
4710 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004711 }
4712
4713 private static String getMmTelProvisioningKey(int subId, int tech) {
4714 // resulting key is provision_ims_mmtel_{subId}_{tech}
4715 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4716 }
4717
4718 /**
4719 * Query CarrierConfig to see if the specified capability requires provisioning for the
4720 * carrier associated with the subscription id.
4721 */
4722 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4723 int capability) {
4724 CarrierConfigManager configManager = new CarrierConfigManager(context);
4725 PersistableBundle c = configManager.getConfigForSubId(subId);
4726 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004727 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004728 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4729 false);
4730 boolean requireVoiceVtProvisioning = c.getBoolean(
4731 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4732
4733 // First check to make sure that the capability requires provisioning.
4734 switch (capability) {
4735 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4736 // intentional fallthrough
4737 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4738 if (requireVoiceVtProvisioning) {
4739 // Voice and Video requires provisioning
4740 return true;
4741 }
4742 break;
4743 }
4744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4745 if (requireUtProvisioning) {
4746 // UT requires provisioning
4747 return true;
4748 }
4749 break;
4750 }
4751 }
4752 return false;
4753 }
4754
allenwtsu99c623b2020-01-03 18:24:23 +08004755 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4756 int capability) {
4757 CarrierConfigManager configManager = new CarrierConfigManager(context);
4758 PersistableBundle c = configManager.getConfigForSubId(subId);
4759
4760 boolean requireRcsProvisioning = c.getBoolean(
4761 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4762
4763 // First check to make sure that the capability requires provisioning.
4764 switch (capability) {
4765 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4766 // intentional fallthrough
4767 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4768 if (requireRcsProvisioning) {
4769 // OPTION or PRESENCE requires provisioning
4770 return true;
4771 }
4772 break;
4773 }
4774 }
4775 return false;
4776 }
4777
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004778 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004779 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004780 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4781 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4782 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004783 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4784 mApp, subId, "getImsProvisioningInt");
4785
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004786 final long identity = Binder.clearCallingIdentity();
4787 try {
4788 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004789 int slotId = getSlotIndex(subId);
4790 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4791 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4792 + subId + "' for key:" + key);
4793 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4794 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004795
4796 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4797 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4798 return retVal;
4799 }
4800
calvinpanb5a34062021-02-08 19:59:36 +08004801 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004802 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004803 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4804 + subId + "' for key:" + key);
4805 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004806 } finally {
4807 Binder.restoreCallingIdentity(identity);
4808 }
4809 }
4810
4811 @Override
4812 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004813 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4814 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4815 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004816 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4817 mApp, subId, "getImsProvisioningString");
4818
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004819 final long identity = Binder.clearCallingIdentity();
4820 try {
4821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004822 int slotId = getSlotIndex(subId);
4823 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4824 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4825 + subId + "' for key:" + key);
4826 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4827 }
calvinpanb5a34062021-02-08 19:59:36 +08004828 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004829 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004830 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4831 + subId + "' for key:" + key);
4832 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
4836 }
4837
4838 @Override
4839 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004840 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4841 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4842 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4844 "setImsProvisioningInt");
joonhunshin2c3e4232021-11-28 07:32:01 +00004845
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004849 int slotId = getSlotIndex(subId);
4850 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4851 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4852 + subId + "' for key:" + key);
4853 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4854 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004855
4856 int retVal = ImsProvisioningController.getInstance()
4857 .setProvisioningValue(subId, key, value);
4858 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4859 return retVal;
4860 }
4861
calvinpanb5a34062021-02-08 19:59:36 +08004862 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4863 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004864 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004865 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004866 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
4870 }
4871
4872 @Override
4873 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004874 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4875 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4876 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4878 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004882 int slotId = getSlotIndex(subId);
4883 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4884 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4885 + subId + "' for key:" + key);
4886 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4887 }
calvinpanb5a34062021-02-08 19:59:36 +08004888 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4889 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004891 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
4896 }
4897
Brad Ebinger919631e2021-06-02 17:46:35 -07004898 /**
4899 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4900 * for the given slot ID or no ImsResolver instance has been created.
4901 * @param slotId The slot ID that the IMS service is created for.
4902 * @throws ImsException If there is no ImsService configured for this slot.
4903 */
4904 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4905 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4906 ImsFeature.FEATURE_MMTEL)) {
4907 throw new ImsException("This subscription does not support MMTEL over IMS",
4908 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4909 }
4910 }
4911
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004912 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004913 int slotId = SubscriptionManager.getSlotIndex(subId);
4914 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004915 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4916 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004917 }
4918 return slotId;
4919 }
4920
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 private int getSlotIndex(int subId) {
4922 int slotId = SubscriptionManager.getSlotIndex(subId);
4923 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4924 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4925 }
4926 return slotId;
4927 }
4928
Wink Saville36469e72014-06-11 15:17:00 -07004929 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004930 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004931 */
4932 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004933 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4934 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004935 try {
4936 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4937 } catch (SecurityException se) {
4938 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4939 throw new SecurityException("Package " + callingPackage + " does not belong to "
4940 + Binder.getCallingUid());
4941 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004942 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004943 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004944 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004945 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004946 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004947 mApp, subId, callingPackage, callingFeatureId,
4948 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004949 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4950 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 final long identity = Binder.clearCallingIdentity();
4953 try {
4954 final Phone phone = getPhone(subId);
4955 if (phone != null) {
4956 return phone.getServiceState().getDataNetworkType();
4957 } else {
4958 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4959 }
4960 } finally {
4961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004963 }
4964
4965 /**
4966 * Returns the data network type
4967 */
4968 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004969 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004970 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4971 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004972 }
4973
4974 /**
4975 * Returns the data network type for a subId
4976 */
4977 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004978 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4979 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07004980 String functionName = "getDataNetworkTypeForSubscriber";
4981 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
4982 mApp, functionName)) {
4983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4984 mApp, subId, callingPackage, callingFeatureId, functionName)) {
4985 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4986 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004987 }
4988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 final long identity = Binder.clearCallingIdentity();
4990 try {
4991 final Phone phone = getPhone(subId);
4992 if (phone != null) {
4993 return phone.getServiceState().getDataNetworkType();
4994 } else {
4995 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4996 }
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005000 }
5001
5002 /**
Wink Saville36469e72014-06-11 15:17:00 -07005003 * Returns the Voice network type for a subId
5004 */
5005 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005006 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5007 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005008 String functionName = "getVoiceNetworkTypeForSubscriber";
5009 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5010 mApp, functionName)) {
5011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5012 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5013 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5014 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005015 }
5016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 final long identity = Binder.clearCallingIdentity();
5018 try {
5019 final Phone phone = getPhone(subId);
5020 if (phone != null) {
5021 return phone.getServiceState().getVoiceNetworkType();
5022 } else {
5023 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5024 }
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005028 }
5029
5030 /**
5031 * @return true if a ICC card is present
5032 */
5033 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005034 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005035 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5036 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005037 }
5038
5039 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005040 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005041 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005042 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005043 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 final Phone phone = PhoneFactory.getPhone(slotIndex);
5047 if (phone != null) {
5048 return phone.getIccCard().hasIccCard();
5049 } else {
5050 return false;
5051 }
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005055 }
5056
5057 /**
5058 * Return if the current radio is LTE on CDMA. This
5059 * is a tri-state return value as for a period of time
5060 * the mode may be unknown.
5061 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005062 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005063 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005064 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005065 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005067 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5068 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5069 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005070 }
5071
Sanket Padawe356d7632015-06-22 14:03:32 -07005072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005073 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5074 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005075 try {
5076 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5077 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005078 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5079 }
5080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 final long identity = Binder.clearCallingIdentity();
5082 try {
5083 final Phone phone = getPhone(subId);
5084 if (phone == null) {
5085 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5086 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005087 return TelephonyProperties.lte_on_cdma_device()
5088 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 }
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005092 }
Wink Saville36469e72014-06-11 15:17:00 -07005093 }
5094
Wink Saville36469e72014-06-11 15:17:00 -07005095 /**
5096 * {@hide}
5097 * Returns Default subId, 0 in the case of single standby.
5098 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005099 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005100 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005101 }
5102
Shishir Agrawala9f32182016-04-12 12:00:16 -07005103 private int getSlotForDefaultSubscription() {
5104 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5105 }
5106
Wink Savilleb564aae2014-10-23 10:18:09 -07005107 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005108 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005109 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005110
Pengquan Menge92a50d2018-09-21 15:54:48 -07005111 private boolean isActiveSubscription(int subId) {
5112 return mSubscriptionController.isActiveSubId(subId);
5113 }
5114
Ihab Awadf2177b72013-11-25 13:33:23 -08005115 /**
5116 * @see android.telephony.TelephonyManager.WifiCallingChoices
5117 */
5118 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 final long identity = Binder.clearCallingIdentity();
5120 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005121 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5123 getWhenToMakeWifiCallsDefaultPreference());
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
5126 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005127 }
5128
5129 /**
5130 * @see android.telephony.TelephonyManager.WifiCallingChoices
5131 */
5132 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005136 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
5140 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005141 }
5142
Sailesh Nepald1e68152013-12-12 19:08:02 -08005143 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005144 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005145 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005146 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005147
Jordan Liu4c733742019-02-28 12:03:40 -08005148 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5149 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5150 if (phoneId == -1) {
5151 throw new IllegalArgumentException("Given slot index: " + slotIndex
5152 + " does not correspond to an active phone");
5153 }
5154 return PhoneFactory.getPhone(phoneId);
5155 }
5156
Shishir Agrawal566b7612013-10-28 14:41:00 -07005157 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005158 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5159 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5161 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005163 if (DBG) {
5164 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5165 }
5166 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5167 p2);
5168 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005169
Jordan Liu4c733742019-02-28 12:03:40 -08005170
5171 @Override
5172 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5173 int slotIndex, String callingPackage, String aid, int p2) {
5174 enforceModifyPermission();
5175 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5176 if (DBG) {
5177 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5178 }
5179 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5180 callingPackage, aid, p2);
5181 }
5182
5183 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5184 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 if (TextUtils.equals(ISDR_AID, aid)) {
5188 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005189 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5190 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 if (bestComponent == null
5192 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5193 loge("The calling package is not allowed to access ISD-R.");
5194 throw new SecurityException(
5195 "The calling package is not allowed to access ISD-R.");
5196 }
Derek Tan740e1672017-06-27 14:56:27 -07005197 }
Derek Tan740e1672017-06-27 14:56:27 -07005198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005200 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5201 null /* workSource */);
5202 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 return response;
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
5206 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005207 }
5208
5209 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005210 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5212 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005213 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5214 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5215 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005216
Jordan Liu4c733742019-02-28 12:03:40 -08005217 @Override
5218 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5219 enforceModifyPermission();
5220 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5221 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5222 channel);
5223 }
5224
5225 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 final long identity = Binder.clearCallingIdentity();
5227 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 if (channel < 0) {
5229 return false;
5230 }
Jordan Liu4c733742019-02-28 12:03:40 -08005231 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5232 null /* workSource */);
5233 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 return success;
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005237 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005238 }
5239
5240 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005241 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005242 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5244 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005245 if (DBG) {
5246 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5247 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5248 + p3 + " data=" + data);
5249 }
5250 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5251 command, p1, p2, p3, data);
5252 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005253
Jordan Liu4c733742019-02-28 12:03:40 -08005254 @Override
5255 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5256 int command, int p1, int p2, int p3, String data) {
5257 enforceModifyPermission();
5258 if (DBG) {
5259 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5260 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5261 + p3 + " data=" + data);
5262 }
5263 return iccTransmitApduLogicalChannelWithPermission(
5264 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5265 data);
5266 }
5267
5268 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5269 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005272 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 return "";
5274 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005277 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5278 null /* workSource */);
5279 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 // Append the returned status code to the end of the response payload.
5282 String s = Integer.toHexString(
5283 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5284 if (response.payload != null) {
5285 s = IccUtils.bytesToHexString(response.payload) + s;
5286 }
5287 return s;
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005290 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005291 }
Jake Hambye994d462014-02-03 13:10:13 -08005292
Evan Charltonc66da362014-05-16 14:06:40 -07005293 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005294 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5295 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5297 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005299 if (DBG) {
5300 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5301 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5302 }
5303 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5304 cla, command, p1, p2, p3, data);
5305 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005306
Jordan Liu4c733742019-02-28 12:03:40 -08005307 @Override
5308 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5309 int command, int p1, int p2, int p3, String data) {
5310 enforceModifyPermission();
5311 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5312 if (DBG) {
5313 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5314 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5315 + " data=" + data);
5316 }
5317
5318 return iccTransmitApduBasicChannelWithPermission(
5319 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5320 p2, p3, data);
5321 }
5322
5323 // open APDU basic channel assuming the caller has sufficient permissions
5324 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5325 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5329 && TextUtils.equals(ISDR_AID, data)) {
5330 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005331 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5332 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 if (bestComponent == null
5334 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5335 loge("The calling package is not allowed to select ISD-R.");
5336 throw new SecurityException(
5337 "The calling package is not allowed to select ISD-R.");
5338 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005339 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005342 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5343 null /* workSource */);
5344 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 // Append the returned status code to the end of the response payload.
5347 String s = Integer.toHexString(
5348 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5349 if (response.payload != null) {
5350 s = IccUtils.bytesToHexString(response.payload) + s;
5351 }
5352 return s;
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005355 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005356 }
5357
5358 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005359 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005360 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5362 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 final long identity = Binder.clearCallingIdentity();
5365 try {
5366 if (DBG) {
5367 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5368 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5369 }
5370
5371 IccIoResult response =
5372 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5373 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5374 subId);
5375
5376 if (DBG) {
5377 log("Exchange SIM_IO [R]" + response);
5378 }
5379
5380 byte[] result = null;
5381 int length = 2;
5382 if (response.payload != null) {
5383 length = 2 + response.payload.length;
5384 result = new byte[length];
5385 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5386 } else {
5387 result = new byte[length];
5388 }
5389
5390 result[length - 1] = (byte) response.sw2;
5391 result[length - 2] = (byte) response.sw1;
5392 return result;
5393 } finally {
5394 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005395 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005396 }
5397
Nathan Haroldb3014052017-01-25 15:57:32 -08005398 /**
5399 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5400 * on a particular subscription
5401 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005402 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5403 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005405 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005406 return null;
5407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408
5409 final long identity = Binder.clearCallingIdentity();
5410 try {
5411 if (appType != TelephonyManager.APPTYPE_USIM
5412 && appType != TelephonyManager.APPTYPE_SIM) {
5413 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5414 return null;
5415 }
5416 Object response = sendRequest(
5417 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5418 if (response instanceof String[]) {
5419 return (String[]) response;
5420 }
yincheng zhao2737e882019-09-06 17:06:54 -07005421 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005423 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 } finally {
5425 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005426 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005427 }
5428
yincheng zhao2737e882019-09-06 17:06:54 -07005429 /**
5430 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5431 * subscription.
5432 *
5433 * @param subId the id of the subscription.
5434 * @param appType the uicc app type, must be USIM or SIM.
5435 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5436 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005437 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005438 * @return number of fplmns that is successfully written to the SIM.
5439 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005440 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5441 String callingFeatureId) {
5442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5443 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005444 if (DBG) logv("no permissions for setForbiddenplmns");
5445 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5446 }
5447 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5448 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5449 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5450 }
5451 if (fplmns == null) {
5452 throw new IllegalArgumentException("Fplmn List provided is null");
5453 }
5454 for (String fplmn : fplmns) {
5455 if (!CellIdentity.isValidPlmn(fplmn)) {
5456 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5457 }
5458 }
5459 final long identity = Binder.clearCallingIdentity();
5460 try {
5461 Object response = sendRequest(
5462 CMD_SET_FORBIDDEN_PLMNS,
5463 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5464 subId);
5465 return (int) response;
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
5468 }
5469 }
5470
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005471 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005472 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5474 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 final long identity = Binder.clearCallingIdentity();
5477 try {
5478 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5479 if (response.payload == null) {
5480 return "";
5481 }
Evan Charltonc66da362014-05-16 14:06:40 -07005482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 // Append the returned status code to the end of the response payload.
5484 String s = Integer.toHexString(
5485 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5486 s = IccUtils.bytesToHexString(response.payload) + s;
5487 return s;
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
Evan Charltonc66da362014-05-16 14:06:40 -07005491 }
5492
Jake Hambye994d462014-02-03 13:10:13 -08005493 /**
5494 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5495 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5496 *
5497 * @param itemID the ID of the item to read
5498 * @return the NV item as a String, or null on error.
5499 */
5500 @Override
5501 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005502 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5504 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505
5506 final long identity = Binder.clearCallingIdentity();
5507 try {
5508 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005509 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5511 return value;
5512 } finally {
5513 Binder.restoreCallingIdentity(identity);
5514 }
Jake Hambye994d462014-02-03 13:10:13 -08005515 }
5516
5517 /**
5518 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5519 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5520 *
5521 * @param itemID the ID of the item to read
5522 * @param itemValue the value to write, as a String
5523 * @return true on success; false on any failure
5524 */
5525 @Override
5526 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005527 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5529 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530
5531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5534 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005535 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5537 return success;
5538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540 }
Jake Hambye994d462014-02-03 13:10:13 -08005541 }
5542
5543 /**
5544 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5545 * Used for device configuration by some CDMA operators.
5546 *
5547 * @param preferredRoamingList byte array containing the new PRL
5548 * @return true on success; false on any failure
5549 */
5550 @Override
5551 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5553 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554
5555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5558 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5559 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5560 return success;
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
Jake Hambye994d462014-02-03 13:10:13 -08005564 }
5565
5566 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005567 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005568 * Used for device configuration by some CDMA operators.
5569 *
chen xu6dac5ab2018-10-26 17:39:23 -07005570 * @param slotIndex - device slot.
5571 *
Jake Hambye994d462014-02-03 13:10:13 -08005572 * @return true on success; false on any failure
5573 */
5574 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005575 public boolean resetModemConfig(int slotIndex) {
5576 Phone phone = PhoneFactory.getPhone(slotIndex);
5577 if (phone != null) {
5578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5579 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580
chen xu6dac5ab2018-10-26 17:39:23 -07005581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5584 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5585 return success;
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
5588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 }
chen xu6dac5ab2018-10-26 17:39:23 -07005590 return false;
5591 }
5592
5593 /**
5594 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5595 *
5596 * @param slotIndex - device slot.
5597 *
5598 * @return true on success; false on any failure
5599 */
5600 @Override
5601 public boolean rebootModem(int slotIndex) {
5602 Phone phone = PhoneFactory.getPhone(slotIndex);
5603 if (phone != null) {
5604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5605 mApp, phone.getSubId(), "rebootModem");
5606
5607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5610 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5611 return success;
5612 } finally {
5613 Binder.restoreCallingIdentity(identity);
5614 }
5615 }
5616 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005617 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005618
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005619 public String[] getPcscfAddress(String apnType, String callingPackage,
5620 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005621 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5623 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005624 return new String[0];
5625 }
5626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627 final long identity = Binder.clearCallingIdentity();
5628 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005629 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
Wink Saville36469e72014-06-11 15:17:00 -07005633 }
5634
Brad Ebinger51f743a2017-01-23 13:50:20 -08005635 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005636 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5637 * {@link #disableIms(int)}.
5638 * @param slotIndex device slot.
5639 */
5640 public void resetIms(int slotIndex) {
5641 enforceModifyPermission();
5642
5643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 if (mImsResolver == null) {
5646 // may happen if the does not support IMS.
5647 return;
5648 }
5649 mImsResolver.disableIms(slotIndex);
5650 mImsResolver.enableIms(slotIndex);
5651 } finally {
5652 Binder.restoreCallingIdentity(identity);
5653 }
5654 }
5655
5656 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005657 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5658 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005659 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005660 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005665 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005666 // may happen if the device does not support IMS.
5667 return;
5668 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005669 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 } finally {
5671 Binder.restoreCallingIdentity(identity);
5672 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005673 }
5674
5675 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005676 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5677 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005678 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005679 public void disableIms(int slotId) {
5680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681
5682 final long identity = Binder.clearCallingIdentity();
5683 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005684 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005685 // may happen if the device does not support IMS.
5686 return;
5687 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005688 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689 } finally {
5690 Binder.restoreCallingIdentity(identity);
5691 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005692 }
5693
5694 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005695 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5696 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005697 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005698 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005699 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005700 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701
5702 final long identity = Binder.clearCallingIdentity();
5703 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005704 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005705 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5706 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005707 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005708 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005712 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005713 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005714 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5715 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005716 @Override
5717 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005718 enforceModifyPermission();
5719
5720 final long identity = Binder.clearCallingIdentity();
5721 try {
5722 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005723 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
5727 }
5728
5729 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005730 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005731 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005732 */
5733 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5734 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005738 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005739 // may happen if the device does not support IMS.
5740 return null;
5741 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005742 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005746 }
5747
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005748 /**
5749 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005750 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005751 */
5752 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005757 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005758 // may happen if the device does not support IMS.
5759 return null;
5760 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005761 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005765 }
5766
Brad Ebinger884c07b2018-02-15 16:17:40 -08005767 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005768 * Sets the ImsService Package Name that Telephony will bind to.
5769 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 * @param slotIndex the slot ID that the ImsService should bind for.
5771 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005772 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005773 * @param featureTypes An integer array of feature types associated with a packageName.
5774 * @param packageName The name of the package that the current configuration will be replaced
5775 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005776 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005777 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005778 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5779 int[] featureTypes, String packageName) {
5780 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5783 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005784 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 final long identity = Binder.clearCallingIdentity();
5787 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005788 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005789 // may happen if the device does not support IMS.
5790 return false;
5791 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005792 Map<Integer, String> featureConfig = new HashMap<>();
5793 for (int featureType : featureTypes) {
5794 featureConfig.put(featureType, packageName);
5795 }
5796 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5797 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 } finally {
5799 Binder.restoreCallingIdentity(identity);
5800 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005801 }
5802
5803 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005804 * Clears any carrier ImsService overrides for the slot index specified that were previously
5805 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5806 *
5807 * This should only be used for testing.
5808 *
5809 * @param slotIndex the slot ID that the ImsService should bind for.
5810 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5811 */
5812 @Override
5813 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5814 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5815 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5816 "clearCarrierImsServiceOverride");
5817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5818 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5819 "clearCarrierImsServiceOverride");
5820
5821 final long identity = Binder.clearCallingIdentity();
5822 try {
5823 if (mImsResolver == null) {
5824 // may happen if the device does not support IMS.
5825 return false;
5826 }
5827 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
5830 }
5831 }
5832
5833 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005835 *
5836 * @param slotId The slot that the ImsService is associated with.
5837 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5838 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005840 * @return the package name of the ImsService configuration.
5841 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5843 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005844 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005846 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005847 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5848 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 final long identity = Binder.clearCallingIdentity();
5851 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005853 // may happen if the device does not support IMS.
5854 return "";
5855 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005856 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5858 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005862 }
5863
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005864 /**
5865 * Get the MmTelFeature state associated with the requested subscription id.
5866 * @param subId The subscription that the MmTelFeature is associated with.
5867 * @param callback A callback with an integer containing the
5868 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5869 */
5870 @Override
5871 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5872 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5873 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5874 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5875 "IMS not available on device.");
5876 }
5877 final long token = Binder.clearCallingIdentity();
5878 try {
5879 int slotId = getSlotIndex(subId);
5880 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5881 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5882 + subId + "'");
5883 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5884 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005885 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005886 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5887 try {
5888 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5889 } catch (RemoteException e) {
5890 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5891 + "Ignore");
5892 }
5893 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005894 } catch (ImsException e) {
5895 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005896 } finally {
5897 Binder.restoreCallingIdentity(token);
5898 }
5899 }
5900
Daniel Brightbb5840b2021-01-12 15:48:18 -08005901 /**
5902 * Sets the ims registration state on all valid {@link Phone}s.
5903 */
5904 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005905 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906
5907 final long identity = Binder.clearCallingIdentity();
5908 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005909 // NOTE: Before S, this method only set the default phone.
5910 for (final Phone phone : PhoneFactory.getPhones()) {
5911 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5912 phone.setImsRegistrationState(registered);
5913 }
5914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Wink Saville36469e72014-06-11 15:17:00 -07005918 }
5919
5920 /**
Stuart Scott54788802015-03-30 13:18:01 -07005921 * Set the network selection mode to automatic.
5922 *
5923 */
5924 @Override
5925 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5927 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928
5929 final long identity = Binder.clearCallingIdentity();
5930 try {
shilufc958392020-01-20 11:36:01 -08005931 if (!isActiveSubscription(subId)) {
5932 return;
5933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005935 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5936 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Stuart Scott54788802015-03-30 13:18:01 -07005940 }
5941
Jack Yud10cdd42020-09-28 20:28:01 -07005942 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005943 * Ask the radio to connect to the input network and change selection mode to manual.
5944 *
5945 * @param subId the id of the subscription.
5946 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5947 * the operator to attach to.
5948 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5949 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5950 * normal network selection next time.
5951 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005952 */
5953 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005954 public boolean setNetworkSelectionModeManual(
5955 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5957 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005958
5959 if (!isActiveSubscription(subId)) {
5960 return false;
5961 }
5962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 final long identity = Binder.clearCallingIdentity();
5964 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005965 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005967 if (DBG) {
5968 log("setNetworkSelectionModeManual: subId: " + subId
5969 + " operator: " + operatorInfo);
5970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005975 }
shilu84f6e8b2019-12-19 13:58:01 -08005976 /**
5977 * Get the manual network selection
5978 *
5979 * @param subId the id of the subscription.
5980 *
5981 * @return the previously saved user selected PLMN
5982 */
5983 @Override
5984 public String getManualNetworkSelectionPlmn(int subId) {
5985 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005986 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005987 mApp, subId, "getManualNetworkSelectionPlmn");
5988
5989 final long identity = Binder.clearCallingIdentity();
5990 try {
5991 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005992 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005993 }
5994
5995 final Phone phone = getPhone(subId);
5996 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005997 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005998 }
5999 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6000 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6001 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6002 } finally {
6003 Binder.restoreCallingIdentity(identity);
6004 }
6005 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006006
6007 /**
6008 * Scans for available networks.
6009 */
6010 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006011 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6012 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6014 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006015 LocationAccessPolicy.LocationPermissionResult locationResult =
6016 LocationAccessPolicy.checkLocationPermission(mApp,
6017 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6018 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006019 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006020 .setCallingPid(Binder.getCallingPid())
6021 .setCallingUid(Binder.getCallingUid())
6022 .setMethod("getCellNetworkScanResults")
6023 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006024 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6025 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006026 .build());
6027 switch (locationResult) {
6028 case DENIED_HARD:
6029 throw new SecurityException("Not allowed to access scan results -- location");
6030 case DENIED_SOFT:
6031 return null;
6032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033
Pengquan Menga1bb6272018-09-06 09:59:22 -07006034 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 try {
6036 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006037 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006042 }
6043
6044 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006045 * Get the call forwarding info, given the call forwarding reason.
6046 */
6047 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006048 public void getCallForwarding(int subId, int callForwardingReason,
6049 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006050 enforceReadPrivilegedPermission("getCallForwarding");
6051 long identity = Binder.clearCallingIdentity();
6052 try {
6053 if (DBG) {
6054 log("getCallForwarding: subId " + subId
6055 + " callForwardingReason" + callForwardingReason);
6056 }
Hall Liu27d24262020-09-18 19:04:59 -07006057
6058 Phone phone = getPhone(subId);
6059 if (phone == null) {
6060 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006061 callback.onError(
6062 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006063 } catch (RemoteException e) {
6064 // ignore
6065 }
6066 return;
6067 }
6068
6069 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6070 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6071 @Override
6072 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6073 try {
6074 callback.onCallForwardingInfoAvailable(info);
6075 } catch (RemoteException e) {
6076 // ignore
6077 }
6078 }
6079
6080 @Override
6081 public void onError(int error) {
6082 try {
6083 callback.onError(error);
6084 } catch (RemoteException e) {
6085 // ignore
6086 }
6087 }
6088 });
6089 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
6093 }
6094
6095 /**
6096 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6097 * reason, the number to forward, and the timeout before the forwarding is attempted.
6098 */
6099 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006100 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6101 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006102 enforceModifyPermission();
6103 long identity = Binder.clearCallingIdentity();
6104 try {
6105 if (DBG) {
6106 log("setCallForwarding: subId " + subId
6107 + " callForwardingInfo" + callForwardingInfo);
6108 }
Hall Liu27d24262020-09-18 19:04:59 -07006109
6110 Phone phone = getPhone(subId);
6111 if (phone == null) {
6112 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006113 callback.accept(
6114 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006115 } catch (RemoteException e) {
6116 // ignore
6117 }
6118 return;
6119 }
6120
6121 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6122 FunctionalUtils.ignoreRemoteException(callback::accept));
6123
6124 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006125 } finally {
6126 Binder.restoreCallingIdentity(identity);
6127 }
6128 }
6129
6130 /**
Hall Liu27d24262020-09-18 19:04:59 -07006131 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006132 */
6133 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006134 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006135 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006136 long identity = Binder.clearCallingIdentity();
6137 try {
Hall Liu27d24262020-09-18 19:04:59 -07006138 Phone phone = getPhone(subId);
6139 if (phone == null) {
6140 try {
6141 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6142 } catch (RemoteException e) {
6143 // ignore
6144 }
6145 return;
6146 }
SongFerngWang0e767992021-03-31 22:08:45 +08006147 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6148 PersistableBundle c = configManager.getConfigForSubId(subId);
6149 boolean requireUssd = c.getBoolean(
6150 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006151
Shuo Qian4a594052020-01-23 11:59:30 -08006152 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006153 if (requireUssd) {
6154 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6155 getSubscriptionCarrierId(subId));
6156 String newUssdCommand = "";
6157 try {
6158 newUssdCommand = carrierXmlParser.getFeature(
6159 CarrierXmlParser.FEATURE_CALL_WAITING)
6160 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6161 } catch (NullPointerException e) {
6162 loge("Failed to generate USSD number" + e);
6163 }
6164 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6165 mMainThreadHandler, callback, carrierXmlParser,
6166 CarrierXmlParser.SsEntry.SSAction.QUERY);
6167 final String ussdCommand = newUssdCommand;
6168 Executors.newSingleThreadExecutor().execute(() -> {
6169 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6170 });
6171 } else {
6172 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6173 callback::accept);
6174 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6175 }
Shuo Qian4a594052020-01-23 11:59:30 -08006176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
6179 }
6180
6181 /**
Hall Liu27d24262020-09-18 19:04:59 -07006182 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006183 */
6184 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006185 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006186 enforceModifyPermission();
6187 long identity = Binder.clearCallingIdentity();
6188 try {
Hall Liu27d24262020-09-18 19:04:59 -07006189 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6190
6191 Phone phone = getPhone(subId);
6192 if (phone == null) {
6193 try {
6194 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6195 } catch (RemoteException e) {
6196 // ignore
6197 }
6198 return;
6199 }
6200
SongFerngWang0e767992021-03-31 22:08:45 +08006201 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6202 PersistableBundle c = configManager.getConfigForSubId(subId);
6203 boolean requireUssd = c.getBoolean(
6204 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006205
SongFerngWang0e767992021-03-31 22:08:45 +08006206 if (DBG) log("getCallWaitingStatus: subId " + subId);
6207 if (requireUssd) {
6208 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6209 getSubscriptionCarrierId(subId));
6210 CarrierXmlParser.SsEntry.SSAction ssAction =
6211 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6212 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6213 String newUssdCommand = "";
6214 try {
6215 newUssdCommand = carrierXmlParser.getFeature(
6216 CarrierXmlParser.FEATURE_CALL_WAITING)
6217 .makeCommand(ssAction, null);
6218 } catch (NullPointerException e) {
6219 loge("Failed to generate USSD number" + e);
6220 }
6221 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6222 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6223 final String ussdCommand = newUssdCommand;
6224 Executors.newSingleThreadExecutor().execute(() -> {
6225 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6226 });
6227 } else {
6228 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6229 FunctionalUtils.ignoreRemoteException(callback::accept));
6230
6231 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6232 }
Shuo Qian4a594052020-01-23 11:59:30 -08006233 } finally {
6234 Binder.restoreCallingIdentity(identity);
6235 }
6236 }
6237
6238 /**
yinxub1bed742017-04-17 11:45:04 -07006239 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006240 *
yinxub1bed742017-04-17 11:45:04 -07006241 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006242 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6243 * location related information which will be sent if the caller already possess
6244 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006245 * @param request contains the radio access networks with bands/channels to scan
6246 * @param messenger callback messenger for scan results or errors
6247 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006248 * @return the id of the requested scan which can be used to stop the scan.
6249 */
6250 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006251 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6252 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006253 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6255 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006256 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006257 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6258 if (!renounceFineLocationAccess) {
6259 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6260 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6261 .setCallingPackage(callingPackage)
6262 .setCallingFeatureId(callingFeatureId)
6263 .setCallingPid(Binder.getCallingPid())
6264 .setCallingUid(Binder.getCallingUid())
6265 .setMethod("requestNetworkScan")
6266 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6267 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6268 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6269 .build());
6270 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006271 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006272 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6273 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006274 if (e != null) {
6275 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6276 throw e;
6277 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006278 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006279 return TelephonyScanManager.INVALID_SCAN_ID;
6280 }
6281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 }
Hall Liu912dfd32019-04-25 14:02:26 -07006283 int callingUid = Binder.getCallingUid();
6284 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006288 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006289 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006290 } finally {
6291 Binder.restoreCallingIdentity(identity);
6292 }
yinxu504e1392017-04-12 16:03:22 -07006293 }
6294
Hall Liub2ac8ef2019-02-28 15:56:23 -08006295 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006296 NetworkScanRequest request, int subId, String callingPackage) {
6297 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006298 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6299 boolean hasNetworkScanPermission =
6300 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6301 == PERMISSION_GRANTED;
6302
6303 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6304 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6305 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006306 }
6307
6308 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6309 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006310 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6311 return new SecurityException("Specific channels must not be"
6312 + " scanned without location access.");
6313 }
6314 }
6315 }
6316
Hall Liub2ac8ef2019-02-28 15:56:23 -08006317 return null;
6318 }
6319
yinxu504e1392017-04-12 16:03:22 -07006320 /**
6321 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006322 *
6323 * @param subId id of the subscription
6324 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006325 */
6326 @Override
6327 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6329 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330
Hall Liu912dfd32019-04-25 14:02:26 -07006331 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 final long identity = Binder.clearCallingIdentity();
6333 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006334 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
yinxu504e1392017-04-12 16:03:22 -07006338 }
6339
6340 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006341 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006342 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006343 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006344 */
6345 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006346 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006347 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006348 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006349 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350
6351 final long identity = Binder.clearCallingIdentity();
6352 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006353 if (DBG) log("getAllowedNetworkTypesBitmask");
6354 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6355 int networkTypesBitmask = (result != null ? result[0] : -1);
6356 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6357 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 } finally {
6359 Binder.restoreCallingIdentity(identity);
6360 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006361 }
6362
6363 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006364 * Get the allowed network types for certain reason.
6365 *
6366 * @param subId the id of the subscription.
6367 * @param reason the reason the allowed network type change is taking place
6368 * @return the allowed network types.
6369 */
6370 @Override
6371 public long getAllowedNetworkTypesForReason(int subId,
6372 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006373 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006374 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006375 final long identity = Binder.clearCallingIdentity();
6376 try {
6377 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
6381 }
6382
6383 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006384 * Enable/Disable E-UTRA-NR Dual Connectivity
6385 * @param subId subscription id of the sim card
6386 * @param nrDualConnectivityState expected NR dual connectivity state
6387 * This can be passed following states
6388 * <ol>
6389 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6390 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6391 * <li>Disable NR dual connectivity and force secondary cell to be released
6392 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6393 * </ol>
6394 * @return operation result.
6395 */
6396 @Override
6397 public int setNrDualConnectivityState(int subId,
6398 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6400 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006401 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006402 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6403 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6404 }
6405
Sooraj Sasindran37444802020-08-11 10:40:43 -07006406 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6407 final long identity = Binder.clearCallingIdentity();
6408 try {
6409 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6410 nrDualConnectivityState, subId,
6411 workSource);
6412 if (DBG) log("enableNRDualConnectivity result: " + result);
6413 return result;
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
6417 }
6418
6419 /**
6420 * Is E-UTRA-NR Dual Connectivity enabled
6421 * @return true if dual connectivity is enabled else false
6422 */
6423 @Override
6424 public boolean isNrDualConnectivityEnabled(int subId) {
6425 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006426 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006427 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006428 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006429 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6430 return false;
6431 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006432 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6433 final long identity = Binder.clearCallingIdentity();
6434 try {
6435 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6436 null, subId, workSource);
6437 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6438 return isEnabled;
6439 } finally {
6440 Binder.restoreCallingIdentity(identity);
6441 }
6442 }
6443
6444 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006445 * Set the allowed network types of the device and
6446 * provide the reason triggering the allowed network change.
6447 *
6448 * @param subId the id of the subscription.
6449 * @param reason the reason the allowed network type change is taking place
6450 * @param allowedNetworkTypes the allowed network types.
6451 * @return true on success; false on any failure.
6452 */
6453 @Override
6454 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006455 @TelephonyManager.AllowedNetworkTypesReason int reason,
6456 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6458 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006459 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006460 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6461 return false;
6462 }
6463 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6464 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006465 return false;
6466 }
6467
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006468 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6469 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6470
6471
6472 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6473 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6474 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006475 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006476
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006477 final long identity = Binder.clearCallingIdentity();
6478 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006479 Boolean success = (Boolean) sendRequest(
6480 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6481 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6482
6483 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6484 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
6488 }
6489
6490 /**
Miaoa84611c2019-03-15 09:21:10 +08006491 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006492 *
Miaoa84611c2019-03-15 09:21:10 +08006493 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006494 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006495 * @hide
6496 */
6497 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006498 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006501 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502 try {
Miaoa84611c2019-03-15 09:21:10 +08006503 if (phone != null) {
6504 return phone.hasMatchedTetherApnSetting();
6505 } else {
6506 return false;
6507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 } finally {
6509 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006510 }
Junda Liu475951f2014-11-07 16:45:03 -08006511 }
6512
6513 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006514 * Get the user enabled state of Mobile Data.
6515 *
6516 * TODO: remove and use isUserDataEnabled.
6517 * This can't be removed now because some vendor codes
6518 * calls through ITelephony directly while they should
6519 * use TelephonyManager.
6520 *
6521 * @return true on enabled
6522 */
6523 @Override
6524 public boolean getDataEnabled(int subId) {
6525 return isUserDataEnabled(subId);
6526 }
6527
6528 /**
6529 * Get whether mobile data is enabled per user setting.
6530 *
6531 * There are other factors deciding whether mobile data is actually enabled, but they are
6532 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006533 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006534 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6535 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006536 *
6537 * @return {@code true} if data is enabled else {@code false}
6538 */
6539 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006540 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006541 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006542 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006543 try {
6544 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6545 functionName);
6546 } catch (Exception e) {
6547 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6548 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006549 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006551 mApp, subId, functionName);
6552
Robert Greenwalt646120a2014-05-23 11:54:03 -07006553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554
6555 final long identity = Binder.clearCallingIdentity();
6556 try {
6557 int phoneId = mSubscriptionController.getPhoneId(subId);
6558 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6559 Phone phone = PhoneFactory.getPhone(phoneId);
6560 if (phone != null) {
6561 boolean retVal = phone.isUserDataEnabled();
6562 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6563 return retVal;
6564 } else {
6565 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6566 return false;
6567 }
6568 } finally {
6569 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006570 }
6571 }
6572
6573 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006574 * Checks if the device is capable of mobile data by considering whether whether the
6575 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6576 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006577 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006578 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006579 */
6580 @Override
6581 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006582 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006583 try {
6584 try {
6585 mApp.enforceCallingOrSelfPermission(
6586 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006587 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006588 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006589 try {
6590 mApp.enforceCallingOrSelfPermission(
6591 android.Manifest.permission.READ_PHONE_STATE,
6592 functionName);
6593 } catch (Exception e2) {
6594 mApp.enforceCallingOrSelfPermission(
6595 permission.READ_BASIC_PHONE_STATE, functionName);
6596 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006597 }
6598 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006599 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 int phoneId = mSubscriptionController.getPhoneId(subId);
6605 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6606 Phone phone = PhoneFactory.getPhone(phoneId);
6607 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006608 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6610 return retVal;
6611 } else {
6612 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6613 return false;
6614 }
6615 } finally {
6616 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006617 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006618 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006619
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006620 /**
6621 * Check if data is enabled for a specific reason
6622 * @param subId Subscription index
6623 * @param reason the reason the data enable change is taking place
6624 * @return {@code true} if the overall data is enabled; {@code false} if not.
6625 */
6626 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006627 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006628 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006629 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006630 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006631 try {
6632 mApp.enforceCallingOrSelfPermission(
6633 android.Manifest.permission.ACCESS_NETWORK_STATE,
6634 functionName);
6635 } catch (Exception e) {
6636 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6637 functionName);
6638 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006639 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006640 try {
6641 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006642 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006643 } catch (Exception e2) {
6644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006645 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006646 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006647 }
6648
6649
6650 final long identity = Binder.clearCallingIdentity();
6651 try {
6652 int phoneId = mSubscriptionController.getPhoneId(subId);
6653 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006654 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006655 + " reason=" + reason);
6656 }
6657 Phone phone = PhoneFactory.getPhone(phoneId);
6658 if (phone != null) {
6659 boolean retVal;
6660 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6661 retVal = phone.isUserDataEnabled();
6662 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006663 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006664 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006666 return retVal;
6667 } else {
6668 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006669 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006670 + subId + " retVal=false");
6671 }
6672 return false;
6673 }
6674 } finally {
6675 Binder.restoreCallingIdentity(identity);
6676 }
6677 }
6678
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006679 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006680 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006681 if (uid == Process.PHONE_UID) {
6682 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6683 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006684 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6685 }
6686
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006687 //load access rules from carrier configs, and check those as well: b/139133814
6688 SubscriptionController subController = SubscriptionController.getInstance();
6689 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6690 || subController == null) return privilegeFromSim;
6691
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006692 PackageManager pkgMgr = phone.getContext().getPackageManager();
6693 String[] packages = pkgMgr.getPackagesForUid(uid);
6694
6695 final long identity = Binder.clearCallingIdentity();
6696 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006697 int subId = phone.getSubId();
6698 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6699 // A test override is in place for the privileges for this subId, so don't try to
6700 // read the subscription privileges.
6701 return privilegeFromSim;
6702 }
6703 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006704 SubscriptionManager subManager = (SubscriptionManager)
6705 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6706 for (String pkg : packages) {
6707 if (subManager.canManageSubscription(subInfo, pkg)) {
6708 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6709 }
6710 }
6711 return privilegeFromSim;
6712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
6715 }
6716
6717 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6718 String pkgName) {
6719 //load access rules from carrier configs, and check those as well: b/139133814
6720 SubscriptionController subController = SubscriptionController.getInstance();
6721 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6722 || subController == null) return privilegeFromSim;
6723
6724 final long identity = Binder.clearCallingIdentity();
6725 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006726 int subId = phone.getSubId();
6727 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6728 // A test override is in place for the privileges for this subId, so don't try to
6729 // read the subscription privileges.
6730 return privilegeFromSim;
6731 }
6732 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006733 SubscriptionManager subManager = (SubscriptionManager)
6734 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6735 return subManager.canManageSubscription(subInfo, pkgName)
6736 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6737 } finally {
6738 Binder.restoreCallingIdentity(identity);
6739 }
6740 }
6741
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006742 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006743 public int getCarrierPrivilegeStatus(int subId) {
6744 final Phone phone = getPhone(subId);
6745 if (phone == null) {
6746 loge("getCarrierPrivilegeStatus: Invalid subId");
6747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6748 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006749 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6750 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006751 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6753 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006754
6755 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006756 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006757 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006758 }
Junda Liu29340342014-07-10 15:23:27 -07006759
6760 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006761 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006762 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006763 final Phone phone = getPhone(subId);
6764 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006765 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6767 }
6768 UiccProfile profile =
6769 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6770 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006771 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006772 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6773 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006774 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006775 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006776 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006777 }
6778
6779 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006780 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006781 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006782 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006783 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006784 }
6785
6786 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006787 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6788 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006789 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6791 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006792 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006793 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006794 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006795 }
6796
6797 @Override
6798 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006799 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006800 if (TextUtils.isEmpty(pkgName))
6801 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006802 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6803 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006804 UiccPort port = UiccController.getInstance().getUiccPort(i);
6805 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006806 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006807 continue;
6808 }
6809
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006810 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006811 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006812 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006813 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6814 break;
6815 }
6816 }
6817
6818 return result;
Junda Liu29340342014-07-10 15:23:27 -07006819 }
Derek Tan89e89d42014-07-08 17:00:10 -07006820
6821 @Override
Junda Liue64de782015-04-16 17:19:16 -07006822 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006823 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006824 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6825 loge("phoneId " + phoneId + " is not valid.");
6826 return null;
6827 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006828 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6829 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006830 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006831 return null ;
6832 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006833 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006834 }
6835
Amith Yamasani6e118872016-02-19 12:53:51 -08006836 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006837 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006838 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006839 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006840 List<String> privilegedPackages = new ArrayList<>();
6841 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006842 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006843 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006844 if (port != null) {
6845 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006846 if (packages == null) {
6847 // Only check packages in user 0 for now
6848 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006849 PackageManager.MATCH_DISABLED_COMPONENTS
6850 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006851 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006852 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006853 }
6854 for (int p = packages.size() - 1; p >= 0; p--) {
6855 PackageInfo pkgInfo = packages.get(p);
6856 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006857 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006858 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006859 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006860 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006861 privilegedPackages.add(pkgInfo.packageName);
6862 }
6863 }
6864 }
6865 }
6866 return privilegedPackages;
6867 }
6868
chen xuf7e9fe82019-05-09 19:31:02 -07006869 @Override
6870 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006871 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6872
6873 final long identity = Binder.clearCallingIdentity();
6874
chen xuf7e9fe82019-05-09 19:31:02 -07006875 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006876 try {
6877 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6878 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6879 }
6880 } finally {
6881 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006882 }
6883 return privilegedPackages;
6884 }
6885
Wink Savilleb564aae2014-10-23 10:18:09 -07006886 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006887 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006888 UiccPort port = phone == null ? null : phone.getUiccPort();
6889 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006890 return null;
6891 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006892 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006893 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006894 return null;
6895 }
6896 return iccId;
6897 }
6898
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006899 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006900 public void setCallComposerStatus(int subId, int status) {
6901 enforceModifyPermission();
6902
6903 final long identity = Binder.clearCallingIdentity();
6904 try {
6905 Phone phone = getPhone(subId);
6906 if (phone != null) {
6907 Phone defaultPhone = phone.getImsPhone();
6908 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6909 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6910 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006911 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6912 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006913 }
6914 }
Shuo Qian284ae752020-12-22 19:10:14 -08006915 } catch (ImsException e) {
6916 throw new ServiceSpecificException(e.getCode());
6917 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006918 Binder.restoreCallingIdentity(identity);
6919 }
6920 }
6921
6922 @Override
6923 public int getCallComposerStatus(int subId) {
6924 enforceReadPrivilegedPermission("getCallComposerStatus");
6925
6926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 Phone phone = getPhone(subId);
6929 if (phone != null) {
6930 Phone defaultPhone = phone.getImsPhone();
6931 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6932 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6933 return imsPhone.getCallComposerStatus();
6934 }
6935 }
6936 } finally {
6937 Binder.restoreCallingIdentity(identity);
6938 }
6939 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6940 }
6941
6942 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006943 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6944 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006945 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006946 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948 final long identity = Binder.clearCallingIdentity();
6949 try {
6950 final String iccId = getIccId(subId);
6951 final Phone phone = getPhone(subId);
6952 if (phone == null) {
6953 return false;
6954 }
6955 final String subscriberId = phone.getSubscriberId();
6956
6957 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006958 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 + subscriberId + " to " + number);
6960 }
6961
6962 if (TextUtils.isEmpty(iccId)) {
6963 return false;
6964 }
6965
6966 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6967
6968 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6969 if (alphaTag == null) {
6970 editor.remove(alphaTagPrefKey);
6971 } else {
6972 editor.putString(alphaTagPrefKey, alphaTag);
6973 }
6974
6975 // Record both the line number and IMSI for this ICCID, since we need to
6976 // track all merged IMSIs based on line number
6977 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6978 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6979 if (number == null) {
6980 editor.remove(numberPrefKey);
6981 editor.remove(subscriberPrefKey);
6982 } else {
6983 editor.putString(numberPrefKey, number);
6984 editor.putString(subscriberPrefKey, subscriberId);
6985 }
6986
6987 editor.commit();
6988 return true;
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006991 }
Derek Tan7226c842014-07-02 17:42:23 -07006992 }
6993
6994 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006995 public String getLine1NumberForDisplay(int subId, String callingPackage,
6996 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006997 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006999 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007000 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007001 return null;
7002 }
Derek Tan97ebb422014-09-05 16:55:38 -07007003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 final long identity = Binder.clearCallingIdentity();
7005 try {
7006 String iccId = getIccId(subId);
7007 if (iccId != null) {
7008 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7009 if (DBG_MERGE) {
7010 log("getLine1NumberForDisplay returning "
7011 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7012 }
7013 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007015 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7016 return null;
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007019 }
Derek Tan7226c842014-07-02 17:42:23 -07007020 }
7021
7022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007023 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7024 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007026 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007027 return null;
7028 }
Derek Tan97ebb422014-09-05 16:55:38 -07007029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 final long identity = Binder.clearCallingIdentity();
7031 try {
7032 String iccId = getIccId(subId);
7033 if (iccId != null) {
7034 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7035 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7036 }
7037 return null;
7038 } finally {
7039 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007040 }
Derek Tan7226c842014-07-02 17:42:23 -07007041 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007042
7043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007044 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7045 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007046 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7047 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007049 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007050 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007051 return null;
7052 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007053
Jordan Liub49b04b2019-05-06 14:45:15 -07007054 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7055 // the process, where TelephonyManager was instantiated.
7056 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007057 final long identity = Binder.clearCallingIdentity();
7058 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007059 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007060 final TelephonyManager tele = TelephonyManager.from(context);
7061 final SubscriptionManager sub = SubscriptionManager.from(context);
7062
7063 // Figure out what subscribers are currently active
7064 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065
Jordan Liub49b04b2019-05-06 14:45:15 -07007066 // Only consider subs which match the current subId
7067 // This logic can be simplified. See b/131189269 for progress.
7068 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007069 activeSubscriberIds.add(tele.getSubscriberId(subId));
7070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071
7072 // First pass, find a number override for an active subscriber
7073 String mergeNumber = null;
7074 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7075 for (String key : prefs.keySet()) {
7076 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7077 final String subscriberId = (String) prefs.get(key);
7078 if (activeSubscriberIds.contains(subscriberId)) {
7079 final String iccId = key.substring(
7080 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7081 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7082 mergeNumber = (String) prefs.get(numberKey);
7083 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007084 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 + " for active subscriber " + subscriberId);
7086 }
7087 if (!TextUtils.isEmpty(mergeNumber)) {
7088 break;
7089 }
7090 }
7091 }
7092 }
7093
7094 // Shortcut when no active merged subscribers
7095 if (TextUtils.isEmpty(mergeNumber)) {
7096 return null;
7097 }
7098
7099 // Second pass, find all subscribers under that line override
7100 final ArraySet<String> result = new ArraySet<>();
7101 for (String key : prefs.keySet()) {
7102 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7103 final String number = (String) prefs.get(key);
7104 if (mergeNumber.equals(number)) {
7105 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7106 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7107 final String subscriberId = (String) prefs.get(subscriberKey);
7108 if (!TextUtils.isEmpty(subscriberId)) {
7109 result.add(subscriberId);
7110 }
7111 }
7112 }
7113 }
7114
7115 final String[] resultArray = result.toArray(new String[result.size()]);
7116 Arrays.sort(resultArray);
7117 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007118 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7120 }
7121 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007122 } finally {
7123 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007124 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007125 }
7126
7127 @Override
zoey chen38003472019-12-13 17:16:31 +08007128 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7129 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007130
7131 final long identity = Binder.clearCallingIdentity();
7132 try {
7133 final TelephonyManager telephonyManager = mApp.getSystemService(
7134 TelephonyManager.class);
7135 String subscriberId = telephonyManager.getSubscriberId(subId);
7136 if (subscriberId == null) {
7137 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007138 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007139 + subId);
7140 }
7141 return null;
7142 }
7143
7144 final SubscriptionInfo info = SubscriptionController.getInstance()
7145 .getSubscriptionInfo(subId);
7146 final ParcelUuid groupUuid = info.getGroupUuid();
7147 // If it doesn't belong to any group, return just subscriberId of itself.
7148 if (groupUuid == null) {
7149 return new String[]{subscriberId};
7150 }
7151
7152 // Get all subscriberIds from the group.
7153 final List<String> mergedSubscriberIds = new ArrayList<>();
7154 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007155 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007156 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007157 for (SubscriptionInfo subInfo : groupInfos) {
7158 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7159 if (subscriberId != null) {
7160 mergedSubscriberIds.add(subscriberId);
7161 }
7162 }
7163
7164 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167
7168 }
7169 }
7170
7171 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007172 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007173 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007174 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175
7176 final long identity = Binder.clearCallingIdentity();
7177 try {
7178 final Phone phone = getPhone(subId);
7179 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007183 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007184
7185 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007186 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007187 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7188 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007189 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7190 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191
7192 final long identity = Binder.clearCallingIdentity();
7193 try {
7194 final Phone phone = getPhone(subId);
7195 if (phone == null) {
7196 return false;
7197 }
7198 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7199 cdmaNonRoamingList);
7200 } finally {
7201 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007202 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007203 }
7204
7205 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007206 @Deprecated
7207 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7208 enforceModifyPermission();
7209
7210 int returnValue = 0;
7211 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007212 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007213 if(result.exception == null) {
7214 if (result.result != null) {
7215 byte[] responseData = (byte[])(result.result);
7216 if(responseData.length > oemResp.length) {
7217 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7218 responseData.length + "bytes. Buffer Size is " +
7219 oemResp.length + "bytes.");
7220 }
7221 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7222 returnValue = responseData.length;
7223 }
7224 } else {
7225 CommandException ex = (CommandException) result.exception;
7226 returnValue = ex.getCommandError().ordinal();
7227 if(returnValue > 0) returnValue *= -1;
7228 }
7229 } catch (RuntimeException e) {
7230 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7231 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7232 if(returnValue > 0) returnValue *= -1;
7233 }
7234
7235 return returnValue;
7236 }
7237
7238 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007239 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007240 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007241 try {
7242 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007243 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007244 mApp, phone.getSubId(), "getRadioAccessFamily");
7245 } catch (SecurityException e) {
7246 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7247 throw e;
7248 }
chen xub97461a2018-10-26 14:17:57 -07007249 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007250 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007251 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 final long identity = Binder.clearCallingIdentity();
7254 try {
chen xub97461a2018-10-26 14:17:57 -07007255 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007256 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007257 mApp, phone.getSubId(), "getRadioAccessFamily");
7258 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 } finally {
7260 Binder.restoreCallingIdentity(identity);
7261 }
chen xub97461a2018-10-26 14:17:57 -07007262 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007263 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007264
7265 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007266 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007267 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007268 try {
7269 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7270 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007271 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007272 }
7273 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007274 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007275 }
7276 RoleManager rm = mApp.getSystemService(RoleManager.class);
7277 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7278 if (!dialerRoleHolders.contains(callingPackage)) {
7279 throw new SecurityException("App must be the dialer role holder to"
7280 + " upload a call composer pic");
7281 }
7282
7283 Executors.newSingleThreadExecutor().execute(() -> {
7284 ByteArrayOutputStream output = new ByteArrayOutputStream(
7285 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7286 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7287 boolean readUntilEnd = false;
7288 int totalBytesRead = 0;
7289 byte[] buffer = new byte[16 * 1024];
7290 while (true) {
7291 int numRead;
7292 try {
7293 numRead = input.read(buffer);
7294 } catch (IOException e) {
7295 try {
7296 fd.checkError();
7297 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7298 null);
7299 } catch (IOException e1) {
7300 // This means that the other side closed explicitly with an error. If this
7301 // happens, log and ignore.
7302 loge("Remote end of call composer picture pipe closed: " + e1);
7303 }
7304 break;
7305 }
7306 if (numRead == -1) {
7307 readUntilEnd = true;
7308 break;
7309 }
7310 totalBytesRead += numRead;
7311 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7312 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7313 try {
7314 input.close();
7315 } catch (IOException e) {
7316 // ignore
7317 }
7318 break;
7319 }
7320 output.write(buffer, 0, numRead);
7321 }
7322 // Generally, the remote end will close the file descriptors. The only case where we
7323 // close is above, where the picture size is too big.
7324
7325 try {
7326 fd.checkError();
7327 } catch (IOException e) {
7328 loge("Remote end for call composer closed with an error: " + e);
7329 return;
7330 }
7331
Hall Liuaa4211e2021-01-20 15:43:39 -08007332 if (!readUntilEnd) {
7333 loge("Did not finish reading entire image; aborting");
7334 return;
7335 }
Hall Liu82694d52020-12-11 18:22:04 -08007336
Hall Liuaa4211e2021-01-20 15:43:39 -08007337 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7338 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7339 new CallComposerPictureTransfer.Factory() {},
7340 imageData,
7341 (result) -> {
7342 if (result.first != null) {
7343 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7344 Bundle outputResult = new Bundle();
7345 outputResult.putParcelable(
7346 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7347 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7348 outputResult);
7349 } else {
7350 callback.send(result.second, null);
7351 }
7352 }
7353 );
Hall Liu82694d52020-12-11 18:22:04 -08007354 });
7355 }
7356
7357 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007358 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007359 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007360 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361
7362 final long identity = Binder.clearCallingIdentity();
7363 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007364 ImsManager.getInstance(defaultPhone.getContext(),
7365 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007369 }
7370
7371 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007372 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007373 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7375 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007376 return false;
7377 }
Svet Ganovb320e182015-04-16 12:30:10 -07007378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 // Check the user preference and the system-level IMS setting. Even if the user has
7382 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7383 // In the long run, we may instead need to check if there exists a connection service
7384 // which can support video calling.
7385 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007386 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 return imsManager.isVtEnabledByPlatform()
7388 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7389 && imsManager.isVtEnabledByUser();
7390 } finally {
7391 Binder.restoreCallingIdentity(identity);
7392 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007393 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007394
Andrew Leea1239f22015-03-02 17:44:07 -08007395 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007396 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7397 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007399 mApp, subId, callingPackage, callingFeatureId,
7400 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 return false;
7402 }
7403
7404 final long identity = Binder.clearCallingIdentity();
7405 try {
7406 CarrierConfigManager configManager =
7407 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007408 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7410 } finally {
7411 Binder.restoreCallingIdentity(identity);
7412 }
Andrew Leea1239f22015-03-02 17:44:07 -08007413 }
7414
7415 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007416 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007418 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 return false;
7420 }
7421
7422 final long identity = Binder.clearCallingIdentity();
7423 try {
7424 CarrierConfigManager configManager =
7425 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007426 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
Andrew Leea1239f22015-03-02 17:44:07 -08007431 }
7432
Andrew Lee9431b832015-03-09 18:46:45 -07007433 @Override
7434 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007435 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007436 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007437 }
7438
7439 @Override
7440 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 final long identity = Binder.clearCallingIdentity();
7442 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007443 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 } finally {
7445 Binder.restoreCallingIdentity(identity);
7446 }
Andrew Lee9431b832015-03-09 18:46:45 -07007447 }
7448
Hall Liuf6668912018-10-31 17:05:23 -07007449 /**
7450 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7451 * support for the feature and device firmware support.
7452 *
7453 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7454 */
7455 @Override
7456 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007458 final Phone phone = getPhone(subscriptionId);
7459 if (phone == null) {
7460 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7461 return false;
7462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7466 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007467 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 return isCarrierSupported && isDeviceSupported;
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
Hall Liu98187582018-01-22 19:15:32 -08007472 }
7473
Hall Liuf6668912018-10-31 17:05:23 -07007474 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007475 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7476 * RTT setting, will return true if the device and carrier both support RTT.
7477 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007478 */
7479 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 final long identity = Binder.clearCallingIdentity();
7481 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007482 boolean isRttSupported = isRttSupported(subscriptionId);
7483 boolean isUserRttSettingOn = Settings.Secure.getInt(
7484 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7485 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7486 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7487 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007491 }
7492
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007493 @Deprecated
7494 @Override
7495 public String getDeviceId(String callingPackage) {
7496 return getDeviceIdWithFeature(callingPackage, null);
7497 }
7498
Sanket Padawe7310cc72015-01-14 09:53:20 -08007499 /**
7500 * Returns the unique device ID of phone, for example, the IMEI for
7501 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7502 *
7503 * <p>Requires Permission:
7504 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7505 */
7506 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007507 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007508 try {
7509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7510 } catch (SecurityException se) {
7511 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7512 throw new SecurityException("Package " + callingPackage + " does not belong to "
7513 + Binder.getCallingUid());
7514 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007515 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007516 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007517 return null;
7518 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007519 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007520 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007521 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007522 return null;
7523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524
7525 final long identity = Binder.clearCallingIdentity();
7526 try {
7527 return phone.getDeviceId();
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007531 }
7532
Ping Sunc67b7c22016-03-02 19:16:45 +08007533 /**
7534 * {@hide}
7535 * Returns the IMS Registration Status on a particular subid
7536 *
7537 * @param subId
7538 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007539 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007540 Phone phone = getPhone(subId);
7541 if (phone != null) {
7542 return phone.isImsRegistered();
7543 } else {
7544 return false;
7545 }
7546 }
7547
Santos Cordon7a1885b2015-02-03 11:15:19 -08007548 @Override
7549 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 final long identity = Binder.clearCallingIdentity();
7551 try {
7552 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007556 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007557
Tyler Gunnf70ed162019-04-03 15:28:53 -07007558 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007559 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007560 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007562 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007563 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7564 }
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
7567 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
7571 }
7572
7573 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007574 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007575 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007576 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007577 mApp,
7578 subscriptionId,
7579 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007580 final long identity = Binder.clearCallingIdentity();
7581 try {
7582 Phone phone = getPhone(subscriptionId);
7583 if (phone == null) {
7584 return null;
7585 }
7586 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
7590 }
7591
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007592 /**
7593 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007594 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007595 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 Phone phone = getPhone(subId);
7599 if (phone != null) {
7600 return phone.isWifiCallingEnabled();
7601 } else {
7602 return false;
7603 }
7604 } finally {
7605 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007606 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007607 }
7608
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007609 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007610 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007611 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007612 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 Phone phone = getPhone(subId);
7616 if (phone != null) {
7617 return phone.isVideoEnabled();
7618 } else {
7619 return false;
7620 }
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007623 }
7624 }
7625
7626 /**
7627 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7628 * defined in {@link ImsRegistrationImplBase}.
7629 */
7630 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 final long identity = Binder.clearCallingIdentity();
7632 try {
7633 Phone phone = getPhone(subId);
7634 if (phone != null) {
7635 return phone.getImsRegistrationTech();
7636 } else {
7637 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7638 }
7639 } finally {
7640 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007641 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007642 }
7643
Stuart Scott8eef64f2015-04-08 15:13:54 -07007644 @Override
7645 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007646 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007647 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7648 return;
7649 }
Kai Shif70f46f2021-03-03 13:59:46 -08007650 Phone defaultPhone = getDefaultPhone();
7651 if (defaultPhone != null) {
7652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7653 mApp, getDefaultPhone().getSubId(), "factoryReset");
7654 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007655 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007656
Svet Ganovcc087f82015-05-12 20:35:54 -07007657 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007658 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7659 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007660 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007661 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007662 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007663 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007664 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007665 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007666 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007667 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007668 // There has been issues when Sms raw table somehow stores orphan
7669 // fragments. They lead to garbled message when new fragments come
7670 // in and combined with those stale ones. In case this happens again,
7671 // user can reset all network settings which will clean up this table.
7672 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007673 // Clean up IMS settings as well here.
7674 int slotId = getSlotIndex(subId);
7675 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7676 ImsManager.getInstance(mApp, slotId).factoryReset();
7677 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007678
Kai Shif70f46f2021-03-03 13:59:46 -08007679 if (defaultPhone == null) {
7680 return;
7681 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007682 // Erase modem config if erase modem on network setting is enabled.
7683 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7684 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7685 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007686 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007687 }
Kai Shif70f46f2021-03-03 13:59:46 -08007688
7689 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007690 } finally {
7691 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007692 }
7693 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007694
SongFerngWangfd89b102021-05-27 22:44:54 +08007695 @VisibleForTesting
7696 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7697 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7698 return;
7699 }
7700 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7701 RILConstants.PREFERRED_NETWORK_MODE);
7702 SubscriptionManager.setSubscriptionProperty(subId,
7703 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7704 "user=" + defaultNetworkType);
7705 phone.loadAllowedNetworksFromSubscriptionDatabase();
7706 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7707 defaultNetworkType, null);
7708 }
7709
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007710 private void cleanUpSmsRawTable(Context context) {
7711 ContentResolver resolver = context.getContentResolver();
7712 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7713 resolver.delete(uri, null, null);
7714 }
7715
Narayan Kamath1c496c22015-04-16 14:40:19 +01007716 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007717 public String getSimLocaleForSubscriber(int subId) {
7718 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7719 final Phone phone = getPhone(subId);
7720 if (phone == null) {
7721 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007722 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 final long identity = Binder.clearCallingIdentity();
7725 try {
chen xu5d3637b2019-01-21 23:31:38 -08007726 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007727 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007728 if (info == null) {
7729 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7730 return null;
7731 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 // Try and fetch the locale from the carrier properties or from the SIM language
7733 // preferences (EF-PL and EF-LI)...
7734 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007736 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7737 if (localeFromDefaultSim != null) {
7738 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7739 if (DBG) log("Using locale from subId: " + subId + " locale: "
7740 + localeFromDefaultSim);
7741 return localeFromDefaultSim.toLanguageTag();
7742 } else {
7743 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744 }
7745 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 // The SIM language preferences only store a language (e.g. fr = French), not an
7748 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7749 // the SIM and carrier preferences does not include a country we add the country
7750 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007751 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007753 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 return mccLocale.toLanguageTag();
7755 }
7756
7757 if (DBG) log("No locale found - returning null");
7758 return null;
7759 } finally {
7760 Binder.restoreCallingIdentity(identity);
7761 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007762 }
7763
7764 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007765 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007766 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007767 }
7768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 /**
7770 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7771 */
7772 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007773 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007774 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007775 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007776
Chenjie Yu1ba97252018-01-11 18:16:20 -08007777 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007778 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007779
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007780 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007781 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7782 * representing the state of the modem.
7783 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007784 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7785 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007786 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007787 */
7788 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007789 public void requestModemActivityInfo(ResultReceiver result) {
7790 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007791 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792
7793 final long identity = Binder.clearCallingIdentity();
7794 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007795 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 } finally {
7797 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007798 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007799 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007800
Siddharth Rayb8114062018-06-17 15:02:38 -07007801 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7802 // less than total activity duration.
7803 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7804 if (info == null) {
7805 return false;
7806 }
7807 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007808 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7809 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7810
Siddharth Rayb8114062018-06-17 15:02:38 -07007811 return (info.isValid()
7812 && (info.getSleepTimeMillis() <= activityDurationMs)
7813 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007814 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007815 && (totalTxTimeMs <= activityDurationMs));
7816 }
7817
Jack Yu85bd38a2015-11-09 11:34:32 -08007818 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007819 * Returns the service state information on specified subscription.
7820 */
7821 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007822 public ServiceState getServiceStateForSubscriber(int subId,
7823 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7824 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007826 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007827 return null;
7828 }
7829
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007830 boolean hasFinePermission = false;
7831 boolean hasCoarsePermission = false;
7832 if (!renounceFineLocationAccess) {
7833 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7834 LocationAccessPolicy.checkLocationPermission(mApp,
7835 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7836 .setCallingPackage(callingPackage)
7837 .setCallingFeatureId(callingFeatureId)
7838 .setCallingPid(Binder.getCallingPid())
7839 .setCallingUid(Binder.getCallingUid())
7840 .setMethod("getServiceStateForSubscriber")
7841 .setLogAsInfo(true)
7842 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7843 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7844 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7845 .build());
7846 hasFinePermission =
7847 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7848 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007849
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007850 if (!renounceCoarseLocationAccess) {
7851 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7852 LocationAccessPolicy.checkLocationPermission(mApp,
7853 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7854 .setCallingPackage(callingPackage)
7855 .setCallingFeatureId(callingFeatureId)
7856 .setCallingPid(Binder.getCallingPid())
7857 .setCallingUid(Binder.getCallingUid())
7858 .setMethod("getServiceStateForSubscriber")
7859 .setLogAsInfo(true)
7860 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7861 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7862 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7863 .build());
7864 hasCoarsePermission =
7865 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7866 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007867
Jack Yu479f40e2020-10-27 21:29:25 -07007868 final Phone phone = getPhone(subId);
7869 if (phone == null) {
7870 return null;
7871 }
7872
Jordan Liu0f2bc442020-11-18 16:47:37 -08007873 final long identity = Binder.clearCallingIdentity();
7874
Jack Yu479f40e2020-10-27 21:29:25 -07007875 boolean isCallingPackageDataService = phone.getDataServicePackages()
7876 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007877 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007878 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7879 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7880 Rlog.d(LOG_TAG,
7881 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7882 return null;
7883 }
7884
Hall Liuf19c44f2018-11-27 14:38:17 -08007885 ServiceState ss = phone.getServiceState();
7886
7887 // Scrub out the location info in ServiceState depending on what level of access
7888 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007889 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007890 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7891 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007892 } finally {
7893 Binder.restoreCallingIdentity(identity);
7894 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007895 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007896
7897 /**
7898 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7899 *
7900 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7901 * voicemail ringtone.
7902 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7903 * PhoneAccount.
7904 */
7905 @Override
7906 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 final long identity = Binder.clearCallingIdentity();
7908 try {
7909 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7910 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007911 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007918 }
7919
7920 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007921 * Sets the per-account voicemail ringtone.
7922 *
7923 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7924 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7925 *
7926 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7927 * voicemail ringtone.
7928 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7929 * PhoneAccount.
7930 */
7931 @Override
7932 public void setVoicemailRingtoneUri(String callingPackage,
7933 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007934 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007935 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007936 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7937 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7939 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7940 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942
7943 final long identity = Binder.clearCallingIdentity();
7944 try {
7945 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7946 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007947 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 }
7949 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7950 } finally {
7951 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007952 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007953 }
7954
7955 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007956 * Returns whether vibration is set for voicemail notification in Phone settings.
7957 *
7958 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7959 * voicemail vibration setting.
7960 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7961 */
7962 @Override
7963 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964 final long identity = Binder.clearCallingIdentity();
7965 try {
7966 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7967 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007968 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7972 } finally {
7973 Binder.restoreCallingIdentity(identity);
7974 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007975 }
7976
Youhan Wange64578a2016-05-02 15:32:42 -07007977 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007978 * Sets the per-account voicemail vibration.
7979 *
7980 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7981 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7982 *
7983 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7984 * voicemail vibration setting.
7985 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7986 * specific PhoneAccount.
7987 */
7988 @Override
7989 public void setVoicemailVibrationEnabled(String callingPackage,
7990 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007991 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007992 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007993 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7994 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7996 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7997 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007998 }
7999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000 final long identity = Binder.clearCallingIdentity();
8001 try {
8002 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8003 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008004 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 }
8006 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8007 } finally {
8008 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008009 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008010 }
8011
8012 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008013 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8014 *
8015 * @throws SecurityException if the caller does not have the required permission
8016 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008017 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008018 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008019 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008020 }
8021
8022 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008023 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8024 * permission.
8025 *
8026 * @throws SecurityException if the caller does not have the required permission
8027 */
8028 private void enforceSendSmsPermission() {
8029 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8030 }
8031
8032 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008033 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008034 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008035 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008036 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008037 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 final long identity = Binder.clearCallingIdentity();
8039 try {
8040 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008041 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008042 if (componentName == null) {
8043 throw new SecurityException(
8044 "Caller not current active visual voicemail package[null]");
8045 }
8046 String vvmPackage = componentName.getPackageName();
8047 if (!callingPackage.equals(vvmPackage)) {
8048 throw new SecurityException("Caller not current active visual voicemail package["
8049 + vvmPackage + "]");
8050 }
8051 } finally {
8052 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008053 }
8054 }
8055
8056 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008057 * Return the application ID for the app type.
8058 *
8059 * @param subId the subscription ID that this request applies to.
8060 * @param appType the uicc app type.
8061 * @return Application ID for specificied app type, or null if no uicc.
8062 */
8063 @Override
8064 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008065 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008066 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067
8068 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008069 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 if (phone == null) {
8071 return null;
8072 }
8073 String aid = null;
8074 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008075 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 .getApplicationByType(appType).getAid();
8077 } catch (Exception e) {
8078 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8079 }
8080 return aid;
8081 } finally {
8082 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008083 }
Youhan Wange64578a2016-05-02 15:32:42 -07008084 }
8085
Youhan Wang4001d252016-05-11 10:29:41 -07008086 /**
8087 * Return the Electronic Serial Number.
8088 *
8089 * @param subId the subscription ID that this request applies to.
8090 * @return ESN or null if error.
8091 */
8092 @Override
8093 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008094 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008095 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008096
8097 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008098 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008099 if (phone == null) {
8100 return null;
8101 }
8102 String esn = null;
8103 try {
8104 esn = phone.getEsn();
8105 } catch (Exception e) {
8106 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8107 }
8108 return esn;
8109 } finally {
8110 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008111 }
Youhan Wang4001d252016-05-11 10:29:41 -07008112 }
8113
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008114 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008115 * Return the Preferred Roaming List Version.
8116 *
8117 * @param subId the subscription ID that this request applies to.
8118 * @return PRLVersion or null if error.
8119 */
8120 @Override
8121 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008122 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008123 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124
8125 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008126 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 if (phone == null) {
8128 return null;
8129 }
8130 String cdmaPrlVersion = null;
8131 try {
8132 cdmaPrlVersion = phone.getCdmaPrlVersion();
8133 } catch (Exception e) {
8134 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8135 }
8136 return cdmaPrlVersion;
8137 } finally {
8138 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008139 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008140 }
8141
8142 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008143 * Get snapshot of Telephony histograms
8144 * @return List of Telephony histograms
8145 * @hide
8146 */
8147 @Override
8148 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8150 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151
8152 final long identity = Binder.clearCallingIdentity();
8153 try {
8154 return RIL.getTelephonyRILTimingHistograms();
8155 } finally {
8156 Binder.restoreCallingIdentity(identity);
8157 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008158 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008159
8160 /**
8161 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008162 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8163 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008164 * Require system privileges. In the future we may add this to carrier APIs.
8165 *
Michele Berionne482f8202018-11-27 18:57:59 -08008166 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008167 */
8168 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008169 @TelephonyManager.SetCarrierRestrictionResult
8170 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008171 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008172 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008173
Michele Berionne482f8202018-11-27 18:57:59 -08008174 if (carrierRestrictionRules == null) {
8175 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008176 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178 final long identity = Binder.clearCallingIdentity();
8179 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008180 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008181 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182 } finally {
8183 Binder.restoreCallingIdentity(identity);
8184 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008185 }
8186
8187 /**
8188 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008189 * Get the allowed carrier list and the excluded carrier list, including the priority between
8190 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008191 * Require system privileges. In the future we may add this to carrier APIs.
8192 *
Michele Berionne482f8202018-11-27 18:57:59 -08008193 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008194 */
8195 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008196 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008197 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008198 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199
8200 final long identity = Binder.clearCallingIdentity();
8201 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008202 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8203 if (response instanceof CarrierRestrictionRules) {
8204 return (CarrierRestrictionRules) response;
8205 }
8206 // Response is an Exception of some kind,
8207 // which is signalled to the user as a NULL retval
8208 return null;
8209 } catch (Exception e) {
8210 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8211 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212 } finally {
8213 Binder.restoreCallingIdentity(identity);
8214 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008215 }
8216
fionaxu59545b42016-05-25 15:53:37 -07008217 /**
fionaxu59545b42016-05-25 15:53:37 -07008218 * Action set from carrier signalling broadcast receivers to enable/disable radio
8219 * @param subId the subscription ID that this action applies to.
8220 * @param enabled control enable or disable radio.
8221 * {@hide}
8222 */
8223 @Override
8224 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8225 enforceModifyPermission();
8226 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008227
8228 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008229 if (phone == null) {
8230 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8231 return;
8232 }
8233 try {
8234 phone.carrierActionSetRadioEnabled(enabled);
8235 } catch (Exception e) {
8236 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237 } finally {
8238 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008239 }
8240 }
8241
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008242 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008243 * Enable or disable Voice over NR (VoNR)
8244 * @param subId the subscription ID that this action applies to.
8245 * @param enabled enable or disable VoNR.
8246 * @return operation result.
8247 */
8248 @Override
8249 public int setVoNrEnabled(int subId, boolean enabled) {
8250 enforceModifyPermission();
8251 final Phone phone = getPhone(subId);
8252
8253 final long identity = Binder.clearCallingIdentity();
8254 if (phone == null) {
8255 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8256 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8257 }
8258
8259 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8260 try {
8261 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8262 workSource);
8263 if (DBG) log("setVoNrEnabled result: " + result);
8264 return result;
8265 } finally {
8266 Binder.restoreCallingIdentity(identity);
8267 }
8268 }
8269
8270 /**
8271 * Is voice over NR enabled
8272 * @return true if VoNR is enabled else false
8273 */
8274 @Override
8275 public boolean isVoNrEnabled(int subId) {
8276 enforceReadPrivilegedPermission("isVoNrEnabled");
8277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8278 final long identity = Binder.clearCallingIdentity();
8279 try {
8280 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8281 null, subId, workSource);
8282 if (DBG) log("isVoNrEnabled: " + isEnabled);
8283 return isEnabled;
8284 } finally {
8285 Binder.restoreCallingIdentity(identity);
8286 }
8287 }
8288
8289 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008290 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8291 * network status based on which carrier apps could apply actions accordingly,
8292 * enable/disable default url handler for example.
8293 *
8294 * @param subId the subscription ID that this action applies to.
8295 * @param report control start/stop reporting the default network status.
8296 * {@hide}
8297 */
8298 @Override
8299 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8300 enforceModifyPermission();
8301 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302
8303 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008304 if (phone == null) {
8305 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8306 return;
8307 }
8308 try {
8309 phone.carrierActionReportDefaultNetworkStatus(report);
8310 } catch (Exception e) {
8311 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 } finally {
8313 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008314 }
8315 }
8316
8317 /**
fionaxud9622282017-07-17 17:51:30 -07008318 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8319 * @param subId the subscription ID that this action applies to.
8320 * {@hide}
8321 */
8322 @Override
8323 public void carrierActionResetAll(int subId) {
8324 enforceModifyPermission();
8325 final Phone phone = getPhone(subId);
8326 if (phone == null) {
8327 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8328 return;
8329 }
8330 try {
8331 phone.carrierActionResetAll();
8332 } catch (Exception e) {
8333 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8334 }
8335 }
8336
8337 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008338 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8339 * bug report is being generated.
8340 */
8341 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008342 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008343 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8344 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008345 writer.println("Permission Denial: can't dump Phone from pid="
8346 + Binder.getCallingPid()
8347 + ", uid=" + Binder.getCallingUid()
8348 + "without permission "
8349 + android.Manifest.permission.DUMP);
8350 return;
8351 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008352 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008353 }
Jack Yueb89b242016-06-22 13:27:47 -07008354
Brad Ebingerdac2f002018-04-03 15:17:52 -07008355 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008356 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8357 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8358 @NonNull String[] args) {
8359 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8360 this, in.getFileDescriptor(), out.getFileDescriptor(),
8361 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008362 }
8363
Jack Yueb89b242016-06-22 13:27:47 -07008364 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008365 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008366 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008367 * @param reason the reason the data enable change is taking place
8368 * @param enabled True if enabling the data, otherwise disabling.
8369 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008370 */
8371 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008372 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008373 boolean enabled) {
8374 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8375 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8376 try {
8377 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008378 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008379 } catch (SecurityException se) {
8380 enforceModifyPermission();
8381 }
8382 } else {
8383 enforceModifyPermission();
8384 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385
8386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 Phone phone = getPhone(subId);
8389 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008390 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8391 phone.carrierActionSetMeteredApnsEnabled(enabled);
8392 } else {
8393 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 }
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008398 }
8399 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008400
8401 /**
8402 * Get Client request stats
8403 * @return List of Client Request Stats
8404 * @hide
8405 */
8406 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008407 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8408 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008409 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008410 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008411 return null;
8412 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008413 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008415 final long identity = Binder.clearCallingIdentity();
8416 try {
8417 if (phone != null) {
8418 return phone.getClientRequestStats();
8419 }
8420
8421 return null;
8422 } finally {
8423 Binder.restoreCallingIdentity(identity);
8424 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008425 }
8426
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008427 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008428 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008429 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008430 }
Jack Yueb4124c2017-02-16 15:32:43 -08008431
8432 /**
Grace Chen70990072017-03-24 17:21:30 -07008433 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008434 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008435 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008436 * @param state State of SIM (power down, power up, pass through)
8437 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8438 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8439 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008440 *
8441 **/
8442 @Override
Grace Chen70990072017-03-24 17:21:30 -07008443 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008444 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008445 Phone phone = PhoneFactory.getPhone(slotIndex);
8446
vagdeviaf9a5b92018-08-15 16:01:53 -07008447 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008449 final long identity = Binder.clearCallingIdentity();
8450 try {
8451 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008452 phone.setSimPowerState(state, null, workSource);
8453 }
8454 } finally {
8455 Binder.restoreCallingIdentity(identity);
8456 }
8457 }
8458
8459 /**
8460 * Set SIM card power state.
8461 *
8462 * @param slotIndex SIM slot id.
8463 * @param state State of SIM (power down, power up, pass through)
8464 * @param callback callback to trigger after success or failure
8465 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8466 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8467 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8468 *
8469 **/
8470 @Override
8471 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8472 IIntegerConsumer callback) {
8473 enforceModifyPermission();
8474 Phone phone = PhoneFactory.getPhone(slotIndex);
8475
8476 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8477
8478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 if (phone != null) {
8481 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8482 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008483 }
8484 } finally {
8485 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008486 }
8487 }
Shuo Qiandd210312017-04-12 22:11:33 +00008488
Tyler Gunn65d45c22017-06-05 11:22:26 -07008489 private boolean isUssdApiAllowed(int subId) {
8490 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008491 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008492 if (configManager == null) {
8493 return false;
8494 }
8495 PersistableBundle pb = configManager.getConfigForSubId(subId);
8496 if (pb == null) {
8497 return false;
8498 }
8499 return pb.getBoolean(
8500 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8501 }
8502
Shuo Qiandd210312017-04-12 22:11:33 +00008503 /**
8504 * Check if phone is in emergency callback mode
8505 * @return true if phone is in emergency callback mode
8506 * @param subId sub id
8507 */
goneil9c5f4872017-12-05 14:07:56 -08008508 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008509 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008510 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008511 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008512
8513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 if (phone != null) {
8516 return phone.isInEcm();
8517 } else {
8518 return false;
8519 }
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008522 }
8523 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008524
8525 /**
8526 * Get the current signal strength information for the given subscription.
8527 * Because this information is not updated when the device is in a low power state
8528 * it should not be relied-upon to be current.
8529 * @param subId Subscription index
8530 * @return the most recent cached signal strength info from the modem
8531 */
8532 @Override
8533 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008534 final long identity = Binder.clearCallingIdentity();
8535 try {
8536 Phone p = getPhone(subId);
8537 if (p == null) {
8538 return null;
8539 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541 return p.getSignalStrength();
8542 } finally {
8543 Binder.restoreCallingIdentity(identity);
8544 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008545 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008546
Pengquan Meng77b7f132018-08-22 14:49:57 -07008547 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008548 * Get the current modem radio state for the given slot.
8549 * @param slotIndex slot index.
8550 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008551 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008552 * @return the current radio power state from the modem
8553 */
8554 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008555 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008556 Phone phone = PhoneFactory.getPhone(slotIndex);
8557 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8559 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008560 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8561 }
8562
8563 final long identity = Binder.clearCallingIdentity();
8564 try {
8565 return phone.getRadioPowerState();
8566 } finally {
8567 Binder.restoreCallingIdentity(identity);
8568 }
8569 }
8570 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8571 }
8572
8573 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008574 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8575 *
8576 * <p>Requires one of the following permissions:
8577 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008578 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008579 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8580 * privileges.
8581 *
8582 * @param subId subscription id
8583 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8584 * {@code false}.
8585 */
8586 @Override
8587 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008588 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008589 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008590 try {
8591 mApp.enforceCallingOrSelfPermission(
8592 android.Manifest.permission.ACCESS_NETWORK_STATE,
8593 functionName);
8594 } catch (Exception e) {
8595 mApp.enforceCallingOrSelfPermission(
8596 permission.READ_BASIC_PHONE_STATE, functionName);
8597 }
Shuo Qian093013d2020-08-13 15:42:55 -07008598 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008599 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008600 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008601 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008602
Pengquan Menga1bb6272018-09-06 09:59:22 -07008603 boolean isEnabled = false;
8604 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008605 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008606 Phone phone = getPhone(subId);
8607 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008608 } finally {
8609 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008610 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008611 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008612 }
8613
8614
8615 /**
8616 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8617 *
8618 * <p> Requires permission:
8619 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8620 * privileges.
8621 *
8622 * @param subId subscription id
8623 * @param isEnabled {@code true} means enable, {@code false} means disable.
8624 */
8625 @Override
8626 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8628 mApp, subId, "setDataRoamingEnabled");
8629
Pengquan Menga1bb6272018-09-06 09:59:22 -07008630 final long identity = Binder.clearCallingIdentity();
8631 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008632 Phone phone = getPhone(subId);
8633 if (phone != null) {
8634 phone.setDataRoamingEnabled(isEnabled);
8635 }
8636 } finally {
8637 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008638 }
8639 }
8640
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008641 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008642 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008643 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008644 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008645 mApp, subId, "isManualNetworkSelectionAllowed");
8646
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008647 boolean isAllowed = true;
8648 final long identity = Binder.clearCallingIdentity();
8649 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008650 Phone phone = getPhone(subId);
8651 if (phone != null) {
8652 isAllowed = phone.isCspPlmnEnabled();
8653 }
8654 } finally {
8655 Binder.restoreCallingIdentity(identity);
8656 }
8657 return isAllowed;
8658 }
8659
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008660 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8661 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8662 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8663 // Update each UiccPort object based on privilege access
8664 UiccPort[] uiccPorts = card.getUiccPortList();
8665 for (UiccPort port : uiccPorts) {
8666 UiccProfile profile = port.getUiccProfile();
8667 if (profile == null ||
8668 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8669 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8670 return false;
8671 }
8672 }
8673 return true;
8674 }
8675
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008676 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008677 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008678 // Verify that tha callingPackage belongs to the calling UID
8679 mApp.getSystemService(AppOpsManager.class)
8680 .checkPackage(Binder.getCallingUid(), callingPackage);
8681
Jordan Liu1e142fc2019-04-22 15:10:43 -07008682 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008683 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008684 try {
8685 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008686 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008687 } catch (SecurityException e) {
8688 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8689 // has carrier privileges on an active UICC
8690 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8691 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008692 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008693 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008694 }
sandeepjs0a502c42021-09-27 15:34:44 +00008695 // checking compatibility, if calling app's target SDK is T and beyond.
8696 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8697 Binder.getCallingUid())) {
8698 isIccIdAccessRestricted = true;
8699 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008700 final long identity = Binder.clearCallingIdentity();
8701 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008702 UiccController uiccController = UiccController.getInstance();
8703 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008704 if (hasReadPermission) {
8705 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008706 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008707
8708 // Remove private info if the caller doesn't have access
8709 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8710 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008711 //setting the value after compatibility check
8712 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008713 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8714 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008715 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008716 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8717 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8718 if (card == null || card.getUiccPortList().length == 0) {
8719 // assume no access if the card or ports are unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008720 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008721 continue;
8722 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008723
8724 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008725 filteredInfos.add(cardInfo);
8726 } else {
sandeepjs0a502c42021-09-27 15:34:44 +00008727 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008728 }
8729 }
8730 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008731 } finally {
8732 Binder.restoreCallingIdentity(identity);
8733 }
8734 }
8735
sandeepjs0a502c42021-09-27 15:34:44 +00008736 /**
8737 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8738 * generally private and require carrier privileges to view.
8739 *
8740 * @hide
8741 */
8742 @NonNull
8743 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8744 List<UiccPortInfo> portinfo = new ArrayList<>();
8745 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8746 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8747 }
8748 return new UiccCardInfo(
8749 cardInfo.isEuicc(),
8750 cardInfo.getCardId(),
8751 null,
8752 cardInfo.getPhysicalSlotIndex(),
8753 cardInfo.isRemovable(),
8754 cardInfo.isMultipleEnabledProfilesSupported(),
8755 portinfo
8756 );
8757 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008758
sandeepjs0a502c42021-09-27 15:34:44 +00008759 /**
8760 * @hide
8761 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8762 * These values are generally private and require carrier privileges to view.
8763 */
8764 @NonNull
8765 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8766 return new UiccPortInfo(
8767 UiccPortInfo.ICCID_REDACTED,
8768 portInfo.getPortIndex(),
8769 portInfo.getLogicalSlotIndex(),
8770 portInfo.isActive()
8771 );
8772 }
8773 @Override
8774 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
8775 // Verify that tha callingPackage belongs to the calling UID
8776 mApp.getSystemService(AppOpsManager.class)
8777 .checkPackage(Binder.getCallingUid(), callingPackage);
8778
8779 boolean hasReadPermission = false;
8780 boolean isLogicalSlotAccessRestricted = false;
8781 String iccId;
8782
8783 try {
8784 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8785 hasReadPermission = true;
8786 } catch (SecurityException e) {
8787 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8788 // has carrier privileges on an active UICC
8789 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8790 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8791 hasReadPermission = true;
8792 }
8793 }
8794
8795 // checking compatibility, if calling app's target SDK is T and beyond.
8796 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8797 Binder.getCallingUid())) {
8798 isLogicalSlotAccessRestricted = true;
8799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008800 final long identity = Binder.clearCallingIdentity();
8801 try {
8802 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8803 if (slots == null) {
8804 Rlog.i(LOG_TAG, "slots is null.");
8805 return null;
8806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008807 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8808 for (int i = 0; i < slots.length; i++) {
8809 UiccSlot slot = slots[i];
8810 if (slot == null) {
8811 continue;
8812 }
8813
Jordan Liu7be7e652019-05-06 18:55:02 +00008814 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008815 UiccCard card = slot.getUiccCard();
sandeepjs0a502c42021-09-27 15:34:44 +00008816 //if has read permission
8817 if (hasReadPermission) {
8818 iccId = slot.getIccId();
8819 } else {
8820 // if no read permission checking carrier
8821 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
8822 iccId = slot.getIccId();
8823 } else {
8824 //if no carrier permission redact ICCID
8825 iccId = IccUtils.TEST_ICCID;
8826 }
8827 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008828 if (card != null) {
8829 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008830 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008831 cardId = slot.getEid();
8832 if (TextUtils.isEmpty(cardId)) {
sandeepjs0a502c42021-09-27 15:34:44 +00008833 cardId = iccId;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008834 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008835 }
8836
Jordan Liu857451f2019-05-09 16:35:35 -07008837 if (cardId != null) {
8838 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8839 // if cardId is an EID, it's all digits so this is fine
8840 cardId = IccUtils.stripTrailingFs(cardId);
8841 }
8842
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008843 int cardState = 0;
8844 switch (slot.getCardState()) {
8845 case CARDSTATE_ABSENT:
8846 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8847 break;
8848 case CARDSTATE_PRESENT:
8849 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8850 break;
8851 case CARDSTATE_ERROR:
8852 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8853 break;
8854 case CARDSTATE_RESTRICTED:
8855 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8856 break;
8857 default:
8858 break;
8859
8860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008861 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008862 slot.isEuicc(),
8863 cardId,
8864 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008865 slot.isExtendedApduSupported(),
sandeepjs0a502c42021-09-27 15:34:44 +00008866 slot.isRemovable(), Collections.singletonList(
8867 new UiccPortInfo(
8868 iccId,
8869 0 /* TODO: to use portList from UiccSlots */,
8870 slot.getPhoneId(),
8871 slot.isActive())));
8872 //setting the value after compatibility check
8873 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008874 }
8875 return infos;
8876 } finally {
8877 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008878 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008879 }
8880
8881 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008882 @Deprecated
8883 //TODO : once integrating with HAL Changes we can clean up this Internal API.
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008884 public boolean switchSlots(int[] physicalSlots) {
8885 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008886
8887 final long identity = Binder.clearCallingIdentity();
8888 try {
8889 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8890 } finally {
8891 Binder.restoreCallingIdentity(identity);
8892 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008893 }
Jack Yu4c988042018-02-27 15:30:01 -08008894
8895 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008896 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8897 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8898 enforceModifyPermission();
8899
8900 final long identity = Binder.clearCallingIdentity();
8901 try {
8902 //TODO: once integrating the HAL changes we can proceed with to work on the parsing side
8903 int[] physicalSlots = new int[slotMapping.size()];
8904 for (int i = 0; i < physicalSlots.length; i++) {
8905 physicalSlots[i] = slotMapping.get(i).getPhysicalSlotIndex();
8906 }
8907 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8908 } finally {
8909 Binder.restoreCallingIdentity(identity);
8910 }
8911 }
8912
8913 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008914 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008915 final long identity = Binder.clearCallingIdentity();
8916 try {
8917 return UiccController.getInstance().getCardIdForDefaultEuicc();
8918 } finally {
8919 Binder.restoreCallingIdentity(identity);
8920 }
8921 }
8922
Pengquan Meng85728fb2018-03-12 16:31:21 -07008923 /**
goneil47ffb6e2018-04-06 15:40:58 -07008924 * A test API to reload the UICC profile.
8925 *
8926 * <p>Requires that the calling app has permission
8927 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8928 * @hide
8929 */
8930 @Override
8931 public void refreshUiccProfile(int subId) {
8932 enforceModifyPermission();
8933
8934 final long identity = Binder.clearCallingIdentity();
8935 try {
8936 Phone phone = getPhone(subId);
8937 if (phone == null) {
8938 return;
8939 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008940 UiccPort uiccPort = phone.getUiccPort();
8941 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008942 return;
8943 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008944 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008945 if (uiccProfile == null) {
8946 return;
8947 }
8948 uiccProfile.refresh();
8949 } finally {
8950 Binder.restoreCallingIdentity(identity);
8951 }
8952 }
8953
8954 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008955 * Returns false if the mobile data is disabled by default, otherwise return true.
8956 */
8957 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008958 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008959 }
8960
8961 /**
8962 * Returns true if the data roaming is enabled by default, i.e the system property
8963 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8964 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8965 */
8966 private boolean getDefaultDataRoamingEnabled(int subId) {
8967 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008968 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008969 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008970 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8971 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8972 return isDataRoamingEnabled;
8973 }
8974
8975 /**
8976 * Returns the default network type for the given {@code subId}, if the default network type is
8977 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8978 */
8979 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008980 List<Integer> list = TelephonyProperties.default_network();
8981 int phoneId = mSubscriptionController.getPhoneId(subId);
8982 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8983 return list.get(phoneId);
8984 }
8985 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008986 }
fionaxua13278b2018-03-21 00:08:13 -07008987
8988 @Override
8989 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008990 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008991 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008992
8993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 final Phone phone = getPhone(subId);
8996 if (phone == null) {
8997 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8998 return;
8999 }
chen xueaba88a2019-03-15 13:15:10 -07009000 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9001 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009002 if (carrierPrivilegeRules == null) {
9003 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9004 } else {
9005 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009007 } finally {
9008 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009009 }
fionaxua13278b2018-03-21 00:08:13 -07009010 }
9011
9012 @Override
9013 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009014 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009015
9016 final long identity = Binder.clearCallingIdentity();
9017 try {
9018 final Phone phone = getPhone(subId);
9019 if (phone == null) {
9020 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9021 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9022 }
9023 return phone.getCarrierIdListVersion();
9024 } finally {
9025 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009026 }
fionaxua13278b2018-03-21 00:08:13 -07009027 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009028
9029 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009030 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9031 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009033 mApp, subId, callingPackage, callingFeatureId,
9034 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009035 return -1;
9036 }
9037
9038 final long identity = Binder.clearCallingIdentity();
9039 try {
9040 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9041 } finally {
9042 Binder.restoreCallingIdentity(identity);
9043 }
9044 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009045
9046 @Override
9047 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009048 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009049 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009050 mApp, subId, "getCdmaRoamingMode");
9051
9052 final long identity = Binder.clearCallingIdentity();
9053 try {
9054 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9055 } finally {
9056 Binder.restoreCallingIdentity(identity);
9057 }
9058 }
9059
9060 @Override
9061 public boolean setCdmaRoamingMode(int subId, int mode) {
9062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9063 mApp, subId, "setCdmaRoamingMode");
9064
9065 final long identity = Binder.clearCallingIdentity();
9066 try {
9067 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9068 } finally {
9069 Binder.restoreCallingIdentity(identity);
9070 }
9071 }
9072
9073 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009074 public int getCdmaSubscriptionMode(int subId) {
9075 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009076 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009077 mApp, subId, "getCdmaSubscriptionMode");
9078
9079 final long identity = Binder.clearCallingIdentity();
9080 try {
9081 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9082 } finally {
9083 Binder.restoreCallingIdentity(identity);
9084 }
9085 }
9086
9087 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009088 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9090 mApp, subId, "setCdmaSubscriptionMode");
9091
9092 final long identity = Binder.clearCallingIdentity();
9093 try {
9094 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9095 } finally {
9096 Binder.restoreCallingIdentity(identity);
9097 }
9098 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009099
sqianc5eccab2018-10-19 18:46:41 -07009100 @Override
sqian8c685422019-02-22 15:55:18 -08009101 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009102 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009104 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9105 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009106 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9107 }
9108 final long identity = Binder.clearCallingIdentity();
9109 try {
sqian854d44b2018-12-12 16:48:18 -08009110 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9111 for (Phone phone: PhoneFactory.getPhones()) {
9112 if (phone.getEmergencyNumberTracker() != null
9113 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9114 emergencyNumberListInternal.put(
9115 phone.getSubId(),
9116 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9117 }
sqian11b7a0e2018-12-05 18:48:28 -08009118 }
sqian854d44b2018-12-12 16:48:18 -08009119 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009120 } finally {
9121 Binder.restoreCallingIdentity(identity);
9122 }
sqianc5eccab2018-10-19 18:46:41 -07009123 }
9124
9125 @Override
sqian8c685422019-02-22 15:55:18 -08009126 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009127 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009128 if (!exactMatch) {
9129 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009130 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009131 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009132 }
9133 final long identity = Binder.clearCallingIdentity();
9134 try {
sqian854d44b2018-12-12 16:48:18 -08009135 for (Phone phone: PhoneFactory.getPhones()) {
9136 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009137 && phone.getEmergencyNumberTracker()
9138 .isEmergencyNumber(number, exactMatch)) {
9139 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009140 }
sqian11b7a0e2018-12-05 18:48:28 -08009141 }
9142 return false;
9143 } finally {
9144 Binder.restoreCallingIdentity(identity);
9145 }
9146 }
9147
sqianf4ca7ed2019-01-15 18:32:07 -08009148 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009149 * Start emergency callback mode for GsmCdmaPhone for testing.
9150 */
9151 @Override
9152 public void startEmergencyCallbackMode() {
9153 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9154 "startEmergencyCallbackMode");
9155 enforceModifyPermission();
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
9158 for (Phone phone : PhoneFactory.getPhones()) {
9159 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9160 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9161 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9162 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9163 gsmCdmaPhone.obtainMessage(
9164 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9165 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9166 }
9167 }
9168 } finally {
9169 Binder.restoreCallingIdentity(identity);
9170 }
9171 }
9172
9173 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009174 * Update emergency number list for test mode.
9175 */
9176 @Override
9177 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9178 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9179 "updateEmergencyNumberListTestMode");
9180
9181 final long identity = Binder.clearCallingIdentity();
9182 try {
9183 for (Phone phone: PhoneFactory.getPhones()) {
9184 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9185 if (tracker != null) {
9186 tracker.executeEmergencyNumberTestModeCommand(action, num);
9187 }
9188 }
9189 } finally {
9190 Binder.restoreCallingIdentity(identity);
9191 }
9192 }
9193
9194 /**
9195 * Get the full emergency number list for test mode.
9196 */
9197 @Override
9198 public List<String> getEmergencyNumberListTestMode() {
9199 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9200 "getEmergencyNumberListTestMode");
9201
9202 final long identity = Binder.clearCallingIdentity();
9203 try {
9204 Set<String> emergencyNumbers = new HashSet<>();
9205 for (Phone phone: PhoneFactory.getPhones()) {
9206 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9207 if (tracker != null) {
9208 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9209 emergencyNumbers.add(num.getNumber());
9210 }
9211 }
9212 }
9213 return new ArrayList<>(emergencyNumbers);
9214 } finally {
9215 Binder.restoreCallingIdentity(identity);
9216 }
9217 }
9218
chen xud6b45bd2018-10-30 22:27:10 -07009219 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009220 public int getEmergencyNumberDbVersion(int subId) {
9221 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9222
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
9225 final Phone phone = getPhone(subId);
9226 if (phone == null) {
9227 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9228 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9229 }
9230 return phone.getEmergencyNumberDbVersion();
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 }
9235
9236 @Override
9237 public void notifyOtaEmergencyNumberDbInstalled() {
9238 enforceModifyPermission();
9239
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
9242 for (Phone phone: PhoneFactory.getPhones()) {
9243 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9244 if (tracker != null) {
9245 tracker.updateOtaEmergencyNumberDatabase();
9246 }
9247 }
9248 } finally {
9249 Binder.restoreCallingIdentity(identity);
9250 }
9251 }
9252
9253 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009254 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009255 enforceActiveEmergencySessionPermission();
9256
9257 final long identity = Binder.clearCallingIdentity();
9258 try {
9259 for (Phone phone: PhoneFactory.getPhones()) {
9260 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9261 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009262 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9263 }
9264 }
9265 } finally {
9266 Binder.restoreCallingIdentity(identity);
9267 }
9268 }
9269
9270 @Override
9271 public void resetOtaEmergencyNumberDbFilePath() {
9272 enforceActiveEmergencySessionPermission();
9273
9274 final long identity = Binder.clearCallingIdentity();
9275 try {
9276 for (Phone phone: PhoneFactory.getPhones()) {
9277 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9278 if (tracker != null) {
9279 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009280 }
9281 }
9282 } finally {
9283 Binder.restoreCallingIdentity(identity);
9284 }
9285 }
9286
9287 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009288 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9289 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9290 Phone phone = getPhone(subId);
9291 if (phone == null) {
9292 return null;
9293 }
9294 final long identity = Binder.clearCallingIdentity();
9295 try {
9296 UiccProfile profile = UiccController.getInstance()
9297 .getUiccProfileForPhone(phone.getPhoneId());
9298 if (profile != null) {
9299 return profile.getCertsFromCarrierPrivilegeAccessRules();
9300 }
9301 } finally {
9302 Binder.restoreCallingIdentity(identity);
9303 }
9304 return null;
9305 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009306
9307 /**
9308 * Enable or disable a modem stack.
9309 */
9310 @Override
9311 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9312 enforceModifyPermission();
9313
9314 final long identity = Binder.clearCallingIdentity();
9315 try {
9316 Phone phone = PhoneFactory.getPhone(slotIndex);
9317 if (phone == null) {
9318 return false;
9319 } else {
9320 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9321 }
9322 } finally {
9323 Binder.restoreCallingIdentity(identity);
9324 }
9325 }
Michelecea4cf22018-12-21 15:00:11 -08009326
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009327 /**
9328 * Whether a modem stack is enabled or not.
9329 */
9330 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009331 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9332 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009333 Phone phone = PhoneFactory.getPhone(slotIndex);
9334 if (phone == null) return false;
9335
9336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009337 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9338 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009339 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9340 }
9341
9342 final long identity = Binder.clearCallingIdentity();
9343 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009344 try {
9345 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9346 } catch (NoSuchElementException ex) {
9347 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9348 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
9353
Michelecea4cf22018-12-21 15:00:11 -08009354 @Override
Michele0ea7d782019-03-19 14:58:42 -07009355 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009356 enforceModifyPermission();
9357
9358 final long identity = Binder.clearCallingIdentity();
9359 try {
9360 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009361 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009362 .commit();
9363 } finally {
9364 Binder.restoreCallingIdentity(identity);
9365 }
9366 }
9367
9368 @Override
Michele0ea7d782019-03-19 14:58:42 -07009369 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009370 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009372 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9373 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009374 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009375 }
Michelecea4cf22018-12-21 15:00:11 -08009376
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
Michele0ea7d782019-03-19 14:58:42 -07009379 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009380 } finally {
9381 Binder.restoreCallingIdentity(identity);
9382 }
9383 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009384
Michele0ea7d782019-03-19 14:58:42 -07009385 @TelephonyManager.IsMultiSimSupportedResult
9386 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009387 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9388 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9389 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009390 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9391 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009392 }
9393 // Check if the hardware supports multisim functionality. If usage of multisim is not
9394 // supported by the modem, indicate that it is restricted.
9395 PhoneCapability staticCapability =
9396 mPhoneConfigurationManager.getStaticPhoneCapability();
9397 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009398 loge("isMultiSimSupportedInternal: no static configuration available");
9399 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009400 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009401 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009402 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9403 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009404 }
9405 // Check if support of multiple SIMs is restricted by carrier
9406 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009407 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009408 }
9409
Michele0ea7d782019-03-19 14:58:42 -07009410 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009411 }
9412
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009413 /**
9414 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009415 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9416 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9417 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009418 * @param numOfSims number of active sims we want to switch to
9419 */
9420 @Override
9421 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009422 if (numOfSims == 1) {
9423 enforceModifyPermission();
9424 } else {
9425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9426 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9427 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009428 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009429
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009430 try {
Michele30b57b22019-03-01 12:01:14 -08009431 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009432 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009433 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9434 return;
9435 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009436 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 }
9441
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009442 @Override
9443 public boolean isApplicationOnUicc(int subId, int appType) {
9444 enforceReadPrivilegedPermission("isApplicationOnUicc");
9445 Phone phone = getPhone(subId);
9446 if (phone == null) {
9447 return false;
9448 }
9449 final long identity = Binder.clearCallingIdentity();
9450 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009451 UiccPort uiccPort = phone.getUiccPort();
9452 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009453 return false;
9454 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009455 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009456 if (uiccProfile == null) {
9457 return false;
9458 }
9459 if (TelephonyManager.APPTYPE_SIM <= appType
9460 && appType <= TelephonyManager.APPTYPE_ISIM) {
9461 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9462 }
9463 return false;
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
9468
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009469 /**
chen xub4baa772019-04-03 10:23:41 -07009470 * Get whether making changes to modem configurations will trigger reboot.
9471 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009472 */
9473 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009474 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9475 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009477 mApp, subId, callingPackage, callingFeatureId,
9478 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009479 return false;
9480 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009481 final long identity = Binder.clearCallingIdentity();
9482 try {
9483 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9484 } finally {
9485 Binder.restoreCallingIdentity(identity);
9486 }
9487 }
9488
Nathan Harold29f5f052019-02-15 13:41:57 -08009489 private void updateModemStateMetrics() {
9490 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9491 // TODO: check the state for each modem if the api is ready.
9492 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9493 }
9494
Pengquan Meng3889a572019-01-23 11:16:29 -08009495 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00009496 public int[] getSlotsMapping(@NonNull String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009497 enforceReadPrivilegedPermission("getSlotsMapping");
9498
9499 final long identity = Binder.clearCallingIdentity();
9500 try {
9501 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9502 // All logical slots should have a mapping to a physical slot.
9503 int[] logicalSlotsMapping = new int[phoneCount];
sandeepjs0a502c42021-09-27 15:34:44 +00009504 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009505 for (int i = 0; i < slotInfos.length; i++) {
9506 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9507 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9508 }
9509 }
9510 return logicalSlotsMapping;
9511 } finally {
9512 Binder.restoreCallingIdentity(identity);
9513 }
9514 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009515
9516 /**
9517 * Get the IRadio HAL Version
9518 */
9519 @Override
9520 public int getRadioHalVersion() {
9521 Phone phone = getDefaultPhone();
9522 if (phone == null) return -1;
9523 HalVersion hv = phone.getHalVersion();
9524 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9525 return hv.major * 100 + hv.minor;
9526 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009527
9528 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009529 * Get the current calling package name.
9530 * @return the current calling package name
9531 */
9532 @Override
9533 public String getCurrentPackageName() {
9534 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9535 }
9536
9537 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009538 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9539 * corresponding network requests on a subId.
9540 *
9541 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009542 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009543 * 2) APN is un-metered for this subscription, or
9544 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009545 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009546 *
9547 * @return whether data is allowed for a apn type.
9548 *
9549 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009550 */
9551 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009552 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009553 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9554 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009555
9556 // Now that all security checks passes, perform the operation as ourselves.
9557 final long identity = Binder.clearCallingIdentity();
9558 try {
9559 Phone phone = getPhone(subId);
9560 if (phone == null) return false;
9561
Jack Yu41407ee2019-05-13 16:54:09 -07009562 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009563 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
9568
9569 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009570 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009571 enforceReadPrivilegedPermission("isApnMetered");
9572
9573 // Now that all security checks passes, perform the operation as ourselves.
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 Phone phone = getPhone(subId);
9577 if (phone == null) return true; // By default return true.
9578
Jack Yu41407ee2019-05-13 16:54:09 -07009579 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009580 } finally {
9581 Binder.restoreCallingIdentity(identity);
9582 }
9583 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009584
9585 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009586 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9587 int subscriptionId, IBooleanConsumer resultCallback) {
9588 enforceModifyPermission();
9589 long token = Binder.clearCallingIdentity();
9590 try {
9591 Phone phone = getPhone(subscriptionId);
9592 if (phone == null) {
9593 try {
9594 if (resultCallback != null) {
9595 resultCallback.accept(false);
9596 }
9597 } catch (RemoteException e) {
9598 // ignore
9599 }
9600 return;
9601 }
9602 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9603 Pair.create(specifiers, (x) -> {
9604 try {
9605 if (resultCallback != null) {
9606 resultCallback.accept(x);
9607 }
9608 } catch (RemoteException e) {
9609 // ignore
9610 }
9611 });
9612 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9613 } finally {
9614 Binder.restoreCallingIdentity(token);
9615 }
9616 }
9617
9618 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009619 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9620 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009621 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009622 mApp, subId, "getSystemSelectionChannels");
9623 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9624 final long identity = Binder.clearCallingIdentity();
9625 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009626 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9627 if (result instanceof IllegalStateException) {
9628 throw (IllegalStateException) result;
9629 }
9630 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009631 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9632 return specifiers;
9633 } finally {
9634 Binder.restoreCallingIdentity(identity);
9635 }
9636 }
9637
9638 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009639 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009640 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009641 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9642 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9643 if (iccRecords == null) {
9644 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9645 return false;
9646 }
9647 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9648 }
9649
9650 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009651 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9652 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009653 if (callingPackage == null) {
9654 callingPackage = getCurrentPackageName();
9655 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009656 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9657 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009658 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9659 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009660 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9661 }
9662 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9663 Intent intent = new Intent();
9664 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9665 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9666 // Bring up choose default SMS subscription dialog right now
9667 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9668 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9669 mApp.startActivity(intent);
9670 }
chen xud5ca2d52019-05-28 15:20:57 -07009671
9672 @Override
9673 public String getMmsUAProfUrl(int subId) {
9674 //TODO investigate if this API should require proper permission check in R b/133791609
9675 final long identity = Binder.clearCallingIdentity();
9676 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009677 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9678 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9679 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9680 return carrierUAProfUrl;
9681 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009682 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9683 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009684 } finally {
9685 Binder.restoreCallingIdentity(identity);
9686 }
9687 }
9688
9689 @Override
9690 public String getMmsUserAgent(int subId) {
9691 //TODO investigate if this API should require proper permission check in R b/133791609
9692 final long identity = Binder.clearCallingIdentity();
9693 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009694 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9695 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9696 if (!TextUtils.isEmpty(carrierUserAgent)) {
9697 return carrierUserAgent;
9698 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009699 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9700 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009701 } finally {
9702 Binder.restoreCallingIdentity(identity);
9703 }
9704 }
Jack Yub07d4972019-05-28 16:12:25 -07009705
9706 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009707 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9708 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009709
Jack Yub07d4972019-05-28 16:12:25 -07009710 final long identity = Binder.clearCallingIdentity();
9711 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009712 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009713 if (phone == null) return false;
9714
Hall Liua62f5da2020-09-25 10:42:19 -07009715 switch (policy) {
9716 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9717 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9718 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9719 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9720 default:
9721 throw new IllegalArgumentException(policy + " is not a valid policy");
9722 }
Jack Yub07d4972019-05-28 16:12:25 -07009723 } finally {
9724 Binder.restoreCallingIdentity(identity);
9725 }
9726 }
9727
9728 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009729 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009730 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009731 enforceModifyPermission();
9732
changbettyd5c246e2019-12-24 15:40:37 +08009733 final long identity = Binder.clearCallingIdentity();
9734 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009735 Phone phone = getPhone(subscriptionId);
9736 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009737
Hall Liua62f5da2020-09-25 10:42:19 -07009738 switch (policy) {
9739 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9740 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9741 break;
9742 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9743 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9744 break;
9745 default:
9746 throw new IllegalArgumentException(policy + " is not a valid policy");
9747 }
changbettyd5c246e2019-12-24 15:40:37 +08009748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009753 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009754 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009755 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9756 * otherwise.
9757 */
9758 @Override
9759 public void setCepEnabled(boolean isCepEnabled) {
9760 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9761
9762 final long identity = Binder.clearCallingIdentity();
9763 try {
9764 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9765 for (Phone phone : PhoneFactory.getPhones()) {
9766 Phone defaultPhone = phone.getImsPhone();
9767 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9768 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9769 ImsPhoneCallTracker imsPhoneCallTracker =
9770 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9771 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9772 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9773 + imsPhone.getMsisdn());
9774 }
9775 }
9776 } finally {
9777 Binder.restoreCallingIdentity(identity);
9778 }
9779 }
allenwtsu46dcc572020-01-08 18:24:03 +08009780
9781 /**
9782 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9783 *
9784 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9785 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9786 * before being read.
9787 */
9788 @Override
9789 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9790 isCompressed) {
9791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9792 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009793 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9794 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9795 }
9796 if (!isImsAvailableOnDevice()) {
9797 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9798 "IMS not available on device.");
9799 }
9800
9801 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009802 try {
Hui Wang761a6682020-10-31 05:12:53 +00009803 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9804 } finally {
9805 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009806 }
9807 }
zoey chene02881a2019-12-30 16:11:23 +08009808
9809 @Override
9810 public boolean isIccLockEnabled(int subId) {
9811 enforceReadPrivilegedPermission("isIccLockEnabled");
9812
9813 // Now that all security checks passes, perform the operation as ourselves.
9814 final long identity = Binder.clearCallingIdentity();
9815 try {
9816 Phone phone = getPhone(subId);
9817 if (phone != null && phone.getIccCard() != null) {
9818 return phone.getIccCard().getIccLockEnabled();
9819 } else {
9820 return false;
9821 }
9822 } finally {
9823 Binder.restoreCallingIdentity(identity);
9824 }
9825 }
9826
9827 /**
9828 * Set the ICC pin lock enabled or disabled.
9829 *
9830 * @return an integer representing the status of IccLock enabled or disabled in the following
9831 * three cases:
9832 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9833 * successfully.
9834 * - Positive number and zero for remaining password attempts.
9835 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9836 *
9837 */
9838 @Override
9839 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9840 enforceModifyPermission();
9841
9842 Phone phone = getPhone(subId);
9843 if (phone == null) {
9844 return 0;
9845 }
9846 // Now that all security checks passes, perform the operation as ourselves.
9847 final long identity = Binder.clearCallingIdentity();
9848 try {
9849 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9850 new Pair<Boolean, String>(enabled, password), phone, null);
9851 return attemptsRemaining;
9852
9853 } catch (Exception e) {
9854 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9855 } finally {
9856 Binder.restoreCallingIdentity(identity);
9857 }
9858 return 0;
9859 }
9860
9861 /**
9862 * Change the ICC password used in ICC pin lock.
9863 *
9864 * @return an integer representing the status of IccLock changed in the following three cases:
9865 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9866 * - Positive number and zero for remaining password attempts.
9867 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9868 *
9869 */
9870 @Override
9871 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9872 enforceModifyPermission();
9873
9874 Phone phone = getPhone(subId);
9875 if (phone == null) {
9876 return 0;
9877 }
9878 // Now that all security checks passes, perform the operation as ourselves.
9879 final long identity = Binder.clearCallingIdentity();
9880 try {
9881 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9882 new Pair<String, String>(oldPassword, newPassword), phone, null);
9883 return attemptsRemaining;
9884
9885 } catch (Exception e) {
9886 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9887 } finally {
9888 Binder.restoreCallingIdentity(identity);
9889 }
9890 return 0;
9891 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009892
9893 /**
9894 * Request for receiving user activity notification
9895 */
9896 @Override
9897 public void requestUserActivityNotification() {
9898 if (!mNotifyUserActivity.get()
9899 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9900 mNotifyUserActivity.set(true);
9901 }
9902 }
9903
9904 /**
9905 * Called when userActivity is signalled in the power manager.
9906 * This is safe to call from any thread, with any window manager locks held or not.
9907 */
9908 @Override
9909 public void userActivity() {
9910 // ***************************************
9911 // * Inherited from PhoneWindowManager *
9912 // ***************************************
9913 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9914 // WITH ITS LOCKS HELD.
9915 //
9916 // This code must be VERY careful about the locks
9917 // it acquires.
9918 // In fact, the current code acquires way too many,
9919 // and probably has lurking deadlocks.
9920
9921 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9922 throw new SecurityException("Only the OS may call notifyUserActivity()");
9923 }
9924
9925 if (mNotifyUserActivity.getAndSet(false)) {
9926 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9927 USER_ACTIVITY_NOTIFICATION_DELAY);
9928 }
9929 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009930
9931 @Override
9932 public boolean canConnectTo5GInDsdsMode() {
9933 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9934 }
Jack Yud10cdd42020-09-28 20:28:01 -07009935
9936 @Override
9937 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9938 String callingFeatureId) {
9939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9940 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9941 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9942 }
9943
9944 Phone phone = getPhone(subId);
9945 if (phone == null) {
9946 throw new RuntimeException("phone is not available");
9947 }
9948 // Now that all security checks passes, perform the operation as ourselves.
9949 final long identity = Binder.clearCallingIdentity();
9950 try {
9951 return phone.getEquivalentHomePlmns();
9952 } finally {
9953 Binder.restoreCallingIdentity(identity);
9954 }
9955 }
Daniel Bright59e67312020-11-13 11:49:37 -08009956
9957 @Override
9958 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009959 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9960 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009961 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009962 if (radioInterfaceCapabilities == null) {
9963 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009964 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009965 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009966 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009967
Hui Wang641e81c2020-10-12 12:14:23 -07009968 @Override
9969 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9970 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009971 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9972 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9973 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9974 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9975 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009976 if (DBG) {
9977 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9978 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9979 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9980 }
9981
9982 if (!SubscriptionManager.isValidSubscriptionId(subId)
9983 || appType < TelephonyManager.APPTYPE_UNKNOWN
9984 || appType > TelephonyManager.APPTYPE_ISIM
9985 || nafUrl == null || securityProtocol == null || callback == null) {
9986 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9987 if (callback != null) {
9988 try {
9989 callback.onAuthenticationFailure(
9990 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9991 } catch (RemoteException exception) {
9992 log("Fail to notify onAuthenticationFailure due to " + exception);
9993 }
9994 return;
9995 }
9996 }
9997
9998 final long token = Binder.clearCallingIdentity();
9999 try {
10000 getGbaManager(subId).bootstrapAuthenticationRequest(
10001 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10002 forceBootStrapping, callback));
10003 } finally {
10004 Binder.restoreCallingIdentity(token);
10005 }
10006 }
10007
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010008 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010009 * Attempts to set the radio power state for all phones for thermal reason.
10010 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010011 * requested radio power state will actually be set. See {@link
10012 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10013 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010014 * @param enable {@code true} if trying to turn radio on.
10015 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10016 * false}.
10017 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010018 private boolean setRadioPowerForThermal(boolean enable) {
10019 boolean isPhoneAvailable = false;
10020 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10021 Phone phone = PhoneFactory.getPhone(i);
10022 if (phone != null) {
10023 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10024 isPhoneAvailable = true;
10025 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010026 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010027
10028 // return true if successfully informed the phone object about the thermal radio power
10029 // request.
10030 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010031 }
10032
10033 private int handleDataThrottlingRequest(int subId,
10034 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010035 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10036 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10037 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10038 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10039 throw new IllegalArgumentException("modem does not support data throttling");
10040 }
10041
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010042 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10043 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010044 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010045 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10046 }
10047
10048 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10049
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010050 if (isDataThrottlingSupported) {
10051 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010052 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010053 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10054 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10055 } else if (thermalMitigationResult
10056 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010057 log("Modem likely does not support data throttling on secondary carrier. Data " +
10058 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10059 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010060 }
10061 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010062 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010063
10064 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010065 }
10066
Jack Nudelman644b91a2021-03-12 14:09:48 -080010067 private static List<String> getThermalMitigationAllowlist(Context context) {
10068 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10069 for (String pckg : context.getResources()
10070 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10071 sThermalMitigationAllowlistedPackages.add(pckg);
10072 }
10073 }
10074
10075 return sThermalMitigationAllowlistedPackages;
10076 }
10077
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010078 private boolean isAnyPhoneInEmergencyState() {
10079 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10080 if (tm.isInEmergencyCall()) {
10081 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10082 return true;
10083 }
10084 for (Phone phone : PhoneFactory.getPhones()) {
10085 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10086 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10087 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10088 + phone.isInEcm());
10089 return true;
10090 }
10091 }
10092
10093 return false;
10094 }
10095
Jack Nudelman644b91a2021-03-12 14:09:48 -080010096 /**
10097 * Used by shell commands to add an authorized package name for thermal mitigation.
10098 * @param packageName name of package to be allowlisted
10099 * @param context
10100 */
10101 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10102 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10103 sThermalMitigationAllowlistedPackages.add(packageName);
10104 }
10105
10106 /**
10107 * Used by shell commands to remove an authorized package name for thermal mitigation.
10108 * @param packageName name of package to remove from allowlist
10109 * @param context
10110 */
10111 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10112 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10113 sThermalMitigationAllowlistedPackages.remove(packageName);
10114 }
10115
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010116 /**
10117 * Thermal mitigation request to control functionalities at modem.
10118 *
10119 * @param subId the id of the subscription.
10120 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010121 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010122 *
10123 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10124 */
10125 @Override
10126 @ThermalMitigationResult
10127 public int sendThermalMitigationRequest(
10128 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010129 ThermalMitigationRequest thermalMitigationRequest,
10130 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010131 enforceModifyPermission();
10132
Jack Nudelman644b91a2021-03-12 14:09:48 -080010133 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10134 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10135 .contains(callingPackage)) {
10136 throw new SecurityException("Calling package must be configured in the device config. "
10137 + "calling package: " + callingPackage);
10138 }
10139
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010140 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10141 final long identity = Binder.clearCallingIdentity();
10142
10143 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10144 try {
10145 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10146 switch (thermalMitigationAction) {
10147 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10148 thermalMitigationResult =
10149 handleDataThrottlingRequest(subId,
10150 thermalMitigationRequest.getDataThrottlingRequest());
10151 break;
10152 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10153 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10154 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10155 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10156 }
10157
10158 // Ensure that radio is on. If not able to power on due to phone being
10159 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010160 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010161 thermalMitigationResult =
10162 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10163 break;
10164 }
10165
10166 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10167 false);
10168 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10169 break;
10170 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10171 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10172 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10173 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10174 }
10175
10176 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10177 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010178 Phone phone = getPhone(subId);
10179 if (phone == null) {
10180 thermalMitigationResult =
10181 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10182 break;
10183 }
10184
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010185 TelephonyConnectionService service =
10186 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010187 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010188 Log.e(LOG_TAG, "An emergency call is pending");
10189 thermalMitigationResult =
10190 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10191 break;
10192 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010193 thermalMitigationResult =
10194 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10195 break;
10196 }
10197 } else {
10198 thermalMitigationResult =
10199 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10200 break;
10201 }
10202
10203 // Turn radio off. If not able to power off due to phone being unavailable,
10204 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010205 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010206 thermalMitigationResult =
10207 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10208 break;
10209 }
10210 thermalMitigationResult =
10211 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10212 break;
10213 default:
10214 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10215 + "not exist. Requested action: " + thermalMitigationAction);
10216 }
10217 } catch (IllegalArgumentException e) {
10218 throw e;
10219 } catch (Exception e) {
10220 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10221 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10222 } finally {
10223 Binder.restoreCallingIdentity(identity);
10224 }
10225
10226 if (DBG) {
10227 log("thermalMitigationRequest returning with thermalMitigationResult: "
10228 + thermalMitigationResult);
10229 }
10230
10231 return thermalMitigationResult;
10232 }
Hui Wang641e81c2020-10-12 12:14:23 -070010233
10234 /**
10235 * Set the GbaService Package Name that Telephony will bind to.
10236 *
10237 * @param subId The sim that the GbaService is associated with.
10238 * @param packageName The name of the package to be replaced with.
10239 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10240 */
10241 @Override
10242 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10243 enforceModifyPermission();
10244
10245 final long identity = Binder.clearCallingIdentity();
10246 try {
10247 return getGbaManager(subId).overrideServicePackage(packageName);
10248 } finally {
10249 Binder.restoreCallingIdentity(identity);
10250 }
10251 }
10252
10253 /**
10254 * Return the package name of the currently bound GbaService.
10255 *
10256 * @param subId The sim that the GbaService is associated with.
10257 * @return the package name of the GbaService configuration, null if GBA is not supported.
10258 */
10259 @Override
10260 public String getBoundGbaService(int subId) {
10261 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10262
10263 final long identity = Binder.clearCallingIdentity();
10264 try {
10265 return getGbaManager(subId).getServicePackage();
10266 } finally {
10267 Binder.restoreCallingIdentity(identity);
10268 }
10269 }
10270
10271 /**
10272 * Set the release time for telephony to unbind GbaService.
10273 *
10274 * @param subId The sim that the GbaService is associated with.
10275 * @param interval The release time to unbind GbaService by millisecond.
10276 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10277 */
10278 @Override
10279 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10280 enforceModifyPermission();
10281
10282 final long identity = Binder.clearCallingIdentity();
10283 try {
10284 return getGbaManager(subId).overrideReleaseTime(interval);
10285 } finally {
10286 Binder.restoreCallingIdentity(identity);
10287 }
10288 }
10289
10290 /**
10291 * Return the release time for telephony to unbind GbaService.
10292 *
10293 * @param subId The sim that the GbaService is associated with.
10294 * @return The release time to unbind GbaService by millisecond.
10295 */
10296 @Override
10297 public int getGbaReleaseTime(int subId) {
10298 enforceReadPrivilegedPermission("getGbaReleaseTime");
10299
10300 final long identity = Binder.clearCallingIdentity();
10301 try {
10302 return getGbaManager(subId).getReleaseTime();
10303 } finally {
10304 Binder.restoreCallingIdentity(identity);
10305 }
10306 }
10307
10308 private GbaManager getGbaManager(int subId) {
10309 GbaManager instance = GbaManager.getInstance(subId);
10310 if (instance == null) {
10311 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10312 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10313 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10314 }
10315 return instance;
10316 }
Hui Wang761a6682020-10-31 05:12:53 +000010317
10318 /**
10319 * indicate whether the device and the carrier can support
10320 * RCS VoLTE single registration.
10321 */
10322 @Override
10323 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010324 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10325 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10326 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10327 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010328
10329 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10330 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10331 }
10332
10333 final long identity = Binder.clearCallingIdentity();
10334 try {
10335 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10336 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010337 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10338 if (isCapable != null) {
10339 return isCapable;
10340 }
Hui Wang761a6682020-10-31 05:12:53 +000010341 }
Hui Wang67af90e2021-06-04 16:57:15 -070010342 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10343 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010344 } finally {
10345 Binder.restoreCallingIdentity(identity);
10346 }
10347 }
10348
10349 /**
10350 * Register RCS provisioning callback.
10351 */
10352 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010353 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010354 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010355 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010356 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010357 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10358 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010359
10360 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10361 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10362 }
10363 if (!isImsAvailableOnDevice()) {
10364 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10365 "IMS not available on device.");
10366 }
10367
10368 final long identity = Binder.clearCallingIdentity();
10369 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010370 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010371 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010372 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10373 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010374 }
Hui Wang761a6682020-10-31 05:12:53 +000010375 } finally {
10376 Binder.restoreCallingIdentity(identity);
10377 }
10378 }
10379
10380 /**
10381 * Unregister RCS provisioning callback.
10382 */
10383 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010384 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010385 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010386 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010387 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010388 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10389 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010390
10391 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10392 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10393 }
10394 if (!isImsAvailableOnDevice()) {
10395 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10396 "IMS not available on device.");
10397 }
10398
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010401 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010402 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010403 } finally {
10404 Binder.restoreCallingIdentity(identity);
10405 }
10406 }
10407
10408 /**
10409 * trigger RCS reconfiguration.
10410 */
10411 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010412 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10413 "triggerRcsReconfiguration",
10414 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010415
10416 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10417 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10418 }
10419 if (!isImsAvailableOnDevice()) {
10420 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10421 "IMS not available on device.");
10422 }
10423
10424 final long identity = Binder.clearCallingIdentity();
10425 try {
10426 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10427 } finally {
10428 Binder.restoreCallingIdentity(identity);
10429 }
10430 }
10431
10432 /**
10433 * Provide the client configuration parameters of the RCS application.
10434 */
10435 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010436 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10437 "setRcsClientConfiguration",
10438 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010439
10440 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10441 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10442 }
10443 if (!isImsAvailableOnDevice()) {
10444 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10445 "IMS not available on device.");
10446 }
10447
10448 final long identity = Binder.clearCallingIdentity();
10449
10450 try {
10451 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10452 if (configBinder == null) {
10453 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010454 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10455 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010456 } else {
10457 configBinder.setRcsClientConfiguration(rcc);
10458 }
10459 } catch (RemoteException e) {
10460 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010461 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10462 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010463 } finally {
10464 Binder.restoreCallingIdentity(identity);
10465 }
10466 }
10467
10468 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010469 * Enables or disables the test mode for RCS VoLTE single registration.
10470 */
10471 @Override
10472 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10473 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10474 "setRcsSingleRegistrationTestModeEnabled");
10475
10476 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10477 }
10478
10479 /**
10480 * Gets the test mode for RCS VoLTE single registration.
10481 */
10482 @Override
10483 public boolean getRcsSingleRegistrationTestModeEnabled() {
10484 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10485 "getRcsSingleRegistrationTestModeEnabled");
10486
10487 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10488 }
10489
10490 /**
Hui Wang761a6682020-10-31 05:12:53 +000010491 * Overrides the config of RCS VoLTE single registration enabled for the device.
10492 */
10493 @Override
10494 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10495 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10496 "setDeviceSingleRegistrationEnabledOverride");
10497 enforceModifyPermission();
10498
10499 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10500 : Boolean.parseBoolean(enabledStr);
10501 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010502 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010503 }
10504
10505 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010506 * Sends a device to device communication message. Only usable via shell.
10507 * @param message message to send.
10508 * @param value message value.
10509 */
10510 @Override
10511 public void sendDeviceToDeviceMessage(int message, int value) {
10512 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010513 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010514 enforceModifyPermission();
10515
10516 final long identity = Binder.clearCallingIdentity();
10517 try {
10518 TelephonyConnectionService service =
10519 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10520 if (service == null) {
10521 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10522 return;
10523 }
10524 service.sendTestDeviceToDeviceMessage(message, value);
10525 } finally {
10526 Binder.restoreCallingIdentity(identity);
10527 }
10528 }
10529
Tyler Gunnbabbda02021-02-10 11:05:02 -080010530 /**
10531 * Sets the specified device to device transport active.
10532 * @param transport The transport to set active.
10533 */
10534 @Override
10535 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10536 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10537 "setActiveDeviceToDeviceTransport");
10538 enforceModifyPermission();
10539
10540 final long identity = Binder.clearCallingIdentity();
10541 try {
10542 TelephonyConnectionService service =
10543 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10544 if (service == null) {
10545 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10546 return;
10547 }
10548 service.setActiveDeviceToDeviceTransport(transport);
10549 } finally {
10550 Binder.restoreCallingIdentity(identity);
10551 }
10552 }
Tyler Gunn92479152021-01-20 16:30:10 -080010553
Tyler Gunnd4575212021-05-03 14:46:49 -070010554 @Override
10555 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10556 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10557 "setDeviceToDeviceForceEnabled");
10558
10559 final long identity = Binder.clearCallingIdentity();
10560 try {
10561 Arrays.stream(PhoneFactory.getPhones()).forEach(
10562 p -> {
10563 Phone thePhone = p.getImsPhone();
10564 if (thePhone != null && thePhone instanceof ImsPhone) {
10565 ImsPhone imsPhone = (ImsPhone) thePhone;
10566 CallTracker tracker = imsPhone.getCallTracker();
10567 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10568 ImsPhoneCallTracker imsPhoneCallTracker =
10569 (ImsPhoneCallTracker) tracker;
10570 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10571 }
10572 }
10573 }
10574 );
10575 } finally {
10576 Binder.restoreCallingIdentity(identity);
10577 }
10578 }
10579
Tyler Gunn92479152021-01-20 16:30:10 -080010580 /**
Hui Wang761a6682020-10-31 05:12:53 +000010581 * Gets the config of RCS VoLTE single registration enabled for the device.
10582 */
10583 @Override
10584 public boolean getDeviceSingleRegistrationEnabled() {
10585 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10586 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10587 }
10588
10589 /**
10590 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10591 */
10592 @Override
10593 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10594 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10595 "setCarrierSingleRegistrationEnabledOverride");
10596 enforceModifyPermission();
10597
10598 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10599 : Boolean.parseBoolean(enabledStr);
10600 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10601 subId, enabled);
10602 }
10603
10604 /**
10605 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10606 */
10607 @Override
10608 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10609 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10610 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10611 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010612
10613 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010614 * Overrides the ims feature validation result
10615 */
10616 @Override
10617 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10619 "setImsFeatureValidationOverride");
10620
10621 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10622 : Boolean.parseBoolean(enabledStr);
10623 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10624 subId, enabled);
10625 }
10626
10627 /**
10628 * Gets the ims feature validation override value
10629 */
10630 @Override
10631 public boolean getImsFeatureValidationOverride(int subId) {
10632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10633 "getImsFeatureValidationOverride");
10634 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10635 }
10636
10637 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010638 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10639 * their mobile plan.
10640 */
10641 @Override
10642 public String getMobileProvisioningUrl() {
10643 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10644 final long identity = Binder.clearCallingIdentity();
10645 try {
10646 return getDefaultPhone().getMobileProvisioningUrl();
10647 } finally {
10648 Binder.restoreCallingIdentity(identity);
10649 }
10650 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010651
James.cf Linbcdf8b32021-01-14 16:44:13 +080010652 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010653 * Get the EAB contact from the EAB database.
10654 */
10655 @Override
10656 public String getContactFromEab(String contact) {
10657 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10658 enforceModifyPermission();
10659 final long identity = Binder.clearCallingIdentity();
10660 try {
10661 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10662 } finally {
10663 Binder.restoreCallingIdentity(identity);
10664 }
10665 }
10666
10667 /**
Calvin Pana1434322021-07-01 19:27:01 +080010668 * Get the EAB capability from the EAB database.
10669 */
10670 @Override
10671 public String getCapabilityFromEab(String contact) {
10672 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10673 enforceModifyPermission();
10674 final long identity = Binder.clearCallingIdentity();
10675 try {
10676 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10677 } finally {
10678 Binder.restoreCallingIdentity(identity);
10679 }
10680 }
10681
10682 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010683 * Remove the EAB contacts from the EAB database.
10684 */
10685 @Override
10686 public int removeContactFromEab(int subId, String contacts) {
10687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10688 enforceModifyPermission();
10689 final long identity = Binder.clearCallingIdentity();
10690 try {
10691 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10692 } finally {
10693 Binder.restoreCallingIdentity(identity);
10694 }
10695 }
10696
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010697 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010698 public boolean getDeviceUceEnabled() {
10699 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10700 final long identity = Binder.clearCallingIdentity();
10701 try {
10702 return mApp.getDeviceUceEnabled();
10703 } finally {
10704 Binder.restoreCallingIdentity(identity);
10705 }
10706 }
10707
10708 @Override
10709 public void setDeviceUceEnabled(boolean isEnabled) {
10710 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10711 final long identity = Binder.clearCallingIdentity();
10712 try {
10713 mApp.setDeviceUceEnabled(isEnabled);
10714 } finally {
10715 Binder.restoreCallingIdentity(identity);
10716 }
10717 }
10718
Brad Ebinger14d467f2021-02-12 06:18:28 +000010719 /**
10720 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10721 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10722 */
10723 // Used for SHELL command only right now.
10724 @Override
10725 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10726 List<String> featureTags) {
10727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10728 "addUceRegistrationOverrideShell");
10729 final long identity = Binder.clearCallingIdentity();
10730 try {
10731 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10732 new ArraySet<>(featureTags));
10733 } catch (ImsException e) {
10734 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10735 } finally {
10736 Binder.restoreCallingIdentity(identity);
10737 }
10738 }
10739
10740 /**
10741 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10742 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10743 */
10744 // Used for SHELL command only right now.
10745 @Override
10746 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10747 List<String> featureTags) {
10748 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10749 "removeUceRegistrationOverrideShell");
10750 final long identity = Binder.clearCallingIdentity();
10751 try {
10752 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10753 new ArraySet<>(featureTags));
10754 } catch (ImsException e) {
10755 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10756 } finally {
10757 Binder.restoreCallingIdentity(identity);
10758 }
10759 }
10760
10761 /**
10762 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10763 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10764 */
10765 // Used for SHELL command only right now.
10766 @Override
10767 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10769 "clearUceRegistrationOverrideShell");
10770 final long identity = Binder.clearCallingIdentity();
10771 try {
10772 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10773 } catch (ImsException e) {
10774 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
10779
10780 /**
10781 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10782 */
10783 // Used for SHELL command only right now.
10784 @Override
10785 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10786 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10787 "getLatestRcsContactUceCapabilityShell");
10788 final long identity = Binder.clearCallingIdentity();
10789 try {
10790 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10791 } catch (ImsException e) {
10792 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10793 } finally {
10794 Binder.restoreCallingIdentity(identity);
10795 }
10796 }
10797
10798 /**
10799 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10800 * device does not have an active PUBLISH.
10801 */
10802 // Used for SHELL command only right now.
10803 @Override
10804 public String getLastUcePidfXmlShell(int subId) {
10805 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10806 final long identity = Binder.clearCallingIdentity();
10807 try {
10808 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10809 } catch (ImsException e) {
10810 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10811 } finally {
10812 Binder.restoreCallingIdentity(identity);
10813 }
10814 }
10815
James.cf Line8713a42021-04-29 16:04:26 +080010816 /**
10817 * Remove UCE requests cannot be sent to the network status.
10818 */
10819 // Used for SHELL command only right now.
10820 @Override
10821 public boolean removeUceRequestDisallowedStatus(int subId) {
10822 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10823 final long identity = Binder.clearCallingIdentity();
10824 try {
10825 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10826 } catch (ImsException e) {
10827 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
James.cf Lin0fc71b02021-05-25 01:37:38 +080010833 /**
10834 * Remove UCE requests cannot be sent to the network status.
10835 */
10836 // Used for SHELL command only.
10837 @Override
10838 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10840 final long identity = Binder.clearCallingIdentity();
10841 try {
10842 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10843 } catch (ImsException e) {
10844 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10845 } finally {
10846 Binder.restoreCallingIdentity(identity);
10847 }
10848 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010849
James.cf Lin4b784aa2021-01-31 03:25:15 +080010850 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010851 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10852 String callingPackage) {
10853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10854 mApp, subId, "setSignalStrengthUpdateRequest");
10855
10856 final int callingUid = Binder.getCallingUid();
10857 // Verify that tha callingPackage belongs to the calling UID
10858 mApp.getSystemService(AppOpsManager.class)
10859 .checkPackage(callingUid, callingPackage);
10860
Rambo Wang3607f502021-02-01 21:51:40 -080010861 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010862
10863 final long identity = Binder.clearCallingIdentity();
10864 try {
10865 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10866 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10867
10868 if (result instanceof IllegalStateException) {
10869 throw (IllegalStateException) result;
10870 }
10871 } finally {
10872 Binder.restoreCallingIdentity(identity);
10873 }
10874 }
10875
10876 @Override
10877 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10878 String callingPackage) {
10879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10880 mApp, subId, "clearSignalStrengthUpdateRequest");
10881
10882 final int callingUid = Binder.getCallingUid();
10883 // Verify that tha callingPackage belongs to the calling UID
10884 mApp.getSystemService(AppOpsManager.class)
10885 .checkPackage(callingUid, callingPackage);
10886
10887 final long identity = Binder.clearCallingIdentity();
10888 try {
10889 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10890 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10891
10892 if (result instanceof IllegalStateException) {
10893 throw (IllegalStateException) result;
10894 }
10895 } finally {
10896 Binder.restoreCallingIdentity(identity);
10897 }
10898 }
10899
Rambo Wang3607f502021-02-01 21:51:40 -080010900 private static void validateSignalStrengthUpdateRequest(Context context,
10901 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010902 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10903 // phone/system process do not have further restriction on request
10904 return;
10905 }
10906
10907 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010908 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010909 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010910 context.enforceCallingOrSelfPermission(
10911 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10912 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010913 }
10914
10915 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10916 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10917 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10918 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10919 || info.isEnabled()) {
10920 throw new IllegalArgumentException(
10921 "Only system can set hide fields in SignalThresholdInfo");
10922 }
10923
10924 // Thresholds length for each RAN need in range. This has been validated in
10925 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10926 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10927 final int[] thresholds = info.getThresholds();
10928 Objects.requireNonNull(thresholds);
10929 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10930 || thresholds.length
10931 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10932 throw new IllegalArgumentException(
10933 "thresholds length is out of range: " + thresholds.length);
10934 }
10935 }
10936 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010937
10938 /**
10939 * Gets the current phone capability.
10940 *
10941 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10942 * @return the PhoneCapability which describes the data connection capability of modem.
10943 * It's used to evaluate possible phone config change, for example from single
10944 * SIM device to multi-SIM device.
10945 */
10946 @Override
10947 public PhoneCapability getPhoneCapability() {
10948 enforceReadPrivilegedPermission("getPhoneCapability");
10949 final long identity = Binder.clearCallingIdentity();
10950 try {
10951 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10952 } finally {
10953 Binder.restoreCallingIdentity(identity);
10954 }
10955 }
Michele Berionne5e411512020-11-13 02:36:59 +000010956
10957 /**
10958 * Prepare TelephonyManager for an unattended reboot. The reboot is
10959 * required to be done shortly after the API is invoked.
10960 */
10961 @Override
10962 @TelephonyManager.PrepareUnattendedRebootResult
10963 public int prepareForUnattendedReboot() {
10964 enforceRebootPermission();
10965
10966 final long identity = Binder.clearCallingIdentity();
10967 try {
10968 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10969 } finally {
10970 Binder.restoreCallingIdentity(identity);
10971 }
10972 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010973
10974 /**
10975 * Request to get the current slicing configuration including URSP rules and
10976 * NSSAIs (configured, allowed and rejected).
10977 *
10978 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10979 */
10980 @Override
10981 public void getSlicingConfig(ResultReceiver callback) {
10982 enforceReadPrivilegedPermission("getSlicingConfig");
10983
10984 final long identity = Binder.clearCallingIdentity();
10985 try {
10986 Phone phone = getDefaultPhone();
10987 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10988 } finally {
10989 Binder.restoreCallingIdentity(identity);
10990 }
10991 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000010992
10993 /**
10994 * Register an IMS connection state callback
10995 */
10996 @Override
10997 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
10998 String callingPackage) {
10999 if (feature == ImsFeature.FEATURE_MMTEL) {
11000 // ImsMmTelManager
11001 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11002 TelephonyPermissions
11003 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11004 mApp, subId, "registerImsStateCallback");
11005 } else if (feature == ImsFeature.FEATURE_RCS) {
11006 // ImsRcsManager or SipDelegateManager
11007 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11008 Binder.getCallingUid(), "registerImsStateCallback",
11009 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11010 Manifest.permission.READ_PRECISE_PHONE_STATE,
11011 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11012 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11013 }
11014
11015 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11016 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11017 "IMS not available on device.");
11018 }
11019
11020 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11021 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11022 }
11023
11024 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11025 if (controller == null) {
11026 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11027 "IMS not available on device.");
11028 }
11029
11030 if (callingPackage == null) {
11031 callingPackage = getCurrentPackageName();
11032 }
11033
11034 final long token = Binder.clearCallingIdentity();
11035 try {
11036 int slotId = getSlotIndexOrException(subId);
11037 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11038 } catch (ImsException e) {
11039 throw new ServiceSpecificException(e.getCode());
11040 } finally {
11041 Binder.restoreCallingIdentity(token);
11042 }
11043 }
11044
11045 /**
11046 * Unregister an IMS connection state callback
11047 */
11048 @Override
11049 public void unregisterImsStateCallback(IImsStateCallback cb) {
11050 final long token = Binder.clearCallingIdentity();
11051 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11052 if (controller == null) {
11053 return;
11054 }
11055 try {
11056 controller.unregisterImsStateCallback(cb);
11057 } finally {
11058 Binder.restoreCallingIdentity(token);
11059 }
11060 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011061
11062 /**
11063 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11064 *
11065 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11066 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11067 * SecurityException.
11068 * If there is current registered network this value will be same as the registered cell
11069 * identity. If the device goes out of service the previous cell identity is cached and
11070 * will be returned. If the cache age of the Cell identity is more than 24 hours
11071 * it will be cleared and null will be returned.
11072 *
11073 */
11074 @Override
11075 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11076 String callingFeatureId) {
11077 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11078 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11079 LocationAccessPolicy.checkLocationPermission(mApp,
11080 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11081 .setCallingPackage(callingPackage)
11082 .setCallingFeatureId(callingFeatureId)
11083 .setCallingPid(Binder.getCallingPid())
11084 .setCallingUid(Binder.getCallingUid())
11085 .setMethod("getLastKnownCellIdentity")
11086 .setLogAsInfo(true)
11087 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11088 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11089 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11090 .build());
11091
11092 boolean hasFinePermission =
11093 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11094 if (!hasFinePermission
11095 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11096 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11097 + "and BIND_CONNECTION_SERVICE permission.");
11098 }
11099
11100 final long identity = Binder.clearCallingIdentity();
11101 try {
11102 Phone phone = getPhone(subId);
11103 if (phone == null) return null;
11104 ServiceStateTracker sst = phone.getServiceStateTracker();
11105 if (sst == null) return null;
11106 return sst.getLastKnownCellIdentity();
11107 } finally {
11108 Binder.restoreCallingIdentity(identity);
11109 }
11110 }
jimsun38340bf2021-10-26 15:01:23 +080011111
11112 /**
11113 * Sets the modem service class Name that Telephony will bind to.
11114 *
11115 * @param serviceName The class name of the modem service.
11116 * @return true if the operation is succeed, otherwise false.
11117 */
11118 public boolean setModemService(String serviceName) {
11119 Log.d(LOG_TAG, "setModemService - " + serviceName);
11120 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11122 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11123 "setModemService");
11124 return mPhoneConfigurationManager.setModemService(serviceName);
11125 }
11126
11127 /**
11128 * Return the class name of the currently bounded modem service.
11129 *
11130 * @return the class name of the modem service.
11131 */
11132 public String getModemService() {
11133 String result;
11134 Log.d(LOG_TAG, "getModemService");
11135 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11136 TelephonyPermissions
11137 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11138 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11139 "getModemService");
11140 result = mPhoneConfigurationManager.getModemService();
11141 Log.d(LOG_TAG, "result = " + result);
11142 return result;
11143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011144}