blob: 028abfe7690de7418a0a5ae7d9426cf72a6a5fa2 [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) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002802 if (phone.isUsingNewDataStack()) {
2803 phone.getDataSettingsManager().setDataEnabled(
2804 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2805 } else {
2806 phone.getDataEnabledSettings().setDataEnabled(
2807 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809 return true;
2810 } else {
2811 return false;
2812 }
2813 } finally {
2814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 }
2817
Wink Saville36469e72014-06-11 15:17:00 -07002818 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 public boolean disableDataConnectivity() {
2821 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 int subId = mSubscriptionController.getDefaultDataSubId();
2826 final Phone phone = getPhone(subId);
2827 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002828 if (phone.isUsingNewDataStack()) {
2829 phone.getDataSettingsManager().setDataEnabled(
2830 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2831 } else {
2832 phone.getDataEnabledSettings().setDataEnabled(
2833 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2834 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 return true;
2836 } else {
2837 return false;
2838 }
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 }
2843
Sanket Padawe356d7632015-06-22 14:03:32 -07002844 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002845 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 final Phone phone = getPhone(subId);
2849 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002850 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 } else {
2852 return false;
2853 }
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 }
2858
2859 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002860 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002861 }
2862
pkanwarae03a6b2016-11-06 20:37:09 -08002863 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 enforceCallPermission();
2865
2866 final long identity = Binder.clearCallingIdentity();
2867 try {
2868 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2869 return;
2870 }
2871 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2872 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
2875 }
pkanwar32d516d2016-10-14 19:37:38 -07002876 };
2877
Wink Savilleb564aae2014-10-23 10:18:09 -07002878 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
2881 final long identity = Binder.clearCallingIdentity();
2882 try {
2883 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2884 return false;
2885 }
2886 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002892 /**
2893 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2894 * tag on getCallState Binder call.
2895 */
2896 @Deprecated
2897 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002899 if (CompatChanges.isChangeEnabled(
2900 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2901 Binder.getCallingUid())) {
2902 // Do not allow this API to be called on API version 31+, it should only be
2903 // called on old apps using this Binder call directly.
2904 throw new SecurityException("This method can only be used for applications "
2905 + "targeting API version 30 or less.");
2906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 final long identity = Binder.clearCallingIdentity();
2908 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002909 Phone phone = getPhone(getDefaultSubscription());
2910 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2911 PhoneConstantConversions.convertCallState(phone.getState());
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
2914 }
2915 }
2916
2917 @Override
2918 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2919 if (CompatChanges.isChangeEnabled(
2920 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2921 Binder.getCallingUid())) {
2922 // Check READ_PHONE_STATE for API version 31+
2923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2924 featureId, "getCallStateForSubscription")) {
2925 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2926 + "targeting API level 31+.");
2927 }
2928 }
2929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2933 PhoneConstantConversions.convertCallState(phone.getState());
2934 } finally {
2935 Binder.restoreCallingIdentity(identity);
2936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 }
2938
Sanket Padawe356d7632015-06-22 14:03:32 -07002939 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002940 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002941 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2942 }
2943
2944 @Override
2945 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 final long identity = Binder.clearCallingIdentity();
2947 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002948 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949 if (phone != null) {
Jack Yu4accbd92021-11-29 11:36:17 -08002950 if (phone.isUsingNewDataStack()) {
2951 return phone.getDataNetworkController().getInternetDataNetworkState();
2952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002953 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2954 } else {
2955 return PhoneConstantConversions.convertDataState(
2956 PhoneConstants.DataState.DISCONNECTED);
2957 }
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002960 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961 }
2962
Sanket Padawe356d7632015-06-22 14:03:32 -07002963 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002964 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002965 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2966 }
2967
2968 @Override
2969 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970 final long identity = Binder.clearCallingIdentity();
2971 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002972 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973 if (phone != null) {
2974 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2975 } else {
2976 return TelephonyManager.DATA_ACTIVITY_NONE;
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002980 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002981 }
2982
2983 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002984 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002985 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002986 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002987
2988 LocationAccessPolicy.LocationPermissionResult locationResult =
2989 LocationAccessPolicy.checkLocationPermission(mApp,
2990 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2991 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002992 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002993 .setCallingPid(Binder.getCallingPid())
2994 .setCallingUid(Binder.getCallingUid())
2995 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002996 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002997 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2998 .build());
2999 switch (locationResult) {
3000 case DENIED_HARD:
3001 throw new SecurityException("Not allowed to access cell location");
3002 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003003 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3004 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 }
3006
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003007 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003011 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003012 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 } finally {
3014 Binder.restoreCallingIdentity(identity);
3015 }
Svetoslav64fad262015-04-14 14:35:21 -07003016 }
3017
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003018 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003019 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003020 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3021 // registered cell info, so return a NULL country instead.
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003024 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3025 // Get default phone in this case.
3026 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3027 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003028 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003030 if (phone == null) return "";
3031 ServiceStateTracker sst = phone.getServiceStateTracker();
3032 if (sst == null) return "";
3033 LocaleTracker lt = sst.getLocaleTracker();
3034 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003035 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003039 }
3040
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003041 /**
3042 * This method was removed due to potential issues caused by performing partial
3043 * updates of service state, and lack of a credible use case.
3044 *
3045 * This has the ability to break the telephony implementation by disabling notification of
3046 * changes in device connectivity. DO NOT USE THIS!
3047 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003048 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 public void enableLocationUpdates() {
3050 mApp.enforceCallingOrSelfPermission(
3051 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052 }
3053
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003054 /**
3055 * This method was removed due to potential issues caused by performing partial
3056 * updates of service state, and lack of a credible use case.
3057 *
3058 * This has the ability to break the telephony implementation by disabling notification of
3059 * changes in device connectivity. DO NOT USE THIS!
3060 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 @Override
3062 public void disableLocationUpdates() {
3063 mApp.enforceCallingOrSelfPermission(
3064 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003065 }
3066
3067 @Override
3068 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003069 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3070 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003071 try {
3072 mApp.getSystemService(AppOpsManager.class)
3073 .checkPackage(Binder.getCallingUid(), callingPackage);
3074 } catch (SecurityException e) {
3075 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3076 throw e;
3077 }
3078
Nathan Haroldf096d982020-11-18 17:18:06 -08003079 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003080 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3081 throw new SecurityException(
3082 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3083 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003084
Jordan Liu1617b712019-07-10 15:06:26 -07003085 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3087 return null;
3088 }
Svetoslav64fad262015-04-14 14:35:21 -07003089
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003090 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003092 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003093 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094
Nathan Haroldf180aac2018-06-01 18:43:55 -07003095 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3096 for (CellInfo ci : info) {
3097 if (ci instanceof CellInfoGsm) {
3098 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3099 } else if (ci instanceof CellInfoWcdma) {
3100 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3101 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003102 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003103 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 }
3105
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003106 private List<CellInfo> getCachedCellInfo() {
3107 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3108 for (Phone phone : PhoneFactory.getPhones()) {
3109 List<CellInfo> info = phone.getAllCellInfo();
3110 if (info != null) cellInfos.addAll(info);
3111 }
3112 return cellInfos;
3113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114
3115 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003116 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003117 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003118 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003119
3120 LocationAccessPolicy.LocationPermissionResult locationResult =
3121 LocationAccessPolicy.checkLocationPermission(mApp,
3122 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3123 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003124 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003125 .setCallingPid(Binder.getCallingPid())
3126 .setCallingUid(Binder.getCallingUid())
3127 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003128 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003129 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3130 .build());
3131 switch (locationResult) {
3132 case DENIED_HARD:
3133 throw new SecurityException("Not allowed to access cell info");
3134 case DENIED_SOFT:
3135 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003136 }
3137
Nathan Haroldf096d982020-11-18 17:18:06 -08003138 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003139 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3140 return getCachedCellInfo();
3141 }
3142
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003143 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003144 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3148 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003149 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003150 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 if (info != null) cellInfos.addAll(info);
3152 }
3153 return cellInfos;
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 }
3157 }
3158
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003159 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003160 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3161 String callingFeatureId) {
3162 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3163 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003164 }
3165
3166 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003167 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3168 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003169 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003170 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003171 }
3172
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003173 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3174 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003175 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003176 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003177
3178 LocationAccessPolicy.LocationPermissionResult locationResult =
3179 LocationAccessPolicy.checkLocationPermission(mApp,
3180 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3181 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003182 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003183 .setCallingPid(Binder.getCallingPid())
3184 .setCallingUid(Binder.getCallingUid())
3185 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003186 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3187 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003188 .build());
3189 switch (locationResult) {
3190 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003191 if (TelephonyPermissions
3192 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003193 // Safetynet logging for b/154934934
3194 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3195 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003196 throw new SecurityException("Not allowed to access cell info");
3197 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003198 if (TelephonyPermissions
3199 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003200 // Safetynet logging for b/154934934
3201 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3202 }
Nathan Harold5320c422019-05-09 10:26:08 -07003203 try {
3204 cb.onCellInfo(new ArrayList<CellInfo>());
3205 } catch (RemoteException re) {
3206 // Drop without consequences
3207 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003208 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003209 }
3210
Nathan Harolda939a962019-05-09 10:13:47 -07003211
3212 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003213 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3214
3215 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3216 }
3217
3218 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003220 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003221 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222
3223 final long identity = Binder.clearCallingIdentity();
3224 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003225 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 } finally {
3227 Binder.restoreCallingIdentity(identity);
3228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003229 }
3230
Shishir Agrawala9f32182016-04-12 12:00:16 -07003231 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003232 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003233 Phone phone = PhoneFactory.getPhone(slotIndex);
3234 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003235 return null;
3236 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003237 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003238 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003239 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003240 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003241 return null;
3242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243
3244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 return phone.getImei();
3247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003250 }
3251
3252 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003253 public String getTypeAllocationCodeForSlot(int slotIndex) {
3254 Phone phone = PhoneFactory.getPhone(slotIndex);
3255 String tac = null;
3256 if (phone != null) {
3257 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003258 try {
3259 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3260 } catch (IndexOutOfBoundsException e) {
3261 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3262 return null;
3263 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003264 }
3265 return tac;
3266 }
3267
3268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003269 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003270 try {
3271 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3272 } catch (SecurityException se) {
3273 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3274 throw new SecurityException("Package " + callingPackage + " does not belong to "
3275 + Binder.getCallingUid());
3276 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003277 Phone phone = PhoneFactory.getPhone(slotIndex);
3278 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003279 return null;
3280 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281
Jeff Davidson913390f2018-02-23 17:11:49 -08003282 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003283 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003284 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003285 return null;
3286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287
3288 final long identity = Binder.clearCallingIdentity();
3289 try {
3290 return phone.getMeid();
3291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
Jack Yu2af8d712017-03-15 17:14:14 -07003294 }
3295
3296 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003297 public String getManufacturerCodeForSlot(int slotIndex) {
3298 Phone phone = PhoneFactory.getPhone(slotIndex);
3299 String manufacturerCode = null;
3300 if (phone != null) {
3301 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003302 try {
3303 manufacturerCode =
3304 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3305 } catch (IndexOutOfBoundsException e) {
3306 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3307 return null;
3308 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003309 }
3310 return manufacturerCode;
3311 }
3312
3313 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003314 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3315 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003316 Phone phone = PhoneFactory.getPhone(slotIndex);
3317 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003318 return null;
3319 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003320 int subId = phone.getSubId();
3321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003322 mApp, subId, callingPackage, callingFeatureId,
3323 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003324 return null;
3325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 return phone.getDeviceSvn();
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003333 }
3334
fionaxu43304da2017-11-27 22:51:16 -08003335 @Override
3336 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 final Phone phone = getPhone(subId);
3340 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
fionaxu43304da2017-11-27 22:51:16 -08003344 }
3345
3346 @Override
3347 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 final Phone phone = getPhone(subId);
3351 return phone == null ? null : phone.getCarrierName();
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
fionaxu43304da2017-11-27 22:51:16 -08003355 }
3356
calvinpanffe225e2018-11-01 19:43:06 +08003357 @Override
chen xu0026ca62019-03-06 15:28:50 -08003358 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 final Phone phone = getPhone(subId);
3362 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003363 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003364 } finally {
3365 Binder.restoreCallingIdentity(identity);
3366 }
3367 }
3368
3369 @Override
chen xu0026ca62019-03-06 15:28:50 -08003370 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003371 final long identity = Binder.clearCallingIdentity();
3372 try {
3373 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003374 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003375 } finally {
3376 Binder.restoreCallingIdentity(identity);
3377 }
3378 }
3379
chen xu651eec72018-11-11 19:03:44 -08003380 @Override
chen xu864e11c2018-12-06 22:10:03 -08003381 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3382 if (!isSubscriptionMccMnc) {
3383 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3384 }
chen xu651eec72018-11-11 19:03:44 -08003385 final Phone phone = PhoneFactory.getPhone(slotIndex);
3386 if (phone == null) {
3387 return TelephonyManager.UNKNOWN_CARRIER_ID;
3388 }
3389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3392 } finally {
3393 Binder.restoreCallingIdentity(identity);
3394 }
3395 }
3396
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003397 //
3398 // Internal helper methods.
3399 //
3400
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003401 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003402 * Make sure the caller is the calling package itself
3403 *
3404 * @throws SecurityException if the caller is not the calling package
3405 */
3406 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3407 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003408 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3409 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003410 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003411 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003412 } catch (PackageManager.NameNotFoundException e) {
3413 // packageUid is -1
3414 }
3415 if (packageUid != callingUid) {
3416 throw new SecurityException(message + ": Package " + callingPackage
3417 + " does not belong to " + callingUid);
3418 }
3419 }
3420
3421 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003422 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3423 *
3424 * @throws SecurityException if the caller does not have the required permission
3425 */
3426 private void enforceModifyPermission() {
3427 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3428 }
3429
Shuo Qian3b6ee772019-11-13 17:43:31 -08003430 private void enforceActiveEmergencySessionPermission() {
3431 mApp.enforceCallingOrSelfPermission(
3432 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3433 }
3434
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003435 /**
3436 * Make sure the caller has the CALL_PHONE permission.
3437 *
3438 * @throws SecurityException if the caller does not have the required permission
3439 */
3440 private void enforceCallPermission() {
3441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3442 }
3443
paulhu5a773602019-08-23 19:17:33 +08003444 private void enforceSettingsPermission() {
3445 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003446 }
3447
Michele Berionne5e411512020-11-13 02:36:59 +00003448 private void enforceRebootPermission() {
3449 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3450 }
3451
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 private String createTelUrl(String number) {
3453 if (TextUtils.isEmpty(number)) {
3454 return null;
3455 }
3456
Jake Hambye994d462014-02-03 13:10:13 -08003457 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003458 }
3459
Ihab Awadf9e92732013-12-05 18:02:52 -08003460 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3462 }
3463
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003464 private static void logv(String msg) {
3465 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3466 }
3467
Ihab Awadf9e92732013-12-05 18:02:52 -08003468 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003469 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3470 }
3471
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003472 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003473 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003474 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003475 }
3476
Sanket Padawe356d7632015-06-22 14:03:32 -07003477 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003478 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 final Phone phone = PhoneFactory.getPhone(slotIndex);
3482 if (phone == null) {
3483 return PhoneConstants.PHONE_TYPE_NONE;
3484 } else {
3485 return phone.getPhoneType();
3486 }
3487 } finally {
3488 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490 }
3491
3492 /**
3493 * Returns the CDMA ERI icon index to display
3494 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003496 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3497 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3498 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003499 }
3500
Sanket Padawe356d7632015-06-22 14:03:32 -07003501 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003502 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3503 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003505 mApp, subId, callingPackage, callingFeatureId,
3506 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003507 return -1;
3508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509
3510 final long identity = Binder.clearCallingIdentity();
3511 try {
3512 final Phone phone = getPhone(subId);
3513 if (phone != null) {
3514 return phone.getCdmaEriIconIndex();
3515 } else {
3516 return -1;
3517 }
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 }
3522
3523 /**
3524 * Returns the CDMA ERI icon mode,
3525 * 0 - ON
3526 * 1 - FLASHING
3527 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003529 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3530 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3531 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003532 }
3533
Sanket Padawe356d7632015-06-22 14:03:32 -07003534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003535 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3536 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003538 mApp, subId, callingPackage, callingFeatureId,
3539 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003540 return -1;
3541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 final Phone phone = getPhone(subId);
3546 if (phone != null) {
3547 return phone.getCdmaEriIconMode();
3548 } else {
3549 return -1;
3550 }
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003554 }
3555
3556 /**
3557 * Returns the CDMA ERI text,
3558 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003560 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3561 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3562 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003563 }
3564
Sanket Padawe356d7632015-06-22 14:03:32 -07003565 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003566 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3567 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003569 mApp, subId, callingPackage, callingFeatureId,
3570 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003571 return null;
3572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 final Phone phone = getPhone(subId);
3577 if (phone != null) {
3578 return phone.getCdmaEriText();
3579 } else {
3580 return null;
3581 }
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003585 }
3586
3587 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003588 * Returns the CDMA MDN.
3589 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003590 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003591 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3593 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594
3595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003598 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599 return phone.getLine1Number();
3600 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003601 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602 return null;
3603 }
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003606 }
3607 }
3608
3609 /**
3610 * Returns the CDMA MIN.
3611 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003612 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003613 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3615 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003616
3617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 final Phone phone = getPhone(subId);
3620 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3621 return phone.getCdmaMin();
3622 } else {
3623 return null;
3624 }
3625 } finally {
3626 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003627 }
3628 }
3629
Hall Liud892bec2018-11-30 14:51:45 -08003630 @Override
3631 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3632 INumberVerificationCallback callback, String callingPackage) {
3633 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3634 != PERMISSION_GRANTED) {
3635 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3636 }
3637 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3638
3639 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3640 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003641 throw new SecurityException("Calling package must be configured in the device config: "
3642 + "calling package: " + callingPackage
3643 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003644 }
3645
3646 if (range == null) {
3647 throw new NullPointerException("Range must be non-null");
3648 }
3649
3650 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003651 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003652
3653 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3654 }
3655
Junda Liuca05d5d2014-08-14 22:36:34 -07003656 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003657 * Returns true if CDMA provisioning needs to run.
3658 */
3659 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003662 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003666 }
3667
3668 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003669 * Sets the voice mail number of a given subId.
3670 */
3671 @Override
3672 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003673 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3674 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675
3676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3679 new Pair<String, String>(alphaTag, number), new Integer(subId));
3680 return success;
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003684 }
3685
Ta-wei Yen87c49842016-05-13 21:19:52 -07003686 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003687 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3688 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003689 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3690 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003691 if (!TextUtils.equals(callingPackage, systemDialer)) {
3692 throw new SecurityException("caller must be system dialer");
3693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694
3695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3698 if (phoneAccountHandle == null) {
3699 return null;
3700 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003701 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702 } finally {
3703 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003704 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003705 }
3706
3707 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003708 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3709 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003712 mApp, subId, callingPackage, callingFeatureId,
3713 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003714 return null;
3715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003717 final long identity = Binder.clearCallingIdentity();
3718 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003719 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003723 }
3724
3725 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003726 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3727 VisualVoicemailSmsFilterSettings settings) {
3728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729
3730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003737 }
3738
3739 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003740 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3741 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003746 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003750 }
3751
3752 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003753 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3754 String callingPackage, int subId) {
3755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756
3757 final long identity = Binder.clearCallingIdentity();
3758 try {
3759 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003764 }
3765
3766 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003767 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003768 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769
3770 final long identity = Binder.clearCallingIdentity();
3771 try {
3772 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003773 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774 } finally {
3775 Binder.restoreCallingIdentity(identity);
3776 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003777 }
3778
3779 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003780 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3781 String callingAttributionTag, int subId, String number, int port, String text,
3782 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003783 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003784 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003785 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003786 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003787 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3788 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003789 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003790
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003791 /**
fionaxu0152e512016-11-14 13:36:14 -08003792 * Sets the voice activation state of a given subId.
3793 */
3794 @Override
3795 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3797 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798
3799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 final Phone phone = getPhone(subId);
3802 if (phone != null) {
3803 phone.setVoiceActivationState(activationState);
3804 } else {
3805 loge("setVoiceActivationState fails with invalid subId: " + subId);
3806 }
3807 } finally {
3808 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003809 }
3810 }
3811
3812 /**
3813 * Sets the data activation state of a given subId.
3814 */
3815 @Override
3816 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3818 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819
3820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
3823 if (phone != null) {
3824 phone.setDataActivationState(activationState);
3825 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003826 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 }
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003830 }
3831 }
3832
3833 /**
3834 * Returns the voice activation state of a given subId.
3835 */
3836 @Override
3837 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839
fionaxu0152e512016-11-14 13:36:14 -08003840 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003841 final long identity = Binder.clearCallingIdentity();
3842 try {
3843 if (phone != null) {
3844 return phone.getVoiceActivationState();
3845 } else {
3846 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3847 }
3848 } finally {
3849 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003850 }
3851 }
3852
3853 /**
3854 * Returns the data activation state of a given subId.
3855 */
3856 @Override
3857 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003858 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003859
fionaxu0152e512016-11-14 13:36:14 -08003860 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 if (phone != null) {
3864 return phone.getDataActivationState();
3865 } else {
3866 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3867 }
3868 } finally {
3869 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003870 }
3871 }
3872
3873 /**
Wink Saville36469e72014-06-11 15:17:00 -07003874 * Returns the unread count of voicemails for a subId
3875 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003876 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003877 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3878 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003880 mApp, subId, callingPackage, callingFeatureId,
3881 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003882 return 0;
3883 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884 final long identity = Binder.clearCallingIdentity();
3885 try {
3886 final Phone phone = getPhone(subId);
3887 if (phone != null) {
3888 return phone.getVoiceMessageCount();
3889 } else {
3890 return 0;
3891 }
3892 } finally {
3893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003895 }
3896
3897 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003898 * returns true, if the device is in a state where both voice and data
3899 * are supported simultaneously. This can change based on location or network condition.
3900 */
3901 @Override
3902 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 final Phone phone = getPhone(subId);
3906 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3907 } finally {
3908 Binder.restoreCallingIdentity(identity);
3909 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003910 }
3911
3912 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003913 * Send the dialer code if called from the current default dialer or the caller has
3914 * carrier privilege.
3915 * @param inputCode The dialer code to send
3916 */
3917 @Override
3918 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003919 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003920 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003921 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3922 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003923 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003924 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003925 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003930 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003931 } finally {
3932 Binder.restoreCallingIdentity(identity);
3933 }
fionaxu235cc5e2017-03-06 22:25:57 -08003934 }
3935
Pengquan Menga1bb6272018-09-06 09:59:22 -07003936 @Override
3937 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003938 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003939 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003940 mApp, subId, "getNetworkSelectionMode");
3941 final long identity = Binder.clearCallingIdentity();
3942 try {
3943 if (!isActiveSubscription(subId)) {
3944 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3945 }
3946 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3947 } finally {
3948 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003949 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003950 }
3951
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003953 public boolean isInEmergencySmsMode() {
3954 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 for (Phone phone : PhoneFactory.getPhones()) {
3958 if (phone.isInEmergencySmsMode()) {
3959 return true;
3960 }
3961 }
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
3965 return false;
3966 }
3967
shilu366312e2019-12-17 09:28:10 -08003968 /**
3969 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3970 * @param subId The subscription to use to check the configuration.
3971 * @param c The callback that will be used to send the result.
3972 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003973 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003974 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3975 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003976 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003977 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003978
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003979 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3980 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3981 "IMS not available on device.");
3982 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 final long token = Binder.clearCallingIdentity();
3984 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003985 int slotId = getSlotIndexOrException(subId);
3986 verifyImsMmTelConfiguredOrThrow(slotId);
3987 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003988 } catch (ImsException e) {
3989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 } finally {
3991 Binder.restoreCallingIdentity(token);
3992 }
3993 }
3994
shilu366312e2019-12-17 09:28:10 -08003995 /**
3996 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3997 * @param subId The subscription to use to check the configuration.
3998 * @param c The callback that will be used to send the result.
3999 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004001 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004002 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004003 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004004 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4005 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4006 }
Meng Wangafbc5852019-09-19 17:37:13 -07004007 final long token = Binder.clearCallingIdentity();
4008 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004009 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4010 .removeRegistrationCallbackForSubscription(c, subId);
4011 } catch (ImsException e) {
4012 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4013 + "is inactive, ignoring unregister.");
4014 // If the subscription is no longer active, just return, since the callback
4015 // will already have been removed internally.
4016 } finally {
4017 Binder.restoreCallingIdentity(token);
4018 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004019 }
4020
Brad Ebingera34a6c22019-10-22 17:36:18 -07004021 /**
4022 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4023 */
4024 @Override
4025 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4026 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4027 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4028 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4029 "IMS not available on device.");
4030 }
4031 final long token = Binder.clearCallingIdentity();
4032 try {
4033 Phone phone = getPhone(subId);
4034 if (phone == null) {
4035 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4036 + subId + "'");
4037 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4038 }
4039 phone.getImsRegistrationState(regState -> {
4040 try {
4041 consumer.accept((regState == null)
4042 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4043 } catch (RemoteException e) {
4044 // Ignore if the remote process is no longer available to call back.
4045 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4046 }
4047 });
4048 } finally {
4049 Binder.restoreCallingIdentity(token);
4050 }
4051 }
4052
4053 /**
4054 * Get the transport type for the IMS service registration state.
4055 */
4056 @Override
4057 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004058 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004059 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004060 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4061 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4062 "IMS not available on device.");
4063 }
4064 final long token = Binder.clearCallingIdentity();
4065 try {
4066 Phone phone = getPhone(subId);
4067 if (phone == null) {
4068 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4069 + subId + "'");
4070 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4071 }
4072 phone.getImsRegistrationTech(regTech -> {
4073 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4074 int regTechConverted = (regTech == null)
4075 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4076 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4077 regTechConverted);
4078 try {
4079 consumer.accept(regTechConverted);
4080 } catch (RemoteException e) {
4081 // Ignore if the remote process is no longer available to call back.
4082 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4083 }
4084 });
4085 } finally {
4086 Binder.restoreCallingIdentity(token);
4087 }
4088 }
4089
shilu366312e2019-12-17 09:28:10 -08004090 /**
4091 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4092 * @param subId The subscription to use to check the configuration.
4093 * @param c The callback that will be used to send the result.
4094 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004095 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004096 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4097 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004098 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004099 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004100 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4101 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4102 "IMS not available on device.");
4103 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004104 final long token = Binder.clearCallingIdentity();
4105 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004106 int slotId = getSlotIndexOrException(subId);
4107 verifyImsMmTelConfiguredOrThrow(slotId);
4108 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004109 } catch (ImsException e) {
4110 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 } finally {
4112 Binder.restoreCallingIdentity(token);
4113 }
4114 }
4115
shilu366312e2019-12-17 09:28:10 -08004116 /**
4117 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4118 * @param subId The subscription to use to check the configuration.
4119 * @param c The callback that will be used to send the result.
4120 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004122 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004123 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004124 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004125 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4126 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4127 }
Meng Wangafbc5852019-09-19 17:37:13 -07004128
4129 final long token = Binder.clearCallingIdentity();
4130 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004131 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004132 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004133 } catch (ImsException e) {
4134 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4135 + "is inactive, ignoring unregister.");
4136 // If the subscription is no longer active, just return, since the callback
4137 // will already have been removed internally.
4138 } finally {
4139 Binder.restoreCallingIdentity(token);
4140 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 }
4142
4143 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004144 public boolean isCapable(int subId, int capability, int regTech) {
4145 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 final long token = Binder.clearCallingIdentity();
4147 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004148 int slotId = getSlotIndexOrException(subId);
4149 verifyImsMmTelConfiguredOrThrow(slotId);
4150 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004151 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4153 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004154 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004155 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4156 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 } finally {
4158 Binder.restoreCallingIdentity(token);
4159 }
4160 }
4161
4162 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004163 public boolean isAvailable(int subId, int capability, int regTech) {
4164 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 final long token = Binder.clearCallingIdentity();
4166 try {
4167 Phone phone = getPhone(subId);
4168 if (phone == null) return false;
4169 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004170 } catch (com.android.ims.ImsException e) {
4171 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4172 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 } finally {
4174 Binder.restoreCallingIdentity(token);
4175 }
4176 }
4177
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004178 /**
4179 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4180 * subscription.
4181 * @param subId The subscription to use to check the configuration.
4182 * @param callback The callback that will be used to send the result.
4183 * @param capability The MmTelFeature capability that will be used to send the result.
4184 * @param transportType The transport type of the MmTelFeature capability.
4185 */
4186 @Override
4187 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4188 int transportType) {
4189 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4190 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4191 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4192 "IMS not available on device.");
4193 }
4194 final long token = Binder.clearCallingIdentity();
4195 try {
4196 int slotId = getSlotIndex(subId);
4197 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4198 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4199 + subId + "'");
4200 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4201 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004202 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004203 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4204 transportType, aBoolean -> {
4205 try {
4206 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4207 } catch (RemoteException e) {
4208 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4209 + "running. Ignore");
4210 }
4211 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004212 } catch (ImsException e) {
4213 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004214 } finally {
4215 Binder.restoreCallingIdentity(token);
4216 }
4217 }
4218
shilu366312e2019-12-17 09:28:10 -08004219 /**
4220 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4221 * @param subId The subscription to use to check the configuration.
4222 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004223 @Override
4224 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004225 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004226 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004227
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 final long token = Binder.clearCallingIdentity();
4229 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004230 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004231 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004232 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004233 } catch (ImsException e) {
4234 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 } finally {
4236 Binder.restoreCallingIdentity(token);
4237 }
4238 }
4239
4240 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004241 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004243 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 final long identity = Binder.clearCallingIdentity();
4245 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004246 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004247 // This setting doesn't require an active ImsService connection, so do not verify. The
4248 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004249 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004250 } catch (ImsException e) {
4251 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 } finally {
4253 Binder.restoreCallingIdentity(identity);
4254 }
4255 }
4256
shilu366312e2019-12-17 09:28:10 -08004257 /**
4258 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4259 * @param subId The subscription to use to check the configuration.
4260 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004261 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004262 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004263 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004264 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 final long identity = Binder.clearCallingIdentity();
4266 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004267 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004268 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004269 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004270 } catch (ImsException e) {
4271 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 } finally {
4273 Binder.restoreCallingIdentity(identity);
4274 }
4275 }
4276
4277 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004278 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004280 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 final long identity = Binder.clearCallingIdentity();
4282 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004283 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004284 // This setting doesn't require an active ImsService connection, so do not verify. The
4285 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004286 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004287 } catch (ImsException e) {
4288 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 } finally {
4290 Binder.restoreCallingIdentity(identity);
4291 }
4292 }
4293
shilu366312e2019-12-17 09:28:10 -08004294 /**
4295 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4296 * @param subId The subscription to use to check the configuration.
4297 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 @Override
4299 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004300 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004301 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 final long identity = Binder.clearCallingIdentity();
4303 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004304 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004305 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004306 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004307 } catch (ImsException e) {
4308 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 } finally {
4310 Binder.restoreCallingIdentity(identity);
4311 }
4312 }
4313
4314 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004315 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004317 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 final long identity = Binder.clearCallingIdentity();
4319 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004320 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004321 // This setting doesn't require an active ImsService connection, so do not verify. The
4322 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004323 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004324 } catch (ImsException e) {
4325 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
4329 }
4330
shilu366312e2019-12-17 09:28:10 -08004331 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004332 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4333 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4334 * @param subId The subscription to use to check the configuration.
4335 */
4336 @Override
4337 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004338 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004339 mApp, subId, "isCrossSimCallingEnabledByUser");
4340 final long identity = Binder.clearCallingIdentity();
4341 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004342 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004343 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004344 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004345 } catch (ImsException e) {
4346 throw new ServiceSpecificException(e.getCode());
4347 } finally {
4348 Binder.restoreCallingIdentity(identity);
4349 }
4350 }
4351
4352 /**
4353 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4354 * Requires MODIFY_PHONE_STATE permission.
4355 * @param subId The subscription to use to check the configuration.
4356 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4357 * false otherwise
4358 */
4359 @Override
4360 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4362 "setCrossSimCallingEnabled");
4363 final long identity = Binder.clearCallingIdentity();
4364 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004365 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004366 // This setting doesn't require an active ImsService connection, so do not verify. The
4367 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004368 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004369 } catch (ImsException e) {
4370 throw new ServiceSpecificException(e.getCode());
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
4374 }
4375
4376 /**
shilu366312e2019-12-17 09:28:10 -08004377 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4378 * @param subId The subscription to use to check the configuration.
4379 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004380 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004381
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004383 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004384 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 final long identity = Binder.clearCallingIdentity();
4386 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004387 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004388 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004389 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004390 } catch (ImsException e) {
4391 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
4395 }
4396
4397 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004398 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004400 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 final long identity = Binder.clearCallingIdentity();
4402 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004403 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004404 // This setting doesn't require an active ImsService connection, so do not verify. The
4405 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004406 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004407 } catch (ImsException e) {
4408 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004409 } finally {
4410 Binder.restoreCallingIdentity(identity);
4411 }
4412 }
4413
4414 @Override
4415 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4417 "setVoWiFiNonPersistent");
4418 final long identity = Binder.clearCallingIdentity();
4419 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004420 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004421 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004422 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004423 } catch (ImsException e) {
4424 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004425 } finally {
4426 Binder.restoreCallingIdentity(identity);
4427 }
4428 }
4429
shilu366312e2019-12-17 09:28:10 -08004430 /**
4431 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4432 * @param subId The subscription to use to check the configuration.
4433 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 @Override
4435 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004436 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004437 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 final long identity = Binder.clearCallingIdentity();
4439 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004440 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004441 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004443 } catch (ImsException e) {
4444 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004445 } finally {
4446 Binder.restoreCallingIdentity(identity);
4447 }
4448 }
4449
4450 @Override
4451 public void setVoWiFiModeSetting(int subId, int mode) {
4452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4453 "setVoWiFiModeSetting");
4454 final long identity = Binder.clearCallingIdentity();
4455 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004456 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004457 // This setting doesn't require an active ImsService connection, so do not verify. The
4458 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004460 } catch (ImsException e) {
4461 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004462 } finally {
4463 Binder.restoreCallingIdentity(identity);
4464 }
4465 }
4466
4467 @Override
4468 public int getVoWiFiRoamingModeSetting(int subId) {
4469 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004472 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004473 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004475 } catch (ImsException e) {
4476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
4480 }
4481
4482 @Override
4483 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4485 "setVoWiFiRoamingModeSetting");
4486 final long identity = Binder.clearCallingIdentity();
4487 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004488 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004489 // This setting doesn't require an active ImsService connection, so do not verify. The
4490 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004491 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004492 } catch (ImsException e) {
4493 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 } finally {
4495 Binder.restoreCallingIdentity(identity);
4496 }
4497 }
4498
4499 @Override
4500 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4502 "setRttCapabilityEnabled");
4503 final long identity = Binder.clearCallingIdentity();
4504 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004505 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004506 // This setting doesn't require an active ImsService connection, so do not verify. The
4507 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004508 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004509 } catch (ImsException e) {
4510 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
4514 }
4515
shilu366312e2019-12-17 09:28:10 -08004516 /**
4517 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4518 * @param subId The subscription to use to check the configuration.
4519 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004520 @Override
4521 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004522 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004523 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 final long identity = Binder.clearCallingIdentity();
4525 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004526 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004527 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004528 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004529 } catch (ImsException e) {
4530 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
4534 }
4535
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004536 @Override
4537 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4538 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004539
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004540 final long identity = Binder.clearCallingIdentity();
4541 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004542 if (!isImsAvailableOnDevice()) {
4543 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4544 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004545 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004546 int slotId = getSlotIndexOrException(subId);
4547 verifyImsMmTelConfiguredOrThrow(slotId);
4548 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004549 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004550 } catch (ImsException e) {
4551 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004552 } finally {
4553 Binder.restoreCallingIdentity(identity);
4554 }
4555 }
4556
4557 @Override
4558 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4559 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004560
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004561 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004562 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4563 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4564 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004565 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004566 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004567 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004568 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004569 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4570 + "is inactive, ignoring unregister.");
4571 // If the subscription is no longer active, just return, since the callback will already
4572 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004573 } finally {
4574 Binder.restoreCallingIdentity(identity);
4575 }
4576 }
4577
joonhunshin2c3e4232021-11-28 07:32:01 +00004578 @Override
4579 public void registerFeatureProvisioningChangedCallback(int subId,
4580 IFeatureProvisioningCallback callback) {
4581 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4582 mApp, subId, "registerFeatureProvisioningChangedCallback");
4583
4584 final long identity = Binder.clearCallingIdentity();
4585 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4586 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4587 }
4588
4589 ImsProvisioningController.getInstance()
4590 .addFeatureProvisioningChangedCallback(subId, callback);
4591
4592 Binder.restoreCallingIdentity(identity);
4593 }
4594
4595 @Override
4596 public void unregisterFeatureProvisioningChangedCallback(int subId,
4597 IFeatureProvisioningCallback callback) {
4598 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4599 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4600
4601 final long identity = Binder.clearCallingIdentity();
4602 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4603 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4604 }
4605
4606 ImsProvisioningController.getInstance()
4607 .removeFeatureProvisioningChangedCallback(subId, callback);
4608
4609 Binder.restoreCallingIdentity(identity);
4610 }
allenwtsu99c623b2020-01-03 18:24:23 +08004611
4612 private void checkModifyPhoneStatePermission(int subId, String message) {
4613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4614 message);
4615 }
4616
4617 private boolean isImsProvisioningRequired(int subId, int capability,
4618 boolean isMmtelCapability) {
4619 Phone phone = getPhone(subId);
4620 if (phone == null) {
4621 loge("phone instance null for subid " + subId);
4622 return false;
4623 }
4624 if (isMmtelCapability) {
4625 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4626 return false;
4627 }
4628 } else {
4629 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4630 return false;
4631 }
4632 }
4633 return true;
4634 }
4635
4636 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004637 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004638 boolean isProvisioned) {
4639 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4640
4641 final long identity = Binder.clearCallingIdentity();
4642 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004643 ImsProvisioningController.getInstance()
4644 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4645 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004646 } finally {
4647 Binder.restoreCallingIdentity(identity);
4648 }
allenwtsu99c623b2020-01-03 18:24:23 +08004649 }
4650
4651
4652 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004653 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4654 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4655 mApp, subId, "getRcsProvisioningStatusForCapability");
4656
allenwtsu99c623b2020-01-03 18:24:23 +08004657 final long identity = Binder.clearCallingIdentity();
4658 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004659 return ImsProvisioningController.getInstance()
4660 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004661 } finally {
4662 Binder.restoreCallingIdentity(identity);
4663 }
4664 }
4665
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004666 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004667 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4668 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004669 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshin2c3e4232021-11-28 07:32:01 +00004670
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004671 final long identity = Binder.clearCallingIdentity();
4672 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004673 ImsProvisioningController.getInstance()
4674 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
4678 }
4679
4680 @Override
4681 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshin2c3e4232021-11-28 07:32:01 +00004682 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4683 mApp, subId, "getProvisioningStatusForCapability");
4684
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004685 final long identity = Binder.clearCallingIdentity();
4686 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004687 return ImsProvisioningController.getInstance()
4688 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004689
4690 } finally {
4691 Binder.restoreCallingIdentity(identity);
4692 }
4693 }
4694
4695 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004696 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4697 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4698 mApp, subId, "isProvisioningRequiredForCapability");
4699
4700 final long identity = Binder.clearCallingIdentity();
4701 try {
4702 return ImsProvisioningController.getInstance()
4703 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4704 } finally {
4705 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004706 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004707 }
4708
4709 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004710 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4711 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4712 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004713
joonhunshin2c3e4232021-11-28 07:32:01 +00004714 final long identity = Binder.clearCallingIdentity();
4715 try {
4716 return ImsProvisioningController.getInstance()
4717 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004721 }
4722
4723 private static String getMmTelProvisioningKey(int subId, int tech) {
4724 // resulting key is provision_ims_mmtel_{subId}_{tech}
4725 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4726 }
4727
4728 /**
4729 * Query CarrierConfig to see if the specified capability requires provisioning for the
4730 * carrier associated with the subscription id.
4731 */
4732 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4733 int capability) {
4734 CarrierConfigManager configManager = new CarrierConfigManager(context);
4735 PersistableBundle c = configManager.getConfigForSubId(subId);
4736 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004737 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004738 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4739 false);
4740 boolean requireVoiceVtProvisioning = c.getBoolean(
4741 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4742
4743 // First check to make sure that the capability requires provisioning.
4744 switch (capability) {
4745 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4746 // intentional fallthrough
4747 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4748 if (requireVoiceVtProvisioning) {
4749 // Voice and Video requires provisioning
4750 return true;
4751 }
4752 break;
4753 }
4754 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4755 if (requireUtProvisioning) {
4756 // UT requires provisioning
4757 return true;
4758 }
4759 break;
4760 }
4761 }
4762 return false;
4763 }
4764
allenwtsu99c623b2020-01-03 18:24:23 +08004765 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4766 int capability) {
4767 CarrierConfigManager configManager = new CarrierConfigManager(context);
4768 PersistableBundle c = configManager.getConfigForSubId(subId);
4769
4770 boolean requireRcsProvisioning = c.getBoolean(
4771 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4772
4773 // First check to make sure that the capability requires provisioning.
4774 switch (capability) {
4775 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4776 // intentional fallthrough
4777 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4778 if (requireRcsProvisioning) {
4779 // OPTION or PRESENCE requires provisioning
4780 return true;
4781 }
4782 break;
4783 }
4784 }
4785 return false;
4786 }
4787
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004788 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004789 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4791 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4792 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004793 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4794 mApp, subId, "getImsProvisioningInt");
4795
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004796 final long identity = Binder.clearCallingIdentity();
4797 try {
4798 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004799 int slotId = getSlotIndex(subId);
4800 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4801 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4802 + subId + "' for key:" + key);
4803 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4804 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004805
4806 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4807 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4808 return retVal;
4809 }
4810
calvinpanb5a34062021-02-08 19:59:36 +08004811 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004812 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004813 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4814 + subId + "' for key:" + key);
4815 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004816 } finally {
4817 Binder.restoreCallingIdentity(identity);
4818 }
4819 }
4820
4821 @Override
4822 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004823 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4824 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4825 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004826 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4827 mApp, subId, "getImsProvisioningString");
4828
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004829 final long identity = Binder.clearCallingIdentity();
4830 try {
4831 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004832 int slotId = getSlotIndex(subId);
4833 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4834 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4835 + subId + "' for key:" + key);
4836 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4837 }
calvinpanb5a34062021-02-08 19:59:36 +08004838 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004839 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004840 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4841 + subId + "' for key:" + key);
4842 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004843 } finally {
4844 Binder.restoreCallingIdentity(identity);
4845 }
4846 }
4847
4848 @Override
4849 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004850 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4851 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4852 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4854 "setImsProvisioningInt");
joonhunshin2c3e4232021-11-28 07:32:01 +00004855
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004856 final long identity = Binder.clearCallingIdentity();
4857 try {
4858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004859 int slotId = getSlotIndex(subId);
4860 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4861 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4862 + subId + "' for key:" + key);
4863 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4864 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004865
4866 int retVal = ImsProvisioningController.getInstance()
4867 .setProvisioningValue(subId, key, value);
4868 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4869 return retVal;
4870 }
4871
calvinpanb5a34062021-02-08 19:59:36 +08004872 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4873 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004874 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004875 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004876 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004877 } finally {
4878 Binder.restoreCallingIdentity(identity);
4879 }
4880 }
4881
4882 @Override
4883 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004884 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4885 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4886 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4888 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 int slotId = getSlotIndex(subId);
4893 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4894 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4895 + subId + "' for key:" + key);
4896 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4897 }
calvinpanb5a34062021-02-08 19:59:36 +08004898 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4899 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004901 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
4906 }
4907
Brad Ebinger919631e2021-06-02 17:46:35 -07004908 /**
4909 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4910 * for the given slot ID or no ImsResolver instance has been created.
4911 * @param slotId The slot ID that the IMS service is created for.
4912 * @throws ImsException If there is no ImsService configured for this slot.
4913 */
4914 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4915 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4916 ImsFeature.FEATURE_MMTEL)) {
4917 throw new ImsException("This subscription does not support MMTEL over IMS",
4918 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4919 }
4920 }
4921
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004922 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004923 int slotId = SubscriptionManager.getSlotIndex(subId);
4924 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004925 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4926 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004927 }
4928 return slotId;
4929 }
4930
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 private int getSlotIndex(int subId) {
4932 int slotId = SubscriptionManager.getSlotIndex(subId);
4933 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4934 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4935 }
4936 return slotId;
4937 }
4938
Wink Saville36469e72014-06-11 15:17:00 -07004939 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004940 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004941 */
4942 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004943 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4944 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004945 try {
4946 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4947 } catch (SecurityException se) {
4948 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4949 throw new SecurityException("Package " + callingPackage + " does not belong to "
4950 + Binder.getCallingUid());
4951 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004952 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004953 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004954 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004955 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004956 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004957 mApp, subId, callingPackage, callingFeatureId,
4958 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004959 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4960 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 final Phone phone = getPhone(subId);
4965 if (phone != null) {
4966 return phone.getServiceState().getDataNetworkType();
4967 } else {
4968 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4969 }
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004973 }
4974
4975 /**
4976 * Returns the data network type
4977 */
4978 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004979 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004980 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4981 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004982 }
4983
4984 /**
4985 * Returns the data network type for a subId
4986 */
4987 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004988 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4989 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07004990 String functionName = "getDataNetworkTypeForSubscriber";
4991 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
4992 mApp, functionName)) {
4993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4994 mApp, subId, callingPackage, callingFeatureId, functionName)) {
4995 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4996 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004997 }
4998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 final long identity = Binder.clearCallingIdentity();
5000 try {
5001 final Phone phone = getPhone(subId);
5002 if (phone != null) {
5003 return phone.getServiceState().getDataNetworkType();
5004 } else {
5005 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5006 }
5007 } finally {
5008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005010 }
5011
5012 /**
Wink Saville36469e72014-06-11 15:17:00 -07005013 * Returns the Voice network type for a subId
5014 */
5015 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005016 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5017 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005018 String functionName = "getVoiceNetworkTypeForSubscriber";
5019 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5020 mApp, functionName)) {
5021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5022 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5023 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5024 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005025 }
5026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027 final long identity = Binder.clearCallingIdentity();
5028 try {
5029 final Phone phone = getPhone(subId);
5030 if (phone != null) {
5031 return phone.getServiceState().getVoiceNetworkType();
5032 } else {
5033 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5034 }
5035 } finally {
5036 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005037 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005038 }
5039
5040 /**
5041 * @return true if a ICC card is present
5042 */
5043 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005044 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005045 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5046 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005047 }
5048
5049 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005050 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005051 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005052 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005053 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
5056 final Phone phone = PhoneFactory.getPhone(slotIndex);
5057 if (phone != null) {
5058 return phone.getIccCard().hasIccCard();
5059 } else {
5060 return false;
5061 }
5062 } finally {
5063 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005064 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005065 }
5066
5067 /**
5068 * Return if the current radio is LTE on CDMA. This
5069 * is a tri-state return value as for a period of time
5070 * the mode may be unknown.
5071 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005072 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005073 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005074 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005075 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005076 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005077 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5078 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5079 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005080 }
5081
Sanket Padawe356d7632015-06-22 14:03:32 -07005082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005083 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5084 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005085 try {
5086 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5087 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005088 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5089 }
5090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 final Phone phone = getPhone(subId);
5094 if (phone == null) {
5095 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5096 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005097 return TelephonyProperties.lte_on_cdma_device()
5098 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005099 }
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005102 }
Wink Saville36469e72014-06-11 15:17:00 -07005103 }
5104
Wink Saville36469e72014-06-11 15:17:00 -07005105 /**
5106 * {@hide}
5107 * Returns Default subId, 0 in the case of single standby.
5108 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005109 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005110 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005111 }
5112
Shishir Agrawala9f32182016-04-12 12:00:16 -07005113 private int getSlotForDefaultSubscription() {
5114 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5115 }
5116
Wink Savilleb564aae2014-10-23 10:18:09 -07005117 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005118 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005119 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005120
Pengquan Menge92a50d2018-09-21 15:54:48 -07005121 private boolean isActiveSubscription(int subId) {
5122 return mSubscriptionController.isActiveSubId(subId);
5123 }
5124
Ihab Awadf2177b72013-11-25 13:33:23 -08005125 /**
5126 * @see android.telephony.TelephonyManager.WifiCallingChoices
5127 */
5128 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 final long identity = Binder.clearCallingIdentity();
5130 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005131 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5133 getWhenToMakeWifiCallsDefaultPreference());
5134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005137 }
5138
5139 /**
5140 * @see android.telephony.TelephonyManager.WifiCallingChoices
5141 */
5142 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005146 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5148 } finally {
5149 Binder.restoreCallingIdentity(identity);
5150 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005151 }
5152
Sailesh Nepald1e68152013-12-12 19:08:02 -08005153 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005154 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005155 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005156 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005157
Jordan Liu4c733742019-02-28 12:03:40 -08005158 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5159 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5160 if (phoneId == -1) {
5161 throw new IllegalArgumentException("Given slot index: " + slotIndex
5162 + " does not correspond to an active phone");
5163 }
5164 return PhoneFactory.getPhone(phoneId);
5165 }
5166
Shishir Agrawal566b7612013-10-28 14:41:00 -07005167 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005168 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5169 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5171 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005173 if (DBG) {
5174 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5175 }
5176 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5177 p2);
5178 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005179
Jordan Liu4c733742019-02-28 12:03:40 -08005180
5181 @Override
5182 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5183 int slotIndex, String callingPackage, String aid, int p2) {
5184 enforceModifyPermission();
5185 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5186 if (DBG) {
5187 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5188 }
5189 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5190 callingPackage, aid, p2);
5191 }
5192
5193 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5194 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 final long identity = Binder.clearCallingIdentity();
5196 try {
5197 if (TextUtils.equals(ISDR_AID, aid)) {
5198 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005199 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5200 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 if (bestComponent == null
5202 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5203 loge("The calling package is not allowed to access ISD-R.");
5204 throw new SecurityException(
5205 "The calling package is not allowed to access ISD-R.");
5206 }
Derek Tan740e1672017-06-27 14:56:27 -07005207 }
Derek Tan740e1672017-06-27 14:56:27 -07005208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005210 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5211 null /* workSource */);
5212 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 return response;
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005217 }
5218
5219 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005220 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5222 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005223 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5224 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5225 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005226
Jordan Liu4c733742019-02-28 12:03:40 -08005227 @Override
5228 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5229 enforceModifyPermission();
5230 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5231 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5232 channel);
5233 }
5234
5235 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 final long identity = Binder.clearCallingIdentity();
5237 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 if (channel < 0) {
5239 return false;
5240 }
Jordan Liu4c733742019-02-28 12:03:40 -08005241 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5242 null /* workSource */);
5243 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 return success;
5245 } finally {
5246 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005247 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005248 }
5249
5250 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005251 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005252 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5254 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005255 if (DBG) {
5256 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5257 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5258 + p3 + " data=" + data);
5259 }
5260 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5261 command, p1, p2, p3, data);
5262 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005263
Jordan Liu4c733742019-02-28 12:03:40 -08005264 @Override
5265 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5266 int command, int p1, int p2, int p3, String data) {
5267 enforceModifyPermission();
5268 if (DBG) {
5269 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5270 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5271 + p3 + " data=" + data);
5272 }
5273 return iccTransmitApduLogicalChannelWithPermission(
5274 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5275 data);
5276 }
5277
5278 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5279 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 final long identity = Binder.clearCallingIdentity();
5281 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005282 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 return "";
5284 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005287 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5288 null /* workSource */);
5289 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 // Append the returned status code to the end of the response payload.
5292 String s = Integer.toHexString(
5293 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5294 if (response.payload != null) {
5295 s = IccUtils.bytesToHexString(response.payload) + s;
5296 }
5297 return s;
5298 } finally {
5299 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005300 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005301 }
Jake Hambye994d462014-02-03 13:10:13 -08005302
Evan Charltonc66da362014-05-16 14:06:40 -07005303 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005304 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5305 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5307 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005309 if (DBG) {
5310 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5311 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5312 }
5313 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5314 cla, command, p1, p2, p3, data);
5315 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005316
Jordan Liu4c733742019-02-28 12:03:40 -08005317 @Override
5318 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5319 int command, int p1, int p2, int p3, String data) {
5320 enforceModifyPermission();
5321 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5322 if (DBG) {
5323 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5324 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5325 + " data=" + data);
5326 }
5327
5328 return iccTransmitApduBasicChannelWithPermission(
5329 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5330 p2, p3, data);
5331 }
5332
5333 // open APDU basic channel assuming the caller has sufficient permissions
5334 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5335 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 final long identity = Binder.clearCallingIdentity();
5337 try {
5338 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5339 && TextUtils.equals(ISDR_AID, data)) {
5340 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005341 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5342 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 if (bestComponent == null
5344 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5345 loge("The calling package is not allowed to select ISD-R.");
5346 throw new SecurityException(
5347 "The calling package is not allowed to select ISD-R.");
5348 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005349 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005352 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5353 null /* workSource */);
5354 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 // Append the returned status code to the end of the response payload.
5357 String s = Integer.toHexString(
5358 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5359 if (response.payload != null) {
5360 s = IccUtils.bytesToHexString(response.payload) + s;
5361 }
5362 return s;
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005365 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005366 }
5367
5368 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005369 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005370 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5372 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 final long identity = Binder.clearCallingIdentity();
5375 try {
5376 if (DBG) {
5377 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5378 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5379 }
5380
5381 IccIoResult response =
5382 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5383 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5384 subId);
5385
5386 if (DBG) {
5387 log("Exchange SIM_IO [R]" + response);
5388 }
5389
5390 byte[] result = null;
5391 int length = 2;
5392 if (response.payload != null) {
5393 length = 2 + response.payload.length;
5394 result = new byte[length];
5395 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5396 } else {
5397 result = new byte[length];
5398 }
5399
5400 result[length - 1] = (byte) response.sw2;
5401 result[length - 2] = (byte) response.sw1;
5402 return result;
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005405 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005406 }
5407
Nathan Haroldb3014052017-01-25 15:57:32 -08005408 /**
5409 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5410 * on a particular subscription
5411 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005412 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5413 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005415 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005416 return null;
5417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418
5419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 if (appType != TelephonyManager.APPTYPE_USIM
5422 && appType != TelephonyManager.APPTYPE_SIM) {
5423 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5424 return null;
5425 }
5426 Object response = sendRequest(
5427 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5428 if (response instanceof String[]) {
5429 return (String[]) response;
5430 }
yincheng zhao2737e882019-09-06 17:06:54 -07005431 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005433 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 } finally {
5435 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005436 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005437 }
5438
yincheng zhao2737e882019-09-06 17:06:54 -07005439 /**
5440 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5441 * subscription.
5442 *
5443 * @param subId the id of the subscription.
5444 * @param appType the uicc app type, must be USIM or SIM.
5445 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5446 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005447 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005448 * @return number of fplmns that is successfully written to the SIM.
5449 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005450 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5451 String callingFeatureId) {
5452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5453 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005454 if (DBG) logv("no permissions for setForbiddenplmns");
5455 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5456 }
5457 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5458 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5459 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5460 }
5461 if (fplmns == null) {
5462 throw new IllegalArgumentException("Fplmn List provided is null");
5463 }
5464 for (String fplmn : fplmns) {
5465 if (!CellIdentity.isValidPlmn(fplmn)) {
5466 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5467 }
5468 }
5469 final long identity = Binder.clearCallingIdentity();
5470 try {
5471 Object response = sendRequest(
5472 CMD_SET_FORBIDDEN_PLMNS,
5473 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5474 subId);
5475 return (int) response;
5476 } finally {
5477 Binder.restoreCallingIdentity(identity);
5478 }
5479 }
5480
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005481 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005482 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5484 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5489 if (response.payload == null) {
5490 return "";
5491 }
Evan Charltonc66da362014-05-16 14:06:40 -07005492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 // Append the returned status code to the end of the response payload.
5494 String s = Integer.toHexString(
5495 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5496 s = IccUtils.bytesToHexString(response.payload) + s;
5497 return s;
5498 } finally {
5499 Binder.restoreCallingIdentity(identity);
5500 }
Evan Charltonc66da362014-05-16 14:06:40 -07005501 }
5502
Jake Hambye994d462014-02-03 13:10:13 -08005503 /**
5504 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5505 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5506 *
5507 * @param itemID the ID of the item to read
5508 * @return the NV item as a String, or null on error.
5509 */
5510 @Override
5511 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005512 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5514 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515
5516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005519 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5521 return value;
5522 } finally {
5523 Binder.restoreCallingIdentity(identity);
5524 }
Jake Hambye994d462014-02-03 13:10:13 -08005525 }
5526
5527 /**
5528 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5529 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5530 *
5531 * @param itemID the ID of the item to read
5532 * @param itemValue the value to write, as a String
5533 * @return true on success; false on any failure
5534 */
5535 @Override
5536 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005537 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5539 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005540
5541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5544 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005545 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5547 return success;
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
Jake Hambye994d462014-02-03 13:10:13 -08005551 }
5552
5553 /**
5554 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5555 * Used for device configuration by some CDMA operators.
5556 *
5557 * @param preferredRoamingList byte array containing the new PRL
5558 * @return true on success; false on any failure
5559 */
5560 @Override
5561 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5563 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5568 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5569 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5570 return success;
5571 } finally {
5572 Binder.restoreCallingIdentity(identity);
5573 }
Jake Hambye994d462014-02-03 13:10:13 -08005574 }
5575
5576 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005577 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005578 * Used for device configuration by some CDMA operators.
5579 *
chen xu6dac5ab2018-10-26 17:39:23 -07005580 * @param slotIndex - device slot.
5581 *
Jake Hambye994d462014-02-03 13:10:13 -08005582 * @return true on success; false on any failure
5583 */
5584 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005585 public boolean resetModemConfig(int slotIndex) {
5586 Phone phone = PhoneFactory.getPhone(slotIndex);
5587 if (phone != null) {
5588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5589 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590
chen xu6dac5ab2018-10-26 17:39:23 -07005591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5594 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5595 return success;
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 }
chen xu6dac5ab2018-10-26 17:39:23 -07005600 return false;
5601 }
5602
5603 /**
5604 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5605 *
5606 * @param slotIndex - device slot.
5607 *
5608 * @return true on success; false on any failure
5609 */
5610 @Override
5611 public boolean rebootModem(int slotIndex) {
5612 Phone phone = PhoneFactory.getPhone(slotIndex);
5613 if (phone != null) {
5614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5615 mApp, phone.getSubId(), "rebootModem");
5616
5617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5620 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5621 return success;
5622 } finally {
5623 Binder.restoreCallingIdentity(identity);
5624 }
5625 }
5626 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005627 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005628
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005629 public String[] getPcscfAddress(String apnType, String callingPackage,
5630 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005631 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5633 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005634 return new String[0];
5635 }
5636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 final long identity = Binder.clearCallingIdentity();
5638 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005639 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
Wink Saville36469e72014-06-11 15:17:00 -07005643 }
5644
Brad Ebinger51f743a2017-01-23 13:50:20 -08005645 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005646 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5647 * {@link #disableIms(int)}.
5648 * @param slotIndex device slot.
5649 */
5650 public void resetIms(int slotIndex) {
5651 enforceModifyPermission();
5652
5653 final long identity = Binder.clearCallingIdentity();
5654 try {
5655 if (mImsResolver == null) {
5656 // may happen if the does not support IMS.
5657 return;
5658 }
5659 mImsResolver.disableIms(slotIndex);
5660 mImsResolver.enableIms(slotIndex);
5661 } finally {
5662 Binder.restoreCallingIdentity(identity);
5663 }
5664 }
5665
5666 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005667 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5668 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005669 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005670 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672
5673 final long identity = Binder.clearCallingIdentity();
5674 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005675 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005676 // may happen if the device does not support IMS.
5677 return;
5678 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005679 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 } finally {
5681 Binder.restoreCallingIdentity(identity);
5682 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005683 }
5684
5685 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005686 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5687 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005688 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005689 public void disableIms(int slotId) {
5690 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691
5692 final long identity = Binder.clearCallingIdentity();
5693 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005694 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005695 // may happen if the device does not support IMS.
5696 return;
5697 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005698 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005702 }
5703
5704 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005705 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5706 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005707 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005708 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005709 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711
5712 final long identity = Binder.clearCallingIdentity();
5713 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005714 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005715 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5716 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005717 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005718 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 } finally {
5720 Binder.restoreCallingIdentity(identity);
5721 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005722 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005723 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005724 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5725 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005726 @Override
5727 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005728 enforceModifyPermission();
5729
5730 final long identity = Binder.clearCallingIdentity();
5731 try {
5732 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005733 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005734 } finally {
5735 Binder.restoreCallingIdentity(identity);
5736 }
5737 }
5738
5739 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005740 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005741 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005742 */
5743 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005748 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005749 // may happen if the device does not support IMS.
5750 return null;
5751 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005752 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005756 }
5757
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005758 /**
5759 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005760 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005761 */
5762 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764
5765 final long identity = Binder.clearCallingIdentity();
5766 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005767 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005768 // may happen if the device does not support IMS.
5769 return null;
5770 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005771 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005775 }
5776
Brad Ebinger884c07b2018-02-15 16:17:40 -08005777 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005778 * Sets the ImsService Package Name that Telephony will bind to.
5779 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005780 * @param slotIndex the slot ID that the ImsService should bind for.
5781 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005782 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005783 * @param featureTypes An integer array of feature types associated with a packageName.
5784 * @param packageName The name of the package that the current configuration will be replaced
5785 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005786 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005787 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005788 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5789 int[] featureTypes, String packageName) {
5790 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5791 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5793 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005794 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 final long identity = Binder.clearCallingIdentity();
5797 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005798 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005799 // may happen if the device does not support IMS.
5800 return false;
5801 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005802 Map<Integer, String> featureConfig = new HashMap<>();
5803 for (int featureType : featureTypes) {
5804 featureConfig.put(featureType, packageName);
5805 }
5806 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5807 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005811 }
5812
5813 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005814 * Clears any carrier ImsService overrides for the slot index specified that were previously
5815 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5816 *
5817 * This should only be used for testing.
5818 *
5819 * @param slotIndex the slot ID that the ImsService should bind for.
5820 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5821 */
5822 @Override
5823 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5824 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5825 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5826 "clearCarrierImsServiceOverride");
5827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5828 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5829 "clearCarrierImsServiceOverride");
5830
5831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 if (mImsResolver == null) {
5834 // may happen if the device does not support IMS.
5835 return false;
5836 }
5837 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5838 } finally {
5839 Binder.restoreCallingIdentity(identity);
5840 }
5841 }
5842
5843 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005844 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005845 *
5846 * @param slotId The slot that the ImsService is associated with.
5847 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5848 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005849 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005850 * @return the package name of the ImsService configuration.
5851 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5853 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005854 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005855 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005856 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5858 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 final long identity = Binder.clearCallingIdentity();
5861 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005862 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005863 // may happen if the device does not support IMS.
5864 return "";
5865 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005866 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5868 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005872 }
5873
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005874 /**
5875 * Get the MmTelFeature state associated with the requested subscription id.
5876 * @param subId The subscription that the MmTelFeature is associated with.
5877 * @param callback A callback with an integer containing the
5878 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5879 */
5880 @Override
5881 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5882 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5883 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5884 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5885 "IMS not available on device.");
5886 }
5887 final long token = Binder.clearCallingIdentity();
5888 try {
5889 int slotId = getSlotIndex(subId);
5890 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5891 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5892 + subId + "'");
5893 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5894 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005895 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005896 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5897 try {
5898 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5899 } catch (RemoteException e) {
5900 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5901 + "Ignore");
5902 }
5903 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005904 } catch (ImsException e) {
5905 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005906 } finally {
5907 Binder.restoreCallingIdentity(token);
5908 }
5909 }
5910
Daniel Brightbb5840b2021-01-12 15:48:18 -08005911 /**
5912 * Sets the ims registration state on all valid {@link Phone}s.
5913 */
5914 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005915 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916
5917 final long identity = Binder.clearCallingIdentity();
5918 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005919 // NOTE: Before S, this method only set the default phone.
5920 for (final Phone phone : PhoneFactory.getPhones()) {
5921 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5922 phone.setImsRegistrationState(registered);
5923 }
5924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 } finally {
5926 Binder.restoreCallingIdentity(identity);
5927 }
Wink Saville36469e72014-06-11 15:17:00 -07005928 }
5929
5930 /**
Stuart Scott54788802015-03-30 13:18:01 -07005931 * Set the network selection mode to automatic.
5932 *
5933 */
5934 @Override
5935 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5937 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938
5939 final long identity = Binder.clearCallingIdentity();
5940 try {
shilufc958392020-01-20 11:36:01 -08005941 if (!isActiveSubscription(subId)) {
5942 return;
5943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005945 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5946 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
Stuart Scott54788802015-03-30 13:18:01 -07005950 }
5951
Jack Yud10cdd42020-09-28 20:28:01 -07005952 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005953 * Ask the radio to connect to the input network and change selection mode to manual.
5954 *
5955 * @param subId the id of the subscription.
5956 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5957 * the operator to attach to.
5958 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5959 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5960 * normal network selection next time.
5961 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005962 */
5963 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005964 public boolean setNetworkSelectionModeManual(
5965 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5967 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005968
5969 if (!isActiveSubscription(subId)) {
5970 return false;
5971 }
5972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 final long identity = Binder.clearCallingIdentity();
5974 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005975 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005977 if (DBG) {
5978 log("setNetworkSelectionModeManual: subId: " + subId
5979 + " operator: " + operatorInfo);
5980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5982 } finally {
5983 Binder.restoreCallingIdentity(identity);
5984 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005985 }
shilu84f6e8b2019-12-19 13:58:01 -08005986 /**
5987 * Get the manual network selection
5988 *
5989 * @param subId the id of the subscription.
5990 *
5991 * @return the previously saved user selected PLMN
5992 */
5993 @Override
5994 public String getManualNetworkSelectionPlmn(int subId) {
5995 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005996 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005997 mApp, subId, "getManualNetworkSelectionPlmn");
5998
5999 final long identity = Binder.clearCallingIdentity();
6000 try {
6001 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006002 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006003 }
6004
6005 final Phone phone = getPhone(subId);
6006 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006007 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006008 }
6009 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6010 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6011 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6012 } finally {
6013 Binder.restoreCallingIdentity(identity);
6014 }
6015 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006016
6017 /**
6018 * Scans for available networks.
6019 */
6020 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006021 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6022 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6024 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006025 LocationAccessPolicy.LocationPermissionResult locationResult =
6026 LocationAccessPolicy.checkLocationPermission(mApp,
6027 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6028 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006029 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006030 .setCallingPid(Binder.getCallingPid())
6031 .setCallingUid(Binder.getCallingUid())
6032 .setMethod("getCellNetworkScanResults")
6033 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006034 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6035 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006036 .build());
6037 switch (locationResult) {
6038 case DENIED_HARD:
6039 throw new SecurityException("Not allowed to access scan results -- location");
6040 case DENIED_SOFT:
6041 return null;
6042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043
Pengquan Menga1bb6272018-09-06 09:59:22 -07006044 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 try {
6046 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006047 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006052 }
6053
6054 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006055 * Get the call forwarding info, given the call forwarding reason.
6056 */
6057 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006058 public void getCallForwarding(int subId, int callForwardingReason,
6059 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006060 enforceReadPrivilegedPermission("getCallForwarding");
6061 long identity = Binder.clearCallingIdentity();
6062 try {
6063 if (DBG) {
6064 log("getCallForwarding: subId " + subId
6065 + " callForwardingReason" + callForwardingReason);
6066 }
Hall Liu27d24262020-09-18 19:04:59 -07006067
6068 Phone phone = getPhone(subId);
6069 if (phone == null) {
6070 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006071 callback.onError(
6072 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006073 } catch (RemoteException e) {
6074 // ignore
6075 }
6076 return;
6077 }
6078
6079 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6080 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6081 @Override
6082 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6083 try {
6084 callback.onCallForwardingInfoAvailable(info);
6085 } catch (RemoteException e) {
6086 // ignore
6087 }
6088 }
6089
6090 @Override
6091 public void onError(int error) {
6092 try {
6093 callback.onError(error);
6094 } catch (RemoteException e) {
6095 // ignore
6096 }
6097 }
6098 });
6099 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006100 } finally {
6101 Binder.restoreCallingIdentity(identity);
6102 }
6103 }
6104
6105 /**
6106 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6107 * reason, the number to forward, and the timeout before the forwarding is attempted.
6108 */
6109 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006110 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6111 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006112 enforceModifyPermission();
6113 long identity = Binder.clearCallingIdentity();
6114 try {
6115 if (DBG) {
6116 log("setCallForwarding: subId " + subId
6117 + " callForwardingInfo" + callForwardingInfo);
6118 }
Hall Liu27d24262020-09-18 19:04:59 -07006119
6120 Phone phone = getPhone(subId);
6121 if (phone == null) {
6122 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006123 callback.accept(
6124 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006125 } catch (RemoteException e) {
6126 // ignore
6127 }
6128 return;
6129 }
6130
6131 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6132 FunctionalUtils.ignoreRemoteException(callback::accept));
6133
6134 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
6138 }
6139
6140 /**
Hall Liu27d24262020-09-18 19:04:59 -07006141 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006142 */
6143 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006144 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006145 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006146 long identity = Binder.clearCallingIdentity();
6147 try {
Hall Liu27d24262020-09-18 19:04:59 -07006148 Phone phone = getPhone(subId);
6149 if (phone == null) {
6150 try {
6151 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6152 } catch (RemoteException e) {
6153 // ignore
6154 }
6155 return;
6156 }
SongFerngWang0e767992021-03-31 22:08:45 +08006157 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6158 PersistableBundle c = configManager.getConfigForSubId(subId);
6159 boolean requireUssd = c.getBoolean(
6160 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006161
Shuo Qian4a594052020-01-23 11:59:30 -08006162 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006163 if (requireUssd) {
6164 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6165 getSubscriptionCarrierId(subId));
6166 String newUssdCommand = "";
6167 try {
6168 newUssdCommand = carrierXmlParser.getFeature(
6169 CarrierXmlParser.FEATURE_CALL_WAITING)
6170 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6171 } catch (NullPointerException e) {
6172 loge("Failed to generate USSD number" + e);
6173 }
6174 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6175 mMainThreadHandler, callback, carrierXmlParser,
6176 CarrierXmlParser.SsEntry.SSAction.QUERY);
6177 final String ussdCommand = newUssdCommand;
6178 Executors.newSingleThreadExecutor().execute(() -> {
6179 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6180 });
6181 } else {
6182 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6183 callback::accept);
6184 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6185 }
Shuo Qian4a594052020-01-23 11:59:30 -08006186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
6189 }
6190
6191 /**
Hall Liu27d24262020-09-18 19:04:59 -07006192 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006193 */
6194 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006195 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006196 enforceModifyPermission();
6197 long identity = Binder.clearCallingIdentity();
6198 try {
Hall Liu27d24262020-09-18 19:04:59 -07006199 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6200
6201 Phone phone = getPhone(subId);
6202 if (phone == null) {
6203 try {
6204 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6205 } catch (RemoteException e) {
6206 // ignore
6207 }
6208 return;
6209 }
6210
SongFerngWang0e767992021-03-31 22:08:45 +08006211 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6212 PersistableBundle c = configManager.getConfigForSubId(subId);
6213 boolean requireUssd = c.getBoolean(
6214 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006215
SongFerngWang0e767992021-03-31 22:08:45 +08006216 if (DBG) log("getCallWaitingStatus: subId " + subId);
6217 if (requireUssd) {
6218 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6219 getSubscriptionCarrierId(subId));
6220 CarrierXmlParser.SsEntry.SSAction ssAction =
6221 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6222 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6223 String newUssdCommand = "";
6224 try {
6225 newUssdCommand = carrierXmlParser.getFeature(
6226 CarrierXmlParser.FEATURE_CALL_WAITING)
6227 .makeCommand(ssAction, null);
6228 } catch (NullPointerException e) {
6229 loge("Failed to generate USSD number" + e);
6230 }
6231 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6232 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6233 final String ussdCommand = newUssdCommand;
6234 Executors.newSingleThreadExecutor().execute(() -> {
6235 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6236 });
6237 } else {
6238 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6239 FunctionalUtils.ignoreRemoteException(callback::accept));
6240
6241 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6242 }
Shuo Qian4a594052020-01-23 11:59:30 -08006243 } finally {
6244 Binder.restoreCallingIdentity(identity);
6245 }
6246 }
6247
6248 /**
yinxub1bed742017-04-17 11:45:04 -07006249 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006250 *
yinxub1bed742017-04-17 11:45:04 -07006251 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006252 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6253 * location related information which will be sent if the caller already possess
6254 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006255 * @param request contains the radio access networks with bands/channels to scan
6256 * @param messenger callback messenger for scan results or errors
6257 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006258 * @return the id of the requested scan which can be used to stop the scan.
6259 */
6260 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006261 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6262 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006263 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6265 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006266 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006267 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6268 if (!renounceFineLocationAccess) {
6269 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6270 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6271 .setCallingPackage(callingPackage)
6272 .setCallingFeatureId(callingFeatureId)
6273 .setCallingPid(Binder.getCallingPid())
6274 .setCallingUid(Binder.getCallingUid())
6275 .setMethod("requestNetworkScan")
6276 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6277 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6278 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6279 .build());
6280 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006281 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006282 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6283 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006284 if (e != null) {
6285 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6286 throw e;
6287 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006288 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006289 return TelephonyScanManager.INVALID_SCAN_ID;
6290 }
6291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 }
Hall Liu912dfd32019-04-25 14:02:26 -07006293 int callingUid = Binder.getCallingUid();
6294 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006295 final long identity = Binder.clearCallingIdentity();
6296 try {
6297 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006298 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006299 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006300 } finally {
6301 Binder.restoreCallingIdentity(identity);
6302 }
yinxu504e1392017-04-12 16:03:22 -07006303 }
6304
Hall Liub2ac8ef2019-02-28 15:56:23 -08006305 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006306 NetworkScanRequest request, int subId, String callingPackage) {
6307 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006308 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6309 boolean hasNetworkScanPermission =
6310 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6311 == PERMISSION_GRANTED;
6312
6313 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6314 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6315 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006316 }
6317
6318 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6319 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006320 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6321 return new SecurityException("Specific channels must not be"
6322 + " scanned without location access.");
6323 }
6324 }
6325 }
6326
Hall Liub2ac8ef2019-02-28 15:56:23 -08006327 return null;
6328 }
6329
yinxu504e1392017-04-12 16:03:22 -07006330 /**
6331 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006332 *
6333 * @param subId id of the subscription
6334 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006335 */
6336 @Override
6337 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6339 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340
Hall Liu912dfd32019-04-25 14:02:26 -07006341 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 final long identity = Binder.clearCallingIdentity();
6343 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006344 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
yinxu504e1392017-04-12 16:03:22 -07006348 }
6349
6350 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006351 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006352 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006353 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006354 */
6355 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006356 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006357 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006358 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006359 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360
6361 final long identity = Binder.clearCallingIdentity();
6362 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006363 if (DBG) log("getAllowedNetworkTypesBitmask");
6364 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6365 int networkTypesBitmask = (result != null ? result[0] : -1);
6366 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6367 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006371 }
6372
6373 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006374 * Get the allowed network types for certain reason.
6375 *
6376 * @param subId the id of the subscription.
6377 * @param reason the reason the allowed network type change is taking place
6378 * @return the allowed network types.
6379 */
6380 @Override
6381 public long getAllowedNetworkTypesForReason(int subId,
6382 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006383 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006384 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006385 final long identity = Binder.clearCallingIdentity();
6386 try {
6387 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
6391 }
6392
6393 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006394 * Enable/Disable E-UTRA-NR Dual Connectivity
6395 * @param subId subscription id of the sim card
6396 * @param nrDualConnectivityState expected NR dual connectivity state
6397 * This can be passed following states
6398 * <ol>
6399 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6400 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6401 * <li>Disable NR dual connectivity and force secondary cell to be released
6402 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6403 * </ol>
6404 * @return operation result.
6405 */
6406 @Override
6407 public int setNrDualConnectivityState(int subId,
6408 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6410 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006411 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006412 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6413 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6414 }
6415
Sooraj Sasindran37444802020-08-11 10:40:43 -07006416 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6417 final long identity = Binder.clearCallingIdentity();
6418 try {
6419 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6420 nrDualConnectivityState, subId,
6421 workSource);
6422 if (DBG) log("enableNRDualConnectivity result: " + result);
6423 return result;
6424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
6427 }
6428
6429 /**
6430 * Is E-UTRA-NR Dual Connectivity enabled
6431 * @return true if dual connectivity is enabled else false
6432 */
6433 @Override
6434 public boolean isNrDualConnectivityEnabled(int subId) {
6435 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006436 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006437 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006438 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006439 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6440 return false;
6441 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006442 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6443 final long identity = Binder.clearCallingIdentity();
6444 try {
6445 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6446 null, subId, workSource);
6447 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6448 return isEnabled;
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
6452 }
6453
6454 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006455 * Set the allowed network types of the device and
6456 * provide the reason triggering the allowed network change.
6457 *
6458 * @param subId the id of the subscription.
6459 * @param reason the reason the allowed network type change is taking place
6460 * @param allowedNetworkTypes the allowed network types.
6461 * @return true on success; false on any failure.
6462 */
6463 @Override
6464 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006465 @TelephonyManager.AllowedNetworkTypesReason int reason,
6466 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6468 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006469 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006470 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6471 return false;
6472 }
6473 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6474 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006475 return false;
6476 }
6477
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006478 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6479 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6480
6481
6482 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6483 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6484 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006485 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006486
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006487 final long identity = Binder.clearCallingIdentity();
6488 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006489 Boolean success = (Boolean) sendRequest(
6490 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6491 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6492
6493 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6494 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
6498 }
6499
6500 /**
Miaoa84611c2019-03-15 09:21:10 +08006501 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006502 *
Miaoa84611c2019-03-15 09:21:10 +08006503 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006504 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006505 * @hide
6506 */
6507 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006508 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006509 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006510 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006511 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512 try {
Miaoa84611c2019-03-15 09:21:10 +08006513 if (phone != null) {
6514 return phone.hasMatchedTetherApnSetting();
6515 } else {
6516 return false;
6517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006518 } finally {
6519 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006520 }
Junda Liu475951f2014-11-07 16:45:03 -08006521 }
6522
6523 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006524 * Get the user enabled state of Mobile Data.
6525 *
6526 * TODO: remove and use isUserDataEnabled.
6527 * This can't be removed now because some vendor codes
6528 * calls through ITelephony directly while they should
6529 * use TelephonyManager.
6530 *
6531 * @return true on enabled
6532 */
6533 @Override
6534 public boolean getDataEnabled(int subId) {
6535 return isUserDataEnabled(subId);
6536 }
6537
6538 /**
6539 * Get whether mobile data is enabled per user setting.
6540 *
6541 * There are other factors deciding whether mobile data is actually enabled, but they are
6542 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006543 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006544 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6545 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006546 *
6547 * @return {@code true} if data is enabled else {@code false}
6548 */
6549 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006550 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006551 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006552 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006553 try {
6554 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6555 functionName);
6556 } catch (Exception e) {
6557 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6558 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006559 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006561 mApp, subId, functionName);
6562
Robert Greenwalt646120a2014-05-23 11:54:03 -07006563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564
6565 final long identity = Binder.clearCallingIdentity();
6566 try {
6567 int phoneId = mSubscriptionController.getPhoneId(subId);
6568 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6569 Phone phone = PhoneFactory.getPhone(phoneId);
6570 if (phone != null) {
6571 boolean retVal = phone.isUserDataEnabled();
6572 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6573 return retVal;
6574 } else {
6575 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6576 return false;
6577 }
6578 } finally {
6579 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006580 }
6581 }
6582
6583 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006584 * Checks if the device is capable of mobile data by considering whether whether the
6585 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6586 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006587 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006588 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006589 */
6590 @Override
6591 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006592 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006593 try {
6594 try {
6595 mApp.enforceCallingOrSelfPermission(
6596 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006597 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006598 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006599 try {
6600 mApp.enforceCallingOrSelfPermission(
6601 android.Manifest.permission.READ_PHONE_STATE,
6602 functionName);
6603 } catch (Exception e2) {
6604 mApp.enforceCallingOrSelfPermission(
6605 permission.READ_BASIC_PHONE_STATE, functionName);
6606 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006607 }
6608 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006609 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611
6612 final long identity = Binder.clearCallingIdentity();
6613 try {
6614 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 Phone phone = PhoneFactory.getPhone(phoneId);
6616 if (phone != null) {
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006617 boolean retVal;
6618 if (phone.isUsingNewDataStack()) {
6619 retVal = phone.getDataNetworkController().getDataSettingsManager()
6620 .isDataEnabled();
6621 } else {
6622 retVal = phone.getDataEnabledSettings().isDataEnabled();
6623 }
6624 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625 return retVal;
6626 } else {
6627 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6628 return false;
6629 }
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006632 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006633 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006634
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006635 /**
6636 * Check if data is enabled for a specific reason
6637 * @param subId Subscription index
6638 * @param reason the reason the data enable change is taking place
6639 * @return {@code true} if the overall data is enabled; {@code false} if not.
6640 */
6641 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006642 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006643 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006644 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006645 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006646 try {
6647 mApp.enforceCallingOrSelfPermission(
6648 android.Manifest.permission.ACCESS_NETWORK_STATE,
6649 functionName);
6650 } catch (Exception e) {
6651 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6652 functionName);
6653 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006654 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006655 try {
6656 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006657 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006658 } catch (Exception e2) {
6659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006660 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006661 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006662 }
6663
6664
6665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 int phoneId = mSubscriptionController.getPhoneId(subId);
6668 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006669 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006670 + " reason=" + reason);
6671 }
6672 Phone phone = PhoneFactory.getPhone(phoneId);
6673 if (phone != null) {
6674 boolean retVal;
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006675 if (phone.isUsingNewDataStack()) {
6676 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006677 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006678 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6679 retVal = phone.isUserDataEnabled();
6680 } else {
6681 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6682 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006683 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006684 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006685 return retVal;
6686 } else {
6687 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006688 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006689 + subId + " retVal=false");
6690 }
6691 return false;
6692 }
6693 } finally {
6694 Binder.restoreCallingIdentity(identity);
6695 }
6696 }
6697
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006698 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006699 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006700 if (uid == Process.PHONE_UID) {
6701 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6702 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006703 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6704 }
6705
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006706 //load access rules from carrier configs, and check those as well: b/139133814
6707 SubscriptionController subController = SubscriptionController.getInstance();
6708 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6709 || subController == null) return privilegeFromSim;
6710
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006711 PackageManager pkgMgr = phone.getContext().getPackageManager();
6712 String[] packages = pkgMgr.getPackagesForUid(uid);
6713
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006716 int subId = phone.getSubId();
6717 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6718 // A test override is in place for the privileges for this subId, so don't try to
6719 // read the subscription privileges.
6720 return privilegeFromSim;
6721 }
6722 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006723 SubscriptionManager subManager = (SubscriptionManager)
6724 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6725 for (String pkg : packages) {
6726 if (subManager.canManageSubscription(subInfo, pkg)) {
6727 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6728 }
6729 }
6730 return privilegeFromSim;
6731 } finally {
6732 Binder.restoreCallingIdentity(identity);
6733 }
6734 }
6735
6736 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6737 String pkgName) {
6738 //load access rules from carrier configs, and check those as well: b/139133814
6739 SubscriptionController subController = SubscriptionController.getInstance();
6740 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6741 || subController == null) return privilegeFromSim;
6742
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006745 int subId = phone.getSubId();
6746 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6747 // A test override is in place for the privileges for this subId, so don't try to
6748 // read the subscription privileges.
6749 return privilegeFromSim;
6750 }
6751 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006752 SubscriptionManager subManager = (SubscriptionManager)
6753 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6754 return subManager.canManageSubscription(subInfo, pkgName)
6755 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
6758 }
6759 }
6760
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006761 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006762 public int getCarrierPrivilegeStatus(int subId) {
6763 final Phone phone = getPhone(subId);
6764 if (phone == null) {
6765 loge("getCarrierPrivilegeStatus: Invalid subId");
6766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6767 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006768 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6769 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006770 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6772 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006773
6774 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006775 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006776 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006777 }
Junda Liu29340342014-07-10 15:23:27 -07006778
6779 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006780 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006781 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 final Phone phone = getPhone(subId);
6783 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006784 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006785 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6786 }
6787 UiccProfile profile =
6788 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6789 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006790 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6792 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006793 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006794 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006795 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006796 }
6797
6798 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006799 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006800 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006801 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006802 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006803 }
6804
6805 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006806 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6807 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006808 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006809 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6810 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006811 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006812 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006813 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006814 }
6815
6816 @Override
6817 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006818 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006819 if (TextUtils.isEmpty(pkgName))
6820 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006821 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6822 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006823 UiccPort port = UiccController.getInstance().getUiccPort(i);
6824 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006825 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006826 continue;
6827 }
6828
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006829 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006830 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006831 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006832 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6833 break;
6834 }
6835 }
6836
6837 return result;
Junda Liu29340342014-07-10 15:23:27 -07006838 }
Derek Tan89e89d42014-07-08 17:00:10 -07006839
6840 @Override
Junda Liue64de782015-04-16 17:19:16 -07006841 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006842 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006843 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6844 loge("phoneId " + phoneId + " is not valid.");
6845 return null;
6846 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006847 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6848 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006849 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006850 return null ;
6851 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006852 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006853 }
6854
Amith Yamasani6e118872016-02-19 12:53:51 -08006855 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006856 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006857 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006858 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006859 List<String> privilegedPackages = new ArrayList<>();
6860 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006861 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006862 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006863 if (port != null) {
6864 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006865 if (packages == null) {
6866 // Only check packages in user 0 for now
6867 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006868 PackageManager.MATCH_DISABLED_COMPONENTS
6869 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006870 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006871 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006872 }
6873 for (int p = packages.size() - 1; p >= 0; p--) {
6874 PackageInfo pkgInfo = packages.get(p);
6875 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006876 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006877 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006878 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006879 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006880 privilegedPackages.add(pkgInfo.packageName);
6881 }
6882 }
6883 }
6884 }
6885 return privilegedPackages;
6886 }
6887
chen xuf7e9fe82019-05-09 19:31:02 -07006888 @Override
6889 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006890 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6891
6892 final long identity = Binder.clearCallingIdentity();
6893
chen xuf7e9fe82019-05-09 19:31:02 -07006894 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006895 try {
6896 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6897 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6898 }
6899 } finally {
6900 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006901 }
6902 return privilegedPackages;
6903 }
6904
Wink Savilleb564aae2014-10-23 10:18:09 -07006905 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006906 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006907 UiccPort port = phone == null ? null : phone.getUiccPort();
6908 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006909 return null;
6910 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006911 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006912 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006913 return null;
6914 }
6915 return iccId;
6916 }
6917
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006918 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006919 public void setCallComposerStatus(int subId, int status) {
6920 enforceModifyPermission();
6921
6922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 Phone phone = getPhone(subId);
6925 if (phone != null) {
6926 Phone defaultPhone = phone.getImsPhone();
6927 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6928 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6929 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006930 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6931 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006932 }
6933 }
Shuo Qian284ae752020-12-22 19:10:14 -08006934 } catch (ImsException e) {
6935 throw new ServiceSpecificException(e.getCode());
6936 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006937 Binder.restoreCallingIdentity(identity);
6938 }
6939 }
6940
6941 @Override
6942 public int getCallComposerStatus(int subId) {
6943 enforceReadPrivilegedPermission("getCallComposerStatus");
6944
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
6947 Phone phone = getPhone(subId);
6948 if (phone != null) {
6949 Phone defaultPhone = phone.getImsPhone();
6950 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6951 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6952 return imsPhone.getCallComposerStatus();
6953 }
6954 }
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
6958 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6959 }
6960
6961 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006962 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6963 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006964 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006965 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 final String iccId = getIccId(subId);
6970 final Phone phone = getPhone(subId);
6971 if (phone == null) {
6972 return false;
6973 }
6974 final String subscriberId = phone.getSubscriberId();
6975
6976 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006977 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 + subscriberId + " to " + number);
6979 }
6980
6981 if (TextUtils.isEmpty(iccId)) {
6982 return false;
6983 }
6984
6985 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6986
6987 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6988 if (alphaTag == null) {
6989 editor.remove(alphaTagPrefKey);
6990 } else {
6991 editor.putString(alphaTagPrefKey, alphaTag);
6992 }
6993
6994 // Record both the line number and IMSI for this ICCID, since we need to
6995 // track all merged IMSIs based on line number
6996 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6997 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6998 if (number == null) {
6999 editor.remove(numberPrefKey);
7000 editor.remove(subscriberPrefKey);
7001 } else {
7002 editor.putString(numberPrefKey, number);
7003 editor.putString(subscriberPrefKey, subscriberId);
7004 }
7005
7006 editor.commit();
7007 return true;
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007010 }
Derek Tan7226c842014-07-02 17:42:23 -07007011 }
7012
7013 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007014 public String getLine1NumberForDisplay(int subId, String callingPackage,
7015 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007016 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007018 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007019 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007020 return null;
7021 }
Derek Tan97ebb422014-09-05 16:55:38 -07007022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 String iccId = getIccId(subId);
7026 if (iccId != null) {
7027 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7028 if (DBG_MERGE) {
7029 log("getLine1NumberForDisplay returning "
7030 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7031 }
7032 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7035 return null;
7036 } finally {
7037 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007038 }
Derek Tan7226c842014-07-02 17:42:23 -07007039 }
7040
7041 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007042 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7043 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007045 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007046 return null;
7047 }
Derek Tan97ebb422014-09-05 16:55:38 -07007048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 final long identity = Binder.clearCallingIdentity();
7050 try {
7051 String iccId = getIccId(subId);
7052 if (iccId != null) {
7053 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7054 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7055 }
7056 return null;
7057 } finally {
7058 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007059 }
Derek Tan7226c842014-07-02 17:42:23 -07007060 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007061
7062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007063 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7064 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007065 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7066 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007068 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007069 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007070 return null;
7071 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007072
Jordan Liub49b04b2019-05-06 14:45:15 -07007073 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7074 // the process, where TelephonyManager was instantiated.
7075 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007076 final long identity = Binder.clearCallingIdentity();
7077 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007078 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 final TelephonyManager tele = TelephonyManager.from(context);
7080 final SubscriptionManager sub = SubscriptionManager.from(context);
7081
7082 // Figure out what subscribers are currently active
7083 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084
Jordan Liub49b04b2019-05-06 14:45:15 -07007085 // Only consider subs which match the current subId
7086 // This logic can be simplified. See b/131189269 for progress.
7087 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007088 activeSubscriberIds.add(tele.getSubscriberId(subId));
7089 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090
7091 // First pass, find a number override for an active subscriber
7092 String mergeNumber = null;
7093 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7094 for (String key : prefs.keySet()) {
7095 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7096 final String subscriberId = (String) prefs.get(key);
7097 if (activeSubscriberIds.contains(subscriberId)) {
7098 final String iccId = key.substring(
7099 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7100 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7101 mergeNumber = (String) prefs.get(numberKey);
7102 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007103 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 + " for active subscriber " + subscriberId);
7105 }
7106 if (!TextUtils.isEmpty(mergeNumber)) {
7107 break;
7108 }
7109 }
7110 }
7111 }
7112
7113 // Shortcut when no active merged subscribers
7114 if (TextUtils.isEmpty(mergeNumber)) {
7115 return null;
7116 }
7117
7118 // Second pass, find all subscribers under that line override
7119 final ArraySet<String> result = new ArraySet<>();
7120 for (String key : prefs.keySet()) {
7121 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7122 final String number = (String) prefs.get(key);
7123 if (mergeNumber.equals(number)) {
7124 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7125 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7126 final String subscriberId = (String) prefs.get(subscriberKey);
7127 if (!TextUtils.isEmpty(subscriberId)) {
7128 result.add(subscriberId);
7129 }
7130 }
7131 }
7132 }
7133
7134 final String[] resultArray = result.toArray(new String[result.size()]);
7135 Arrays.sort(resultArray);
7136 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007137 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7139 }
7140 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007141 } finally {
7142 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007143 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007144 }
7145
7146 @Override
zoey chen38003472019-12-13 17:16:31 +08007147 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7148 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007149
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 final TelephonyManager telephonyManager = mApp.getSystemService(
7153 TelephonyManager.class);
7154 String subscriberId = telephonyManager.getSubscriberId(subId);
7155 if (subscriberId == null) {
7156 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007157 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007158 + subId);
7159 }
7160 return null;
7161 }
7162
7163 final SubscriptionInfo info = SubscriptionController.getInstance()
7164 .getSubscriptionInfo(subId);
7165 final ParcelUuid groupUuid = info.getGroupUuid();
7166 // If it doesn't belong to any group, return just subscriberId of itself.
7167 if (groupUuid == null) {
7168 return new String[]{subscriberId};
7169 }
7170
7171 // Get all subscriberIds from the group.
7172 final List<String> mergedSubscriberIds = new ArrayList<>();
7173 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007174 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007175 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007176 for (SubscriptionInfo subInfo : groupInfos) {
7177 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7178 if (subscriberId != null) {
7179 mergedSubscriberIds.add(subscriberId);
7180 }
7181 }
7182
7183 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186
7187 }
7188 }
7189
7190 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007191 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007192 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007193 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194
7195 final long identity = Binder.clearCallingIdentity();
7196 try {
7197 final Phone phone = getPhone(subId);
7198 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7199 } finally {
7200 Binder.restoreCallingIdentity(identity);
7201 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007202 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007203
7204 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007205 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007206 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7207 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007208 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7209 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210
7211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 final Phone phone = getPhone(subId);
7214 if (phone == null) {
7215 return false;
7216 }
7217 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7218 cdmaNonRoamingList);
7219 } finally {
7220 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007221 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007222 }
7223
7224 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007225 @Deprecated
7226 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7227 enforceModifyPermission();
7228
7229 int returnValue = 0;
7230 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007231 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007232 if(result.exception == null) {
7233 if (result.result != null) {
7234 byte[] responseData = (byte[])(result.result);
7235 if(responseData.length > oemResp.length) {
7236 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7237 responseData.length + "bytes. Buffer Size is " +
7238 oemResp.length + "bytes.");
7239 }
7240 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7241 returnValue = responseData.length;
7242 }
7243 } else {
7244 CommandException ex = (CommandException) result.exception;
7245 returnValue = ex.getCommandError().ordinal();
7246 if(returnValue > 0) returnValue *= -1;
7247 }
7248 } catch (RuntimeException e) {
7249 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7250 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7251 if(returnValue > 0) returnValue *= -1;
7252 }
7253
7254 return returnValue;
7255 }
7256
7257 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007258 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007259 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007260 try {
7261 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007262 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007263 mApp, phone.getSubId(), "getRadioAccessFamily");
7264 } catch (SecurityException e) {
7265 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7266 throw e;
7267 }
chen xub97461a2018-10-26 14:17:57 -07007268 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007269 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007270 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 final long identity = Binder.clearCallingIdentity();
7273 try {
chen xub97461a2018-10-26 14:17:57 -07007274 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007275 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007276 mApp, phone.getSubId(), "getRadioAccessFamily");
7277 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
chen xub97461a2018-10-26 14:17:57 -07007281 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007282 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007283
7284 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007285 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007286 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007287 try {
7288 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7289 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007290 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007291 }
7292 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007293 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007294 }
7295 RoleManager rm = mApp.getSystemService(RoleManager.class);
7296 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7297 if (!dialerRoleHolders.contains(callingPackage)) {
7298 throw new SecurityException("App must be the dialer role holder to"
7299 + " upload a call composer pic");
7300 }
7301
7302 Executors.newSingleThreadExecutor().execute(() -> {
7303 ByteArrayOutputStream output = new ByteArrayOutputStream(
7304 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7305 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7306 boolean readUntilEnd = false;
7307 int totalBytesRead = 0;
7308 byte[] buffer = new byte[16 * 1024];
7309 while (true) {
7310 int numRead;
7311 try {
7312 numRead = input.read(buffer);
7313 } catch (IOException e) {
7314 try {
7315 fd.checkError();
7316 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7317 null);
7318 } catch (IOException e1) {
7319 // This means that the other side closed explicitly with an error. If this
7320 // happens, log and ignore.
7321 loge("Remote end of call composer picture pipe closed: " + e1);
7322 }
7323 break;
7324 }
7325 if (numRead == -1) {
7326 readUntilEnd = true;
7327 break;
7328 }
7329 totalBytesRead += numRead;
7330 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7331 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7332 try {
7333 input.close();
7334 } catch (IOException e) {
7335 // ignore
7336 }
7337 break;
7338 }
7339 output.write(buffer, 0, numRead);
7340 }
7341 // Generally, the remote end will close the file descriptors. The only case where we
7342 // close is above, where the picture size is too big.
7343
7344 try {
7345 fd.checkError();
7346 } catch (IOException e) {
7347 loge("Remote end for call composer closed with an error: " + e);
7348 return;
7349 }
7350
Hall Liuaa4211e2021-01-20 15:43:39 -08007351 if (!readUntilEnd) {
7352 loge("Did not finish reading entire image; aborting");
7353 return;
7354 }
Hall Liu82694d52020-12-11 18:22:04 -08007355
Hall Liuaa4211e2021-01-20 15:43:39 -08007356 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7357 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7358 new CallComposerPictureTransfer.Factory() {},
7359 imageData,
7360 (result) -> {
7361 if (result.first != null) {
7362 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7363 Bundle outputResult = new Bundle();
7364 outputResult.putParcelable(
7365 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7366 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7367 outputResult);
7368 } else {
7369 callback.send(result.second, null);
7370 }
7371 }
7372 );
Hall Liu82694d52020-12-11 18:22:04 -08007373 });
7374 }
7375
7376 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007377 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007378 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007379 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380
7381 final long identity = Binder.clearCallingIdentity();
7382 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007383 ImsManager.getInstance(defaultPhone.getContext(),
7384 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 } finally {
7386 Binder.restoreCallingIdentity(identity);
7387 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007388 }
7389
7390 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007391 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007392 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7394 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007395 return false;
7396 }
Svet Ganovb320e182015-04-16 12:30:10 -07007397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 final long identity = Binder.clearCallingIdentity();
7399 try {
7400 // Check the user preference and the system-level IMS setting. Even if the user has
7401 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7402 // In the long run, we may instead need to check if there exists a connection service
7403 // which can support video calling.
7404 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007405 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 return imsManager.isVtEnabledByPlatform()
7407 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7408 && imsManager.isVtEnabledByUser();
7409 } finally {
7410 Binder.restoreCallingIdentity(identity);
7411 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007412 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007413
Andrew Leea1239f22015-03-02 17:44:07 -08007414 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007415 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7416 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,
7419 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 return false;
7421 }
7422
7423 final long identity = Binder.clearCallingIdentity();
7424 try {
7425 CarrierConfigManager configManager =
7426 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
7431 }
Andrew Leea1239f22015-03-02 17:44:07 -08007432 }
7433
7434 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007435 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007437 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 return false;
7439 }
7440
7441 final long identity = Binder.clearCallingIdentity();
7442 try {
7443 CarrierConfigManager configManager =
7444 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
Andrew Leea1239f22015-03-02 17:44:07 -08007450 }
7451
Andrew Lee9431b832015-03-09 18:46:45 -07007452 @Override
7453 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007454 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007455 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007456 }
7457
7458 @Override
7459 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 final long identity = Binder.clearCallingIdentity();
7461 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007462 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 } finally {
7464 Binder.restoreCallingIdentity(identity);
7465 }
Andrew Lee9431b832015-03-09 18:46:45 -07007466 }
7467
Hall Liuf6668912018-10-31 17:05:23 -07007468 /**
7469 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7470 * support for the feature and device firmware support.
7471 *
7472 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7473 */
7474 @Override
7475 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007477 final Phone phone = getPhone(subscriptionId);
7478 if (phone == null) {
7479 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7480 return false;
7481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007483 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7485 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007486 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 return isCarrierSupported && isDeviceSupported;
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Hall Liu98187582018-01-22 19:15:32 -08007491 }
7492
Hall Liuf6668912018-10-31 17:05:23 -07007493 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007494 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7495 * RTT setting, will return true if the device and carrier both support RTT.
7496 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007497 */
7498 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 final long identity = Binder.clearCallingIdentity();
7500 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007501 boolean isRttSupported = isRttSupported(subscriptionId);
7502 boolean isUserRttSettingOn = Settings.Secure.getInt(
7503 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7504 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7505 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7506 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007510 }
7511
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007512 @Deprecated
7513 @Override
7514 public String getDeviceId(String callingPackage) {
7515 return getDeviceIdWithFeature(callingPackage, null);
7516 }
7517
Sanket Padawe7310cc72015-01-14 09:53:20 -08007518 /**
7519 * Returns the unique device ID of phone, for example, the IMEI for
7520 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7521 *
7522 * <p>Requires Permission:
7523 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7524 */
7525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007527 try {
7528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7529 } catch (SecurityException se) {
7530 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7531 throw new SecurityException("Package " + callingPackage + " does not belong to "
7532 + Binder.getCallingUid());
7533 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007534 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007535 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007536 return null;
7537 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007538 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007539 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007540 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007541 return null;
7542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543
7544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 return phone.getDeviceId();
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007550 }
7551
Ping Sunc67b7c22016-03-02 19:16:45 +08007552 /**
7553 * {@hide}
7554 * Returns the IMS Registration Status on a particular subid
7555 *
7556 * @param subId
7557 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007558 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007559 Phone phone = getPhone(subId);
7560 if (phone != null) {
7561 return phone.isImsRegistered();
7562 } else {
7563 return false;
7564 }
7565 }
7566
Santos Cordon7a1885b2015-02-03 11:15:19 -08007567 @Override
7568 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 final long identity = Binder.clearCallingIdentity();
7570 try {
7571 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007575 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007576
Tyler Gunnf70ed162019-04-03 15:28:53 -07007577 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007578 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007579 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007581 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007582 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7583 }
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
7590 }
7591
7592 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007593 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007594 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007595 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007596 mApp,
7597 subscriptionId,
7598 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007599 final long identity = Binder.clearCallingIdentity();
7600 try {
7601 Phone phone = getPhone(subscriptionId);
7602 if (phone == null) {
7603 return null;
7604 }
7605 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7606 } finally {
7607 Binder.restoreCallingIdentity(identity);
7608 }
7609 }
7610
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007611 /**
7612 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007613 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007614 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615 final long identity = Binder.clearCallingIdentity();
7616 try {
7617 Phone phone = getPhone(subId);
7618 if (phone != null) {
7619 return phone.isWifiCallingEnabled();
7620 } else {
7621 return false;
7622 }
7623 } finally {
7624 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007625 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007626 }
7627
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007628 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007629 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007630 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007631 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632 final long identity = Binder.clearCallingIdentity();
7633 try {
7634 Phone phone = getPhone(subId);
7635 if (phone != null) {
7636 return phone.isVideoEnabled();
7637 } else {
7638 return false;
7639 }
7640 } finally {
7641 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007642 }
7643 }
7644
7645 /**
7646 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7647 * defined in {@link ImsRegistrationImplBase}.
7648 */
7649 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 Phone phone = getPhone(subId);
7653 if (phone != null) {
7654 return phone.getImsRegistrationTech();
7655 } else {
7656 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7657 }
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007660 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007661 }
7662
Stuart Scott8eef64f2015-04-08 15:13:54 -07007663 @Override
7664 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007665 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007666 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7667 return;
7668 }
Kai Shif70f46f2021-03-03 13:59:46 -08007669 Phone defaultPhone = getDefaultPhone();
7670 if (defaultPhone != null) {
7671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7672 mApp, getDefaultPhone().getSubId(), "factoryReset");
7673 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007674 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007675
Svet Ganovcc087f82015-05-12 20:35:54 -07007676 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007677 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7678 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007679 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007680 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007681 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007682 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007683 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007684 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007685 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007686 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007687 // There has been issues when Sms raw table somehow stores orphan
7688 // fragments. They lead to garbled message when new fragments come
7689 // in and combined with those stale ones. In case this happens again,
7690 // user can reset all network settings which will clean up this table.
7691 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007692 // Clean up IMS settings as well here.
7693 int slotId = getSlotIndex(subId);
7694 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7695 ImsManager.getInstance(mApp, slotId).factoryReset();
7696 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007697
Kai Shif70f46f2021-03-03 13:59:46 -08007698 if (defaultPhone == null) {
7699 return;
7700 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007701 // Erase modem config if erase modem on network setting is enabled.
7702 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7703 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7704 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007705 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007706 }
Kai Shif70f46f2021-03-03 13:59:46 -08007707
7708 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007709 } finally {
7710 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007711 }
7712 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007713
SongFerngWangfd89b102021-05-27 22:44:54 +08007714 @VisibleForTesting
7715 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7716 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7717 return;
7718 }
7719 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7720 RILConstants.PREFERRED_NETWORK_MODE);
7721 SubscriptionManager.setSubscriptionProperty(subId,
7722 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7723 "user=" + defaultNetworkType);
7724 phone.loadAllowedNetworksFromSubscriptionDatabase();
7725 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7726 defaultNetworkType, null);
7727 }
7728
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007729 private void cleanUpSmsRawTable(Context context) {
7730 ContentResolver resolver = context.getContentResolver();
7731 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7732 resolver.delete(uri, null, null);
7733 }
7734
Narayan Kamath1c496c22015-04-16 14:40:19 +01007735 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007736 public String getSimLocaleForSubscriber(int subId) {
7737 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7738 final Phone phone = getPhone(subId);
7739 if (phone == null) {
7740 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007741 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007742 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007743 final long identity = Binder.clearCallingIdentity();
7744 try {
chen xu5d3637b2019-01-21 23:31:38 -08007745 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007746 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007747 if (info == null) {
7748 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7749 return null;
7750 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 // Try and fetch the locale from the carrier properties or from the SIM language
7752 // preferences (EF-PL and EF-LI)...
7753 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007755 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7756 if (localeFromDefaultSim != null) {
7757 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7758 if (DBG) log("Using locale from subId: " + subId + " locale: "
7759 + localeFromDefaultSim);
7760 return localeFromDefaultSim.toLanguageTag();
7761 } else {
7762 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763 }
7764 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 // The SIM language preferences only store a language (e.g. fr = French), not an
7767 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7768 // the SIM and carrier preferences does not include a country we add the country
7769 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007770 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007772 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773 return mccLocale.toLanguageTag();
7774 }
7775
7776 if (DBG) log("No locale found - returning null");
7777 return null;
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
7780 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007781 }
7782
7783 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007784 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007785 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007786 }
7787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788 /**
7789 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7790 */
7791 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007792 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007793 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007794 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007795
Chenjie Yu1ba97252018-01-11 18:16:20 -08007796 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007797 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007798
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007799 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007800 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7801 * representing the state of the modem.
7802 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007803 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7804 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007805 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007806 */
7807 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007808 public void requestModemActivityInfo(ResultReceiver result) {
7809 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007810 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811
7812 final long identity = Binder.clearCallingIdentity();
7813 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007814 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 } finally {
7816 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007817 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007818 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007819
Siddharth Rayb8114062018-06-17 15:02:38 -07007820 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7821 // less than total activity duration.
7822 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7823 if (info == null) {
7824 return false;
7825 }
7826 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007827 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7828 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7829
Siddharth Rayb8114062018-06-17 15:02:38 -07007830 return (info.isValid()
7831 && (info.getSleepTimeMillis() <= activityDurationMs)
7832 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007833 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007834 && (totalTxTimeMs <= activityDurationMs));
7835 }
7836
Jack Yu85bd38a2015-11-09 11:34:32 -08007837 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007838 * Returns the service state information on specified subscription.
7839 */
7840 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007841 public ServiceState getServiceStateForSubscriber(int subId,
7842 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7843 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007845 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007846 return null;
7847 }
7848
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007849 boolean hasFinePermission = false;
7850 boolean hasCoarsePermission = false;
7851 if (!renounceFineLocationAccess) {
7852 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7853 LocationAccessPolicy.checkLocationPermission(mApp,
7854 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7855 .setCallingPackage(callingPackage)
7856 .setCallingFeatureId(callingFeatureId)
7857 .setCallingPid(Binder.getCallingPid())
7858 .setCallingUid(Binder.getCallingUid())
7859 .setMethod("getServiceStateForSubscriber")
7860 .setLogAsInfo(true)
7861 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7862 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7863 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7864 .build());
7865 hasFinePermission =
7866 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7867 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007868
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007869 if (!renounceCoarseLocationAccess) {
7870 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7871 LocationAccessPolicy.checkLocationPermission(mApp,
7872 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7873 .setCallingPackage(callingPackage)
7874 .setCallingFeatureId(callingFeatureId)
7875 .setCallingPid(Binder.getCallingPid())
7876 .setCallingUid(Binder.getCallingUid())
7877 .setMethod("getServiceStateForSubscriber")
7878 .setLogAsInfo(true)
7879 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7880 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7881 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7882 .build());
7883 hasCoarsePermission =
7884 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7885 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007886
Jack Yu479f40e2020-10-27 21:29:25 -07007887 final Phone phone = getPhone(subId);
7888 if (phone == null) {
7889 return null;
7890 }
7891
Jordan Liu0f2bc442020-11-18 16:47:37 -08007892 final long identity = Binder.clearCallingIdentity();
7893
Jack Yu479f40e2020-10-27 21:29:25 -07007894 boolean isCallingPackageDataService = phone.getDataServicePackages()
7895 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007897 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7898 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7899 Rlog.d(LOG_TAG,
7900 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7901 return null;
7902 }
7903
Hall Liuf19c44f2018-11-27 14:38:17 -08007904 ServiceState ss = phone.getServiceState();
7905
7906 // Scrub out the location info in ServiceState depending on what level of access
7907 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007908 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007909 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7910 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 } finally {
7912 Binder.restoreCallingIdentity(identity);
7913 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007914 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007915
7916 /**
7917 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7918 *
7919 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7920 * voicemail ringtone.
7921 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7922 * PhoneAccount.
7923 */
7924 @Override
7925 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 final long identity = Binder.clearCallingIdentity();
7927 try {
7928 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7929 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007930 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
7936 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007937 }
7938
7939 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007940 * Sets the per-account voicemail ringtone.
7941 *
7942 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7943 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7944 *
7945 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7946 * voicemail ringtone.
7947 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7948 * PhoneAccount.
7949 */
7950 @Override
7951 public void setVoicemailRingtoneUri(String callingPackage,
7952 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007953 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007954 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007955 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7956 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7958 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7959 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961
7962 final long identity = Binder.clearCallingIdentity();
7963 try {
7964 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7965 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007966 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 }
7968 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007971 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007972 }
7973
7974 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007975 * Returns whether vibration is set for voicemail notification in Phone settings.
7976 *
7977 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7978 * voicemail vibration setting.
7979 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7980 */
7981 @Override
7982 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983 final long identity = Binder.clearCallingIdentity();
7984 try {
7985 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7986 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007987 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007988 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7991 } finally {
7992 Binder.restoreCallingIdentity(identity);
7993 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007994 }
7995
Youhan Wange64578a2016-05-02 15:32:42 -07007996 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007997 * Sets the per-account voicemail vibration.
7998 *
7999 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8000 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8001 *
8002 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8003 * voicemail vibration setting.
8004 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8005 * specific PhoneAccount.
8006 */
8007 @Override
8008 public void setVoicemailVibrationEnabled(String callingPackage,
8009 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008010 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008011 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008012 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8013 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8015 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8016 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008017 }
8018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 final long identity = Binder.clearCallingIdentity();
8020 try {
8021 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8022 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008023 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 }
8025 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8026 } finally {
8027 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008028 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008029 }
8030
8031 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008032 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8033 *
8034 * @throws SecurityException if the caller does not have the required permission
8035 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008036 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008037 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008038 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008039 }
8040
8041 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008042 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8043 * permission.
8044 *
8045 * @throws SecurityException if the caller does not have the required permission
8046 */
8047 private void enforceSendSmsPermission() {
8048 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8049 }
8050
8051 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008052 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008053 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008054 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008055 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008056 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008057 final long identity = Binder.clearCallingIdentity();
8058 try {
8059 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008060 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 if (componentName == null) {
8062 throw new SecurityException(
8063 "Caller not current active visual voicemail package[null]");
8064 }
8065 String vvmPackage = componentName.getPackageName();
8066 if (!callingPackage.equals(vvmPackage)) {
8067 throw new SecurityException("Caller not current active visual voicemail package["
8068 + vvmPackage + "]");
8069 }
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008072 }
8073 }
8074
8075 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008076 * Return the application ID for the app type.
8077 *
8078 * @param subId the subscription ID that this request applies to.
8079 * @param appType the uicc app type.
8080 * @return Application ID for specificied app type, or null if no uicc.
8081 */
8082 @Override
8083 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008084 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008085 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086
8087 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008088 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008089 if (phone == null) {
8090 return null;
8091 }
8092 String aid = null;
8093 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008094 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008095 .getApplicationByType(appType).getAid();
8096 } catch (Exception e) {
8097 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8098 }
8099 return aid;
8100 } finally {
8101 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008102 }
Youhan Wange64578a2016-05-02 15:32:42 -07008103 }
8104
Youhan Wang4001d252016-05-11 10:29:41 -07008105 /**
8106 * Return the Electronic Serial Number.
8107 *
8108 * @param subId the subscription ID that this request applies to.
8109 * @return ESN or null if error.
8110 */
8111 @Override
8112 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008113 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008114 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115
8116 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008117 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 if (phone == null) {
8119 return null;
8120 }
8121 String esn = null;
8122 try {
8123 esn = phone.getEsn();
8124 } catch (Exception e) {
8125 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8126 }
8127 return esn;
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008130 }
Youhan Wang4001d252016-05-11 10:29:41 -07008131 }
8132
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008133 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008134 * Return the Preferred Roaming List Version.
8135 *
8136 * @param subId the subscription ID that this request applies to.
8137 * @return PRLVersion or null if error.
8138 */
8139 @Override
8140 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008141 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008142 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008143
8144 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008145 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008146 if (phone == null) {
8147 return null;
8148 }
8149 String cdmaPrlVersion = null;
8150 try {
8151 cdmaPrlVersion = phone.getCdmaPrlVersion();
8152 } catch (Exception e) {
8153 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8154 }
8155 return cdmaPrlVersion;
8156 } finally {
8157 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008158 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008159 }
8160
8161 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008162 * Get snapshot of Telephony histograms
8163 * @return List of Telephony histograms
8164 * @hide
8165 */
8166 @Override
8167 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8169 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170
8171 final long identity = Binder.clearCallingIdentity();
8172 try {
8173 return RIL.getTelephonyRILTimingHistograms();
8174 } finally {
8175 Binder.restoreCallingIdentity(identity);
8176 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008177 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008178
8179 /**
8180 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008181 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8182 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008183 * Require system privileges. In the future we may add this to carrier APIs.
8184 *
Michele Berionne482f8202018-11-27 18:57:59 -08008185 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008186 */
8187 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008188 @TelephonyManager.SetCarrierRestrictionResult
8189 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008190 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008191 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008192
Michele Berionne482f8202018-11-27 18:57:59 -08008193 if (carrierRestrictionRules == null) {
8194 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008195 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008197 final long identity = Binder.clearCallingIdentity();
8198 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008199 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008200 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201 } finally {
8202 Binder.restoreCallingIdentity(identity);
8203 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008204 }
8205
8206 /**
8207 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008208 * Get the allowed carrier list and the excluded carrier list, including the priority between
8209 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008210 * Require system privileges. In the future we may add this to carrier APIs.
8211 *
Michele Berionne482f8202018-11-27 18:57:59 -08008212 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008213 */
8214 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008215 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008216 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008217 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218
8219 final long identity = Binder.clearCallingIdentity();
8220 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008221 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8222 if (response instanceof CarrierRestrictionRules) {
8223 return (CarrierRestrictionRules) response;
8224 }
8225 // Response is an Exception of some kind,
8226 // which is signalled to the user as a NULL retval
8227 return null;
8228 } catch (Exception e) {
8229 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8230 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008231 } finally {
8232 Binder.restoreCallingIdentity(identity);
8233 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008234 }
8235
fionaxu59545b42016-05-25 15:53:37 -07008236 /**
fionaxu59545b42016-05-25 15:53:37 -07008237 * Action set from carrier signalling broadcast receivers to enable/disable radio
8238 * @param subId the subscription ID that this action applies to.
8239 * @param enabled control enable or disable radio.
8240 * {@hide}
8241 */
8242 @Override
8243 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8244 enforceModifyPermission();
8245 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246
8247 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008248 if (phone == null) {
8249 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8250 return;
8251 }
8252 try {
8253 phone.carrierActionSetRadioEnabled(enabled);
8254 } catch (Exception e) {
8255 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 } finally {
8257 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008258 }
8259 }
8260
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008261 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008262 * Enable or disable Voice over NR (VoNR)
8263 * @param subId the subscription ID that this action applies to.
8264 * @param enabled enable or disable VoNR.
8265 * @return operation result.
8266 */
8267 @Override
8268 public int setVoNrEnabled(int subId, boolean enabled) {
8269 enforceModifyPermission();
8270 final Phone phone = getPhone(subId);
8271
8272 final long identity = Binder.clearCallingIdentity();
8273 if (phone == null) {
8274 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8275 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8276 }
8277
8278 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8279 try {
8280 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8281 workSource);
8282 if (DBG) log("setVoNrEnabled result: " + result);
8283 return result;
8284 } finally {
8285 Binder.restoreCallingIdentity(identity);
8286 }
8287 }
8288
8289 /**
8290 * Is voice over NR enabled
8291 * @return true if VoNR is enabled else false
8292 */
8293 @Override
8294 public boolean isVoNrEnabled(int subId) {
8295 enforceReadPrivilegedPermission("isVoNrEnabled");
8296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8297 final long identity = Binder.clearCallingIdentity();
8298 try {
8299 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8300 null, subId, workSource);
8301 if (DBG) log("isVoNrEnabled: " + isEnabled);
8302 return isEnabled;
8303 } finally {
8304 Binder.restoreCallingIdentity(identity);
8305 }
8306 }
8307
8308 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008309 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8310 * network status based on which carrier apps could apply actions accordingly,
8311 * enable/disable default url handler for example.
8312 *
8313 * @param subId the subscription ID that this action applies to.
8314 * @param report control start/stop reporting the default network status.
8315 * {@hide}
8316 */
8317 @Override
8318 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8319 enforceModifyPermission();
8320 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321
8322 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008323 if (phone == null) {
8324 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8325 return;
8326 }
8327 try {
8328 phone.carrierActionReportDefaultNetworkStatus(report);
8329 } catch (Exception e) {
8330 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 } finally {
8332 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008333 }
8334 }
8335
8336 /**
fionaxud9622282017-07-17 17:51:30 -07008337 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8338 * @param subId the subscription ID that this action applies to.
8339 * {@hide}
8340 */
8341 @Override
8342 public void carrierActionResetAll(int subId) {
8343 enforceModifyPermission();
8344 final Phone phone = getPhone(subId);
8345 if (phone == null) {
8346 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8347 return;
8348 }
8349 try {
8350 phone.carrierActionResetAll();
8351 } catch (Exception e) {
8352 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8353 }
8354 }
8355
8356 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008357 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8358 * bug report is being generated.
8359 */
8360 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008361 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008362 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8363 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008364 writer.println("Permission Denial: can't dump Phone from pid="
8365 + Binder.getCallingPid()
8366 + ", uid=" + Binder.getCallingUid()
8367 + "without permission "
8368 + android.Manifest.permission.DUMP);
8369 return;
8370 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008371 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008372 }
Jack Yueb89b242016-06-22 13:27:47 -07008373
Brad Ebingerdac2f002018-04-03 15:17:52 -07008374 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008375 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8376 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8377 @NonNull String[] args) {
8378 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8379 this, in.getFileDescriptor(), out.getFileDescriptor(),
8380 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008381 }
8382
Jack Yueb89b242016-06-22 13:27:47 -07008383 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008384 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008385 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008386 * @param reason the reason the data enable change is taking place
8387 * @param enabled True if enabling the data, otherwise disabling.
8388 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008389 */
8390 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008391 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008392 boolean enabled) {
8393 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8394 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8395 try {
8396 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008397 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008398 } catch (SecurityException se) {
8399 enforceModifyPermission();
8400 }
8401 } else {
8402 enforceModifyPermission();
8403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008404
8405 final long identity = Binder.clearCallingIdentity();
8406 try {
8407 Phone phone = getPhone(subId);
8408 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008409 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8410 phone.carrierActionSetMeteredApnsEnabled(enabled);
8411 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08008412 if (phone.isUsingNewDataStack()) {
8413 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8414 } else {
8415 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8416 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008418 }
8419 } finally {
8420 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008421 }
8422 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008423
8424 /**
8425 * Get Client request stats
8426 * @return List of Client Request Stats
8427 * @hide
8428 */
8429 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008430 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8431 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008433 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008434 return null;
8435 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008436 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 if (phone != null) {
8441 return phone.getClientRequestStats();
8442 }
8443
8444 return null;
8445 } finally {
8446 Binder.restoreCallingIdentity(identity);
8447 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008448 }
8449
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008450 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008451 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008452 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008453 }
Jack Yueb4124c2017-02-16 15:32:43 -08008454
8455 /**
Grace Chen70990072017-03-24 17:21:30 -07008456 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008457 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008458 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008459 * @param state State of SIM (power down, power up, pass through)
8460 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8461 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8462 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008463 *
8464 **/
8465 @Override
Grace Chen70990072017-03-24 17:21:30 -07008466 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008467 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008468 Phone phone = PhoneFactory.getPhone(slotIndex);
8469
vagdeviaf9a5b92018-08-15 16:01:53 -07008470 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008475 phone.setSimPowerState(state, null, workSource);
8476 }
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
8479 }
8480 }
8481
8482 /**
8483 * Set SIM card power state.
8484 *
8485 * @param slotIndex SIM slot id.
8486 * @param state State of SIM (power down, power up, pass through)
8487 * @param callback callback to trigger after success or failure
8488 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8489 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8490 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8491 *
8492 **/
8493 @Override
8494 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8495 IIntegerConsumer callback) {
8496 enforceModifyPermission();
8497 Phone phone = PhoneFactory.getPhone(slotIndex);
8498
8499 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8500
8501 final long identity = Binder.clearCallingIdentity();
8502 try {
8503 if (phone != null) {
8504 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8505 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008506 }
8507 } finally {
8508 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008509 }
8510 }
Shuo Qiandd210312017-04-12 22:11:33 +00008511
Tyler Gunn65d45c22017-06-05 11:22:26 -07008512 private boolean isUssdApiAllowed(int subId) {
8513 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008514 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008515 if (configManager == null) {
8516 return false;
8517 }
8518 PersistableBundle pb = configManager.getConfigForSubId(subId);
8519 if (pb == null) {
8520 return false;
8521 }
8522 return pb.getBoolean(
8523 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8524 }
8525
Shuo Qiandd210312017-04-12 22:11:33 +00008526 /**
8527 * Check if phone is in emergency callback mode
8528 * @return true if phone is in emergency callback mode
8529 * @param subId sub id
8530 */
goneil9c5f4872017-12-05 14:07:56 -08008531 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008532 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008533 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008534 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008535
8536 final long identity = Binder.clearCallingIdentity();
8537 try {
8538 if (phone != null) {
8539 return phone.isInEcm();
8540 } else {
8541 return false;
8542 }
8543 } finally {
8544 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008545 }
8546 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008547
8548 /**
8549 * Get the current signal strength information for the given subscription.
8550 * Because this information is not updated when the device is in a low power state
8551 * it should not be relied-upon to be current.
8552 * @param subId Subscription index
8553 * @return the most recent cached signal strength info from the modem
8554 */
8555 @Override
8556 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008557 final long identity = Binder.clearCallingIdentity();
8558 try {
8559 Phone p = getPhone(subId);
8560 if (p == null) {
8561 return null;
8562 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008564 return p.getSignalStrength();
8565 } finally {
8566 Binder.restoreCallingIdentity(identity);
8567 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008568 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008569
Pengquan Meng77b7f132018-08-22 14:49:57 -07008570 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008571 * Get the current modem radio state for the given slot.
8572 * @param slotIndex slot index.
8573 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008574 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008575 * @return the current radio power state from the modem
8576 */
8577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008578 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008579 Phone phone = PhoneFactory.getPhone(slotIndex);
8580 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8582 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008583 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8584 }
8585
8586 final long identity = Binder.clearCallingIdentity();
8587 try {
8588 return phone.getRadioPowerState();
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
8591 }
8592 }
8593 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8594 }
8595
8596 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008597 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8598 *
8599 * <p>Requires one of the following permissions:
8600 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008601 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008602 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8603 * privileges.
8604 *
8605 * @param subId subscription id
8606 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8607 * {@code false}.
8608 */
8609 @Override
8610 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008611 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008612 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008613 try {
8614 mApp.enforceCallingOrSelfPermission(
8615 android.Manifest.permission.ACCESS_NETWORK_STATE,
8616 functionName);
8617 } catch (Exception e) {
8618 mApp.enforceCallingOrSelfPermission(
8619 permission.READ_BASIC_PHONE_STATE, functionName);
8620 }
Shuo Qian093013d2020-08-13 15:42:55 -07008621 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008622 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008623 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008624 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008625
Pengquan Menga1bb6272018-09-06 09:59:22 -07008626 boolean isEnabled = false;
8627 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008628 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008629 Phone phone = getPhone(subId);
8630 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008631 } finally {
8632 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008633 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008634 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008635 }
8636
8637
8638 /**
8639 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8640 *
8641 * <p> Requires permission:
8642 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8643 * privileges.
8644 *
8645 * @param subId subscription id
8646 * @param isEnabled {@code true} means enable, {@code false} means disable.
8647 */
8648 @Override
8649 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8651 mApp, subId, "setDataRoamingEnabled");
8652
Pengquan Menga1bb6272018-09-06 09:59:22 -07008653 final long identity = Binder.clearCallingIdentity();
8654 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008655 Phone phone = getPhone(subId);
8656 if (phone != null) {
8657 phone.setDataRoamingEnabled(isEnabled);
8658 }
8659 } finally {
8660 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008661 }
8662 }
8663
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008664 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008665 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008666 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008667 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008668 mApp, subId, "isManualNetworkSelectionAllowed");
8669
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008670 boolean isAllowed = true;
8671 final long identity = Binder.clearCallingIdentity();
8672 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008673 Phone phone = getPhone(subId);
8674 if (phone != null) {
8675 isAllowed = phone.isCspPlmnEnabled();
8676 }
8677 } finally {
8678 Binder.restoreCallingIdentity(identity);
8679 }
8680 return isAllowed;
8681 }
8682
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008683 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8684 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8685 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8686 // Update each UiccPort object based on privilege access
8687 UiccPort[] uiccPorts = card.getUiccPortList();
8688 for (UiccPort port : uiccPorts) {
8689 UiccProfile profile = port.getUiccProfile();
8690 if (profile == null ||
8691 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8692 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8693 return false;
8694 }
8695 }
8696 return true;
8697 }
8698
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008699 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008700 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008701 // Verify that tha callingPackage belongs to the calling UID
8702 mApp.getSystemService(AppOpsManager.class)
8703 .checkPackage(Binder.getCallingUid(), callingPackage);
8704
Jordan Liu1e142fc2019-04-22 15:10:43 -07008705 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008706 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008707 try {
8708 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008709 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008710 } catch (SecurityException e) {
8711 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8712 // has carrier privileges on an active UICC
8713 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8714 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008715 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008716 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008717 }
sandeepjs0a502c42021-09-27 15:34:44 +00008718 // checking compatibility, if calling app's target SDK is T and beyond.
8719 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8720 Binder.getCallingUid())) {
8721 isIccIdAccessRestricted = true;
8722 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008723 final long identity = Binder.clearCallingIdentity();
8724 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008725 UiccController uiccController = UiccController.getInstance();
8726 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008727 if (hasReadPermission) {
8728 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008729 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008730
8731 // Remove private info if the caller doesn't have access
8732 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8733 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008734 //setting the value after compatibility check
8735 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008736 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8737 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008738 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008739 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8740 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8741 if (card == null || card.getUiccPortList().length == 0) {
8742 // assume no access if the card or ports are unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008743 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008744 continue;
8745 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008746
8747 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008748 filteredInfos.add(cardInfo);
8749 } else {
sandeepjs0a502c42021-09-27 15:34:44 +00008750 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008751 }
8752 }
8753 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 }
8758
sandeepjs0a502c42021-09-27 15:34:44 +00008759 /**
8760 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8761 * generally private and require carrier privileges to view.
8762 *
8763 * @hide
8764 */
8765 @NonNull
8766 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8767 List<UiccPortInfo> portinfo = new ArrayList<>();
8768 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8769 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8770 }
8771 return new UiccCardInfo(
8772 cardInfo.isEuicc(),
8773 cardInfo.getCardId(),
8774 null,
8775 cardInfo.getPhysicalSlotIndex(),
8776 cardInfo.isRemovable(),
8777 cardInfo.isMultipleEnabledProfilesSupported(),
8778 portinfo
8779 );
8780 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008781
sandeepjs0a502c42021-09-27 15:34:44 +00008782 /**
8783 * @hide
8784 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8785 * These values are generally private and require carrier privileges to view.
8786 */
8787 @NonNull
8788 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8789 return new UiccPortInfo(
8790 UiccPortInfo.ICCID_REDACTED,
8791 portInfo.getPortIndex(),
8792 portInfo.getLogicalSlotIndex(),
8793 portInfo.isActive()
8794 );
8795 }
8796 @Override
8797 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
8798 // Verify that tha callingPackage belongs to the calling UID
8799 mApp.getSystemService(AppOpsManager.class)
8800 .checkPackage(Binder.getCallingUid(), callingPackage);
8801
8802 boolean hasReadPermission = false;
8803 boolean isLogicalSlotAccessRestricted = false;
8804 String iccId;
8805
8806 try {
8807 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8808 hasReadPermission = true;
8809 } catch (SecurityException e) {
8810 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8811 // has carrier privileges on an active UICC
8812 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8813 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8814 hasReadPermission = true;
8815 }
8816 }
8817
8818 // checking compatibility, if calling app's target SDK is T and beyond.
8819 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8820 Binder.getCallingUid())) {
8821 isLogicalSlotAccessRestricted = true;
8822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008823 final long identity = Binder.clearCallingIdentity();
8824 try {
8825 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8826 if (slots == null) {
8827 Rlog.i(LOG_TAG, "slots is null.");
8828 return null;
8829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008830 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8831 for (int i = 0; i < slots.length; i++) {
8832 UiccSlot slot = slots[i];
8833 if (slot == null) {
8834 continue;
8835 }
8836
Jordan Liu7be7e652019-05-06 18:55:02 +00008837 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008838 UiccCard card = slot.getUiccCard();
sandeepjs0a502c42021-09-27 15:34:44 +00008839 //if has read permission
8840 if (hasReadPermission) {
8841 iccId = slot.getIccId();
8842 } else {
8843 // if no read permission checking carrier
8844 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
8845 iccId = slot.getIccId();
8846 } else {
8847 //if no carrier permission redact ICCID
8848 iccId = IccUtils.TEST_ICCID;
8849 }
8850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008851 if (card != null) {
8852 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008853 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008854 cardId = slot.getEid();
8855 if (TextUtils.isEmpty(cardId)) {
sandeepjs0a502c42021-09-27 15:34:44 +00008856 cardId = iccId;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008858 }
8859
Jordan Liu857451f2019-05-09 16:35:35 -07008860 if (cardId != null) {
8861 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8862 // if cardId is an EID, it's all digits so this is fine
8863 cardId = IccUtils.stripTrailingFs(cardId);
8864 }
8865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008866 int cardState = 0;
8867 switch (slot.getCardState()) {
8868 case CARDSTATE_ABSENT:
8869 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8870 break;
8871 case CARDSTATE_PRESENT:
8872 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8873 break;
8874 case CARDSTATE_ERROR:
8875 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8876 break;
8877 case CARDSTATE_RESTRICTED:
8878 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8879 break;
8880 default:
8881 break;
8882
8883 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008884 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008885 slot.isEuicc(),
8886 cardId,
8887 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008888 slot.isExtendedApduSupported(),
sandeepjs0a502c42021-09-27 15:34:44 +00008889 slot.isRemovable(), Collections.singletonList(
8890 new UiccPortInfo(
8891 iccId,
8892 0 /* TODO: to use portList from UiccSlots */,
8893 slot.getPhoneId(),
8894 slot.isActive())));
8895 //setting the value after compatibility check
8896 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008897 }
8898 return infos;
8899 } finally {
8900 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008901 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008902 }
8903
8904 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008905 @Deprecated
8906 //TODO : once integrating with HAL Changes we can clean up this Internal API.
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008907 public boolean switchSlots(int[] physicalSlots) {
8908 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008909
8910 final long identity = Binder.clearCallingIdentity();
8911 try {
8912 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8913 } finally {
8914 Binder.restoreCallingIdentity(identity);
8915 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008916 }
Jack Yu4c988042018-02-27 15:30:01 -08008917
8918 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008919 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8920 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8921 enforceModifyPermission();
8922
8923 final long identity = Binder.clearCallingIdentity();
8924 try {
8925 //TODO: once integrating the HAL changes we can proceed with to work on the parsing side
8926 int[] physicalSlots = new int[slotMapping.size()];
8927 for (int i = 0; i < physicalSlots.length; i++) {
8928 physicalSlots[i] = slotMapping.get(i).getPhysicalSlotIndex();
8929 }
8930 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8931 } finally {
8932 Binder.restoreCallingIdentity(identity);
8933 }
8934 }
8935
8936 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008937 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008938 final long identity = Binder.clearCallingIdentity();
8939 try {
8940 return UiccController.getInstance().getCardIdForDefaultEuicc();
8941 } finally {
8942 Binder.restoreCallingIdentity(identity);
8943 }
8944 }
8945
Pengquan Meng85728fb2018-03-12 16:31:21 -07008946 /**
goneil47ffb6e2018-04-06 15:40:58 -07008947 * A test API to reload the UICC profile.
8948 *
8949 * <p>Requires that the calling app has permission
8950 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8951 * @hide
8952 */
8953 @Override
8954 public void refreshUiccProfile(int subId) {
8955 enforceModifyPermission();
8956
8957 final long identity = Binder.clearCallingIdentity();
8958 try {
8959 Phone phone = getPhone(subId);
8960 if (phone == null) {
8961 return;
8962 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008963 UiccPort uiccPort = phone.getUiccPort();
8964 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008965 return;
8966 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008967 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008968 if (uiccProfile == null) {
8969 return;
8970 }
8971 uiccProfile.refresh();
8972 } finally {
8973 Binder.restoreCallingIdentity(identity);
8974 }
8975 }
8976
8977 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008978 * Returns false if the mobile data is disabled by default, otherwise return true.
8979 */
8980 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008981 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008982 }
8983
8984 /**
8985 * Returns true if the data roaming is enabled by default, i.e the system property
8986 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8987 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8988 */
8989 private boolean getDefaultDataRoamingEnabled(int subId) {
8990 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008991 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008992 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008993 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8994 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8995 return isDataRoamingEnabled;
8996 }
8997
8998 /**
8999 * Returns the default network type for the given {@code subId}, if the default network type is
9000 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9001 */
9002 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009003 List<Integer> list = TelephonyProperties.default_network();
9004 int phoneId = mSubscriptionController.getPhoneId(subId);
9005 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9006 return list.get(phoneId);
9007 }
9008 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009009 }
fionaxua13278b2018-03-21 00:08:13 -07009010
9011 @Override
9012 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009013 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009014 enforceModifyPermission();
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("setCarrierTestOverride fails with invalid subId: " + subId);
9021 return;
9022 }
chen xueaba88a2019-03-15 13:15:10 -07009023 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9024 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009025 if (carrierPrivilegeRules == null) {
9026 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9027 } else {
9028 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009030 } finally {
9031 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009032 }
fionaxua13278b2018-03-21 00:08:13 -07009033 }
9034
9035 @Override
9036 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009037 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038
9039 final long identity = Binder.clearCallingIdentity();
9040 try {
9041 final Phone phone = getPhone(subId);
9042 if (phone == null) {
9043 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9044 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9045 }
9046 return phone.getCarrierIdListVersion();
9047 } finally {
9048 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009049 }
fionaxua13278b2018-03-21 00:08:13 -07009050 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009051
9052 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009053 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9054 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009056 mApp, subId, callingPackage, callingFeatureId,
9057 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009058 return -1;
9059 }
9060
9061 final long identity = Binder.clearCallingIdentity();
9062 try {
9063 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9064 } finally {
9065 Binder.restoreCallingIdentity(identity);
9066 }
9067 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009068
9069 @Override
9070 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009071 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009072 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009073 mApp, subId, "getCdmaRoamingMode");
9074
9075 final long identity = Binder.clearCallingIdentity();
9076 try {
9077 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9078 } finally {
9079 Binder.restoreCallingIdentity(identity);
9080 }
9081 }
9082
9083 @Override
9084 public boolean setCdmaRoamingMode(int subId, int mode) {
9085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9086 mApp, subId, "setCdmaRoamingMode");
9087
9088 final long identity = Binder.clearCallingIdentity();
9089 try {
9090 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9091 } finally {
9092 Binder.restoreCallingIdentity(identity);
9093 }
9094 }
9095
9096 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009097 public int getCdmaSubscriptionMode(int subId) {
9098 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009099 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009100 mApp, subId, "getCdmaSubscriptionMode");
9101
9102 final long identity = Binder.clearCallingIdentity();
9103 try {
9104 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9105 } finally {
9106 Binder.restoreCallingIdentity(identity);
9107 }
9108 }
9109
9110 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009111 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9113 mApp, subId, "setCdmaSubscriptionMode");
9114
9115 final long identity = Binder.clearCallingIdentity();
9116 try {
9117 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9118 } finally {
9119 Binder.restoreCallingIdentity(identity);
9120 }
9121 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009122
sqianc5eccab2018-10-19 18:46:41 -07009123 @Override
sqian8c685422019-02-22 15:55:18 -08009124 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009125 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009126 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009127 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9128 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009129 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9130 }
9131 final long identity = Binder.clearCallingIdentity();
9132 try {
sqian854d44b2018-12-12 16:48:18 -08009133 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9134 for (Phone phone: PhoneFactory.getPhones()) {
9135 if (phone.getEmergencyNumberTracker() != null
9136 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9137 emergencyNumberListInternal.put(
9138 phone.getSubId(),
9139 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9140 }
sqian11b7a0e2018-12-05 18:48:28 -08009141 }
sqian854d44b2018-12-12 16:48:18 -08009142 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009143 } finally {
9144 Binder.restoreCallingIdentity(identity);
9145 }
sqianc5eccab2018-10-19 18:46:41 -07009146 }
9147
9148 @Override
sqian8c685422019-02-22 15:55:18 -08009149 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009150 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009151 if (!exactMatch) {
9152 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009153 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009154 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009155 }
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
sqian854d44b2018-12-12 16:48:18 -08009158 for (Phone phone: PhoneFactory.getPhones()) {
9159 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009160 && phone.getEmergencyNumberTracker()
9161 .isEmergencyNumber(number, exactMatch)) {
9162 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009163 }
sqian11b7a0e2018-12-05 18:48:28 -08009164 }
9165 return false;
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
9168 }
9169 }
9170
sqianf4ca7ed2019-01-15 18:32:07 -08009171 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009172 * Start emergency callback mode for GsmCdmaPhone for testing.
9173 */
9174 @Override
9175 public void startEmergencyCallbackMode() {
9176 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9177 "startEmergencyCallbackMode");
9178 enforceModifyPermission();
9179 final long identity = Binder.clearCallingIdentity();
9180 try {
9181 for (Phone phone : PhoneFactory.getPhones()) {
9182 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9183 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9184 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9185 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9186 gsmCdmaPhone.obtainMessage(
9187 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9188 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9189 }
9190 }
9191 } finally {
9192 Binder.restoreCallingIdentity(identity);
9193 }
9194 }
9195
9196 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009197 * Update emergency number list for test mode.
9198 */
9199 @Override
9200 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9201 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9202 "updateEmergencyNumberListTestMode");
9203
9204 final long identity = Binder.clearCallingIdentity();
9205 try {
9206 for (Phone phone: PhoneFactory.getPhones()) {
9207 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9208 if (tracker != null) {
9209 tracker.executeEmergencyNumberTestModeCommand(action, num);
9210 }
9211 }
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
9215 }
9216
9217 /**
9218 * Get the full emergency number list for test mode.
9219 */
9220 @Override
9221 public List<String> getEmergencyNumberListTestMode() {
9222 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9223 "getEmergencyNumberListTestMode");
9224
9225 final long identity = Binder.clearCallingIdentity();
9226 try {
9227 Set<String> emergencyNumbers = new HashSet<>();
9228 for (Phone phone: PhoneFactory.getPhones()) {
9229 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9230 if (tracker != null) {
9231 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9232 emergencyNumbers.add(num.getNumber());
9233 }
9234 }
9235 }
9236 return new ArrayList<>(emergencyNumbers);
9237 } finally {
9238 Binder.restoreCallingIdentity(identity);
9239 }
9240 }
9241
chen xud6b45bd2018-10-30 22:27:10 -07009242 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009243 public int getEmergencyNumberDbVersion(int subId) {
9244 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9245
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
9248 final Phone phone = getPhone(subId);
9249 if (phone == null) {
9250 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9251 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9252 }
9253 return phone.getEmergencyNumberDbVersion();
9254 } finally {
9255 Binder.restoreCallingIdentity(identity);
9256 }
9257 }
9258
9259 @Override
9260 public void notifyOtaEmergencyNumberDbInstalled() {
9261 enforceModifyPermission();
9262
9263 final long identity = Binder.clearCallingIdentity();
9264 try {
9265 for (Phone phone: PhoneFactory.getPhones()) {
9266 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9267 if (tracker != null) {
9268 tracker.updateOtaEmergencyNumberDatabase();
9269 }
9270 }
9271 } finally {
9272 Binder.restoreCallingIdentity(identity);
9273 }
9274 }
9275
9276 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009277 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009278 enforceActiveEmergencySessionPermission();
9279
9280 final long identity = Binder.clearCallingIdentity();
9281 try {
9282 for (Phone phone: PhoneFactory.getPhones()) {
9283 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9284 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009285 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9286 }
9287 }
9288 } finally {
9289 Binder.restoreCallingIdentity(identity);
9290 }
9291 }
9292
9293 @Override
9294 public void resetOtaEmergencyNumberDbFilePath() {
9295 enforceActiveEmergencySessionPermission();
9296
9297 final long identity = Binder.clearCallingIdentity();
9298 try {
9299 for (Phone phone: PhoneFactory.getPhones()) {
9300 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9301 if (tracker != null) {
9302 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009303 }
9304 }
9305 } finally {
9306 Binder.restoreCallingIdentity(identity);
9307 }
9308 }
9309
9310 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009311 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9312 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9313 Phone phone = getPhone(subId);
9314 if (phone == null) {
9315 return null;
9316 }
9317 final long identity = Binder.clearCallingIdentity();
9318 try {
9319 UiccProfile profile = UiccController.getInstance()
9320 .getUiccProfileForPhone(phone.getPhoneId());
9321 if (profile != null) {
9322 return profile.getCertsFromCarrierPrivilegeAccessRules();
9323 }
9324 } finally {
9325 Binder.restoreCallingIdentity(identity);
9326 }
9327 return null;
9328 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009329
9330 /**
9331 * Enable or disable a modem stack.
9332 */
9333 @Override
9334 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9335 enforceModifyPermission();
9336
9337 final long identity = Binder.clearCallingIdentity();
9338 try {
9339 Phone phone = PhoneFactory.getPhone(slotIndex);
9340 if (phone == null) {
9341 return false;
9342 } else {
9343 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9344 }
9345 } finally {
9346 Binder.restoreCallingIdentity(identity);
9347 }
9348 }
Michelecea4cf22018-12-21 15:00:11 -08009349
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009350 /**
9351 * Whether a modem stack is enabled or not.
9352 */
9353 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009354 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9355 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009356 Phone phone = PhoneFactory.getPhone(slotIndex);
9357 if (phone == null) return false;
9358
9359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009360 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9361 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009362 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9363 }
9364
9365 final long identity = Binder.clearCallingIdentity();
9366 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009367 try {
9368 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9369 } catch (NoSuchElementException ex) {
9370 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9371 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009372 } finally {
9373 Binder.restoreCallingIdentity(identity);
9374 }
9375 }
9376
Michelecea4cf22018-12-21 15:00:11 -08009377 @Override
Michele0ea7d782019-03-19 14:58:42 -07009378 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009379 enforceModifyPermission();
9380
9381 final long identity = Binder.clearCallingIdentity();
9382 try {
9383 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009384 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009385 .commit();
9386 } finally {
9387 Binder.restoreCallingIdentity(identity);
9388 }
9389 }
9390
9391 @Override
Michele0ea7d782019-03-19 14:58:42 -07009392 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009393 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009395 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9396 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009397 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009398 }
Michelecea4cf22018-12-21 15:00:11 -08009399
9400 final long identity = Binder.clearCallingIdentity();
9401 try {
Michele0ea7d782019-03-19 14:58:42 -07009402 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009407
Michele0ea7d782019-03-19 14:58:42 -07009408 @TelephonyManager.IsMultiSimSupportedResult
9409 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009410 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9411 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9412 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009413 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9414 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009415 }
9416 // Check if the hardware supports multisim functionality. If usage of multisim is not
9417 // supported by the modem, indicate that it is restricted.
9418 PhoneCapability staticCapability =
9419 mPhoneConfigurationManager.getStaticPhoneCapability();
9420 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009421 loge("isMultiSimSupportedInternal: no static configuration available");
9422 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009423 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009424 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009425 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9426 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009427 }
9428 // Check if support of multiple SIMs is restricted by carrier
9429 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009430 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009431 }
9432
Michele0ea7d782019-03-19 14:58:42 -07009433 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009434 }
9435
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009436 /**
9437 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009438 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9439 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9440 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009441 * @param numOfSims number of active sims we want to switch to
9442 */
9443 @Override
9444 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009445 if (numOfSims == 1) {
9446 enforceModifyPermission();
9447 } else {
9448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9449 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9450 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009451 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009452
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009453 try {
Michele30b57b22019-03-01 12:01:14 -08009454 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009455 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009456 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9457 return;
9458 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009459 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9460 } finally {
9461 Binder.restoreCallingIdentity(identity);
9462 }
9463 }
9464
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009465 @Override
9466 public boolean isApplicationOnUicc(int subId, int appType) {
9467 enforceReadPrivilegedPermission("isApplicationOnUicc");
9468 Phone phone = getPhone(subId);
9469 if (phone == null) {
9470 return false;
9471 }
9472 final long identity = Binder.clearCallingIdentity();
9473 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009474 UiccPort uiccPort = phone.getUiccPort();
9475 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009476 return false;
9477 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009478 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009479 if (uiccProfile == null) {
9480 return false;
9481 }
9482 if (TelephonyManager.APPTYPE_SIM <= appType
9483 && appType <= TelephonyManager.APPTYPE_ISIM) {
9484 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9485 }
9486 return false;
9487 } finally {
9488 Binder.restoreCallingIdentity(identity);
9489 }
9490 }
9491
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009492 /**
chen xub4baa772019-04-03 10:23:41 -07009493 * Get whether making changes to modem configurations will trigger reboot.
9494 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009495 */
9496 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009497 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9498 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009500 mApp, subId, callingPackage, callingFeatureId,
9501 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009502 return false;
9503 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009504 final long identity = Binder.clearCallingIdentity();
9505 try {
9506 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510 }
9511
Nathan Harold29f5f052019-02-15 13:41:57 -08009512 private void updateModemStateMetrics() {
9513 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9514 // TODO: check the state for each modem if the api is ready.
9515 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9516 }
9517
Pengquan Meng3889a572019-01-23 11:16:29 -08009518 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00009519 public int[] getSlotsMapping(@NonNull String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009520 enforceReadPrivilegedPermission("getSlotsMapping");
9521
9522 final long identity = Binder.clearCallingIdentity();
9523 try {
9524 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9525 // All logical slots should have a mapping to a physical slot.
9526 int[] logicalSlotsMapping = new int[phoneCount];
sandeepjs0a502c42021-09-27 15:34:44 +00009527 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009528 for (int i = 0; i < slotInfos.length; i++) {
9529 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9530 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9531 }
9532 }
9533 return logicalSlotsMapping;
9534 } finally {
9535 Binder.restoreCallingIdentity(identity);
9536 }
9537 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009538
9539 /**
9540 * Get the IRadio HAL Version
9541 */
9542 @Override
9543 public int getRadioHalVersion() {
9544 Phone phone = getDefaultPhone();
9545 if (phone == null) return -1;
9546 HalVersion hv = phone.getHalVersion();
9547 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9548 return hv.major * 100 + hv.minor;
9549 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009550
9551 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009552 * Get the current calling package name.
9553 * @return the current calling package name
9554 */
9555 @Override
9556 public String getCurrentPackageName() {
9557 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9558 }
9559
9560 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009561 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9562 * corresponding network requests on a subId.
9563 *
9564 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009565 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009566 * 2) APN is un-metered for this subscription, or
9567 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009568 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009569 *
9570 * @return whether data is allowed for a apn type.
9571 *
9572 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009573 */
9574 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009575 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009576 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9577 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009578
9579 // Now that all security checks passes, perform the operation as ourselves.
9580 final long identity = Binder.clearCallingIdentity();
9581 try {
9582 Phone phone = getPhone(subId);
9583 if (phone == null) return false;
9584
Jack Yu41407ee2019-05-13 16:54:09 -07009585 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009586 boolean isDataEnabled;
9587 if (phone.isUsingNewDataStack()) {
9588 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9589 } else {
9590 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9591 }
9592 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009593 } finally {
9594 Binder.restoreCallingIdentity(identity);
9595 }
9596 }
9597
9598 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009599 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009600 enforceReadPrivilegedPermission("isApnMetered");
9601
9602 // Now that all security checks passes, perform the operation as ourselves.
9603 final long identity = Binder.clearCallingIdentity();
9604 try {
9605 Phone phone = getPhone(subId);
9606 if (phone == null) return true; // By default return true.
9607
Jack Yu41407ee2019-05-13 16:54:09 -07009608 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009609 } finally {
9610 Binder.restoreCallingIdentity(identity);
9611 }
9612 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009613
9614 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009615 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9616 int subscriptionId, IBooleanConsumer resultCallback) {
9617 enforceModifyPermission();
9618 long token = Binder.clearCallingIdentity();
9619 try {
9620 Phone phone = getPhone(subscriptionId);
9621 if (phone == null) {
9622 try {
9623 if (resultCallback != null) {
9624 resultCallback.accept(false);
9625 }
9626 } catch (RemoteException e) {
9627 // ignore
9628 }
9629 return;
9630 }
9631 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9632 Pair.create(specifiers, (x) -> {
9633 try {
9634 if (resultCallback != null) {
9635 resultCallback.accept(x);
9636 }
9637 } catch (RemoteException e) {
9638 // ignore
9639 }
9640 });
9641 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9642 } finally {
9643 Binder.restoreCallingIdentity(token);
9644 }
9645 }
9646
9647 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009648 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9649 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009650 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009651 mApp, subId, "getSystemSelectionChannels");
9652 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9653 final long identity = Binder.clearCallingIdentity();
9654 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009655 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9656 if (result instanceof IllegalStateException) {
9657 throw (IllegalStateException) result;
9658 }
9659 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009660 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9661 return specifiers;
9662 } finally {
9663 Binder.restoreCallingIdentity(identity);
9664 }
9665 }
9666
9667 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009668 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009669 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009670 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9671 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9672 if (iccRecords == null) {
9673 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9674 return false;
9675 }
9676 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9677 }
9678
9679 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009680 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9681 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009682 if (callingPackage == null) {
9683 callingPackage = getCurrentPackageName();
9684 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009685 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9686 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009687 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9688 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009689 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9690 }
9691 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9692 Intent intent = new Intent();
9693 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9694 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9695 // Bring up choose default SMS subscription dialog right now
9696 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9697 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9698 mApp.startActivity(intent);
9699 }
chen xud5ca2d52019-05-28 15:20:57 -07009700
9701 @Override
9702 public String getMmsUAProfUrl(int subId) {
9703 //TODO investigate if this API should require proper permission check in R b/133791609
9704 final long identity = Binder.clearCallingIdentity();
9705 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009706 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9707 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9708 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9709 return carrierUAProfUrl;
9710 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009711 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9712 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009713 } finally {
9714 Binder.restoreCallingIdentity(identity);
9715 }
9716 }
9717
9718 @Override
9719 public String getMmsUserAgent(int subId) {
9720 //TODO investigate if this API should require proper permission check in R b/133791609
9721 final long identity = Binder.clearCallingIdentity();
9722 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009723 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9724 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9725 if (!TextUtils.isEmpty(carrierUserAgent)) {
9726 return carrierUserAgent;
9727 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009728 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9729 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009730 } finally {
9731 Binder.restoreCallingIdentity(identity);
9732 }
9733 }
Jack Yub07d4972019-05-28 16:12:25 -07009734
9735 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009736 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9737 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009738
Jack Yub07d4972019-05-28 16:12:25 -07009739 final long identity = Binder.clearCallingIdentity();
9740 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009741 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009742 if (phone == null) return false;
9743
Hall Liua62f5da2020-09-25 10:42:19 -07009744 switch (policy) {
9745 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009746 if (phone.isUsingNewDataStack()) {
9747 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9748 } else {
9749 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9750 }
Hall Liua62f5da2020-09-25 10:42:19 -07009751 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009752 if (phone.isUsingNewDataStack()) {
9753 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9754 } else {
9755 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9756 }
Hall Liua62f5da2020-09-25 10:42:19 -07009757 default:
9758 throw new IllegalArgumentException(policy + " is not a valid policy");
9759 }
Jack Yub07d4972019-05-28 16:12:25 -07009760 } finally {
9761 Binder.restoreCallingIdentity(identity);
9762 }
9763 }
9764
9765 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009766 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009767 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009768 enforceModifyPermission();
9769
changbettyd5c246e2019-12-24 15:40:37 +08009770 final long identity = Binder.clearCallingIdentity();
9771 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009772 Phone phone = getPhone(subscriptionId);
9773 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009774
Hall Liua62f5da2020-09-25 10:42:19 -07009775 switch (policy) {
9776 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009777 if (phone.isUsingNewDataStack()) {
9778 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9779 } else {
9780 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9781 }
Hall Liua62f5da2020-09-25 10:42:19 -07009782 break;
9783 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009784 if (phone.isUsingNewDataStack()) {
9785 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9786 } else {
9787 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9788 }
Hall Liua62f5da2020-09-25 10:42:19 -07009789 break;
9790 default:
9791 throw new IllegalArgumentException(policy + " is not a valid policy");
9792 }
changbettyd5c246e2019-12-24 15:40:37 +08009793 } finally {
9794 Binder.restoreCallingIdentity(identity);
9795 }
9796 }
9797
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009798 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009799 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009800 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9801 * otherwise.
9802 */
9803 @Override
9804 public void setCepEnabled(boolean isCepEnabled) {
9805 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9806
9807 final long identity = Binder.clearCallingIdentity();
9808 try {
9809 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9810 for (Phone phone : PhoneFactory.getPhones()) {
9811 Phone defaultPhone = phone.getImsPhone();
9812 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9813 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9814 ImsPhoneCallTracker imsPhoneCallTracker =
9815 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9816 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9817 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9818 + imsPhone.getMsisdn());
9819 }
9820 }
9821 } finally {
9822 Binder.restoreCallingIdentity(identity);
9823 }
9824 }
allenwtsu46dcc572020-01-08 18:24:03 +08009825
9826 /**
9827 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9828 *
9829 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9830 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9831 * before being read.
9832 */
9833 @Override
9834 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9835 isCompressed) {
9836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9837 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009838 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9839 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9840 }
9841 if (!isImsAvailableOnDevice()) {
9842 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9843 "IMS not available on device.");
9844 }
9845
9846 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009847 try {
Hui Wang761a6682020-10-31 05:12:53 +00009848 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9849 } finally {
9850 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009851 }
9852 }
zoey chene02881a2019-12-30 16:11:23 +08009853
9854 @Override
9855 public boolean isIccLockEnabled(int subId) {
9856 enforceReadPrivilegedPermission("isIccLockEnabled");
9857
9858 // Now that all security checks passes, perform the operation as ourselves.
9859 final long identity = Binder.clearCallingIdentity();
9860 try {
9861 Phone phone = getPhone(subId);
9862 if (phone != null && phone.getIccCard() != null) {
9863 return phone.getIccCard().getIccLockEnabled();
9864 } else {
9865 return false;
9866 }
9867 } finally {
9868 Binder.restoreCallingIdentity(identity);
9869 }
9870 }
9871
9872 /**
9873 * Set the ICC pin lock enabled or disabled.
9874 *
9875 * @return an integer representing the status of IccLock enabled or disabled in the following
9876 * three cases:
9877 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9878 * successfully.
9879 * - Positive number and zero for remaining password attempts.
9880 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9881 *
9882 */
9883 @Override
9884 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9885 enforceModifyPermission();
9886
9887 Phone phone = getPhone(subId);
9888 if (phone == null) {
9889 return 0;
9890 }
9891 // Now that all security checks passes, perform the operation as ourselves.
9892 final long identity = Binder.clearCallingIdentity();
9893 try {
9894 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9895 new Pair<Boolean, String>(enabled, password), phone, null);
9896 return attemptsRemaining;
9897
9898 } catch (Exception e) {
9899 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9900 } finally {
9901 Binder.restoreCallingIdentity(identity);
9902 }
9903 return 0;
9904 }
9905
9906 /**
9907 * Change the ICC password used in ICC pin lock.
9908 *
9909 * @return an integer representing the status of IccLock changed in the following three cases:
9910 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9911 * - Positive number and zero for remaining password attempts.
9912 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9913 *
9914 */
9915 @Override
9916 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9917 enforceModifyPermission();
9918
9919 Phone phone = getPhone(subId);
9920 if (phone == null) {
9921 return 0;
9922 }
9923 // Now that all security checks passes, perform the operation as ourselves.
9924 final long identity = Binder.clearCallingIdentity();
9925 try {
9926 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9927 new Pair<String, String>(oldPassword, newPassword), phone, null);
9928 return attemptsRemaining;
9929
9930 } catch (Exception e) {
9931 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9932 } finally {
9933 Binder.restoreCallingIdentity(identity);
9934 }
9935 return 0;
9936 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009937
9938 /**
9939 * Request for receiving user activity notification
9940 */
9941 @Override
9942 public void requestUserActivityNotification() {
9943 if (!mNotifyUserActivity.get()
9944 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9945 mNotifyUserActivity.set(true);
9946 }
9947 }
9948
9949 /**
9950 * Called when userActivity is signalled in the power manager.
9951 * This is safe to call from any thread, with any window manager locks held or not.
9952 */
9953 @Override
9954 public void userActivity() {
9955 // ***************************************
9956 // * Inherited from PhoneWindowManager *
9957 // ***************************************
9958 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9959 // WITH ITS LOCKS HELD.
9960 //
9961 // This code must be VERY careful about the locks
9962 // it acquires.
9963 // In fact, the current code acquires way too many,
9964 // and probably has lurking deadlocks.
9965
9966 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9967 throw new SecurityException("Only the OS may call notifyUserActivity()");
9968 }
9969
9970 if (mNotifyUserActivity.getAndSet(false)) {
9971 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9972 USER_ACTIVITY_NOTIFICATION_DELAY);
9973 }
9974 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009975
9976 @Override
9977 public boolean canConnectTo5GInDsdsMode() {
9978 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9979 }
Jack Yud10cdd42020-09-28 20:28:01 -07009980
9981 @Override
9982 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9983 String callingFeatureId) {
9984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9985 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9986 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9987 }
9988
9989 Phone phone = getPhone(subId);
9990 if (phone == null) {
9991 throw new RuntimeException("phone is not available");
9992 }
9993 // Now that all security checks passes, perform the operation as ourselves.
9994 final long identity = Binder.clearCallingIdentity();
9995 try {
9996 return phone.getEquivalentHomePlmns();
9997 } finally {
9998 Binder.restoreCallingIdentity(identity);
9999 }
10000 }
Daniel Bright59e67312020-11-13 11:49:37 -080010001
10002 @Override
10003 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010004 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10005 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010006 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010007 if (radioInterfaceCapabilities == null) {
10008 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010009 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010010 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010011 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010012
Hui Wang641e81c2020-10-12 12:14:23 -070010013 @Override
10014 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10015 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010016 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10017 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10018 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10019 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10020 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010021 if (DBG) {
10022 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10023 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10024 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10025 }
10026
10027 if (!SubscriptionManager.isValidSubscriptionId(subId)
10028 || appType < TelephonyManager.APPTYPE_UNKNOWN
10029 || appType > TelephonyManager.APPTYPE_ISIM
10030 || nafUrl == null || securityProtocol == null || callback == null) {
10031 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10032 if (callback != null) {
10033 try {
10034 callback.onAuthenticationFailure(
10035 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10036 } catch (RemoteException exception) {
10037 log("Fail to notify onAuthenticationFailure due to " + exception);
10038 }
10039 return;
10040 }
10041 }
10042
10043 final long token = Binder.clearCallingIdentity();
10044 try {
10045 getGbaManager(subId).bootstrapAuthenticationRequest(
10046 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10047 forceBootStrapping, callback));
10048 } finally {
10049 Binder.restoreCallingIdentity(token);
10050 }
10051 }
10052
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010053 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010054 * Attempts to set the radio power state for all phones for thermal reason.
10055 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010056 * requested radio power state will actually be set. See {@link
10057 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10058 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010059 * @param enable {@code true} if trying to turn radio on.
10060 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10061 * false}.
10062 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010063 private boolean setRadioPowerForThermal(boolean enable) {
10064 boolean isPhoneAvailable = false;
10065 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10066 Phone phone = PhoneFactory.getPhone(i);
10067 if (phone != null) {
10068 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10069 isPhoneAvailable = true;
10070 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010071 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010072
10073 // return true if successfully informed the phone object about the thermal radio power
10074 // request.
10075 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010076 }
10077
10078 private int handleDataThrottlingRequest(int subId,
10079 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010080 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10081 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10082 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10083 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10084 throw new IllegalArgumentException("modem does not support data throttling");
10085 }
10086
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010087 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10088 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010089 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010090 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10091 }
10092
10093 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10094
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010095 if (isDataThrottlingSupported) {
10096 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010097 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010098 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10099 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10100 } else if (thermalMitigationResult
10101 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010102 log("Modem likely does not support data throttling on secondary carrier. Data " +
10103 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10104 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010105 }
10106 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010107 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010108
10109 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010110 }
10111
Jack Nudelman644b91a2021-03-12 14:09:48 -080010112 private static List<String> getThermalMitigationAllowlist(Context context) {
10113 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10114 for (String pckg : context.getResources()
10115 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10116 sThermalMitigationAllowlistedPackages.add(pckg);
10117 }
10118 }
10119
10120 return sThermalMitigationAllowlistedPackages;
10121 }
10122
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010123 private boolean isAnyPhoneInEmergencyState() {
10124 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10125 if (tm.isInEmergencyCall()) {
10126 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10127 return true;
10128 }
10129 for (Phone phone : PhoneFactory.getPhones()) {
10130 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10131 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10132 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10133 + phone.isInEcm());
10134 return true;
10135 }
10136 }
10137
10138 return false;
10139 }
10140
Jack Nudelman644b91a2021-03-12 14:09:48 -080010141 /**
10142 * Used by shell commands to add an authorized package name for thermal mitigation.
10143 * @param packageName name of package to be allowlisted
10144 * @param context
10145 */
10146 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10147 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10148 sThermalMitigationAllowlistedPackages.add(packageName);
10149 }
10150
10151 /**
10152 * Used by shell commands to remove an authorized package name for thermal mitigation.
10153 * @param packageName name of package to remove from allowlist
10154 * @param context
10155 */
10156 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10157 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10158 sThermalMitigationAllowlistedPackages.remove(packageName);
10159 }
10160
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010161 /**
10162 * Thermal mitigation request to control functionalities at modem.
10163 *
10164 * @param subId the id of the subscription.
10165 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010166 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010167 *
10168 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10169 */
10170 @Override
10171 @ThermalMitigationResult
10172 public int sendThermalMitigationRequest(
10173 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010174 ThermalMitigationRequest thermalMitigationRequest,
10175 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010176 enforceModifyPermission();
10177
Jack Nudelman644b91a2021-03-12 14:09:48 -080010178 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10179 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10180 .contains(callingPackage)) {
10181 throw new SecurityException("Calling package must be configured in the device config. "
10182 + "calling package: " + callingPackage);
10183 }
10184
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010185 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10186 final long identity = Binder.clearCallingIdentity();
10187
10188 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10189 try {
10190 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10191 switch (thermalMitigationAction) {
10192 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10193 thermalMitigationResult =
10194 handleDataThrottlingRequest(subId,
10195 thermalMitigationRequest.getDataThrottlingRequest());
10196 break;
10197 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10198 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10199 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10200 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10201 }
10202
10203 // Ensure that radio is on. If not able to power on due to phone being
10204 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010205 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010206 thermalMitigationResult =
10207 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10208 break;
10209 }
10210
10211 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10212 false);
10213 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10214 break;
10215 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10216 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10217 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10218 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10219 }
10220
10221 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10222 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010223 Phone phone = getPhone(subId);
10224 if (phone == null) {
10225 thermalMitigationResult =
10226 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10227 break;
10228 }
10229
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010230 TelephonyConnectionService service =
10231 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010232 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010233 Log.e(LOG_TAG, "An emergency call is pending");
10234 thermalMitigationResult =
10235 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10236 break;
10237 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010238 thermalMitigationResult =
10239 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10240 break;
10241 }
10242 } else {
10243 thermalMitigationResult =
10244 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10245 break;
10246 }
10247
10248 // Turn radio off. If not able to power off due to phone being unavailable,
10249 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010250 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010251 thermalMitigationResult =
10252 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10253 break;
10254 }
10255 thermalMitigationResult =
10256 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10257 break;
10258 default:
10259 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10260 + "not exist. Requested action: " + thermalMitigationAction);
10261 }
10262 } catch (IllegalArgumentException e) {
10263 throw e;
10264 } catch (Exception e) {
10265 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10266 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10267 } finally {
10268 Binder.restoreCallingIdentity(identity);
10269 }
10270
10271 if (DBG) {
10272 log("thermalMitigationRequest returning with thermalMitigationResult: "
10273 + thermalMitigationResult);
10274 }
10275
10276 return thermalMitigationResult;
10277 }
Hui Wang641e81c2020-10-12 12:14:23 -070010278
10279 /**
10280 * Set the GbaService Package Name that Telephony will bind to.
10281 *
10282 * @param subId The sim that the GbaService is associated with.
10283 * @param packageName The name of the package to be replaced with.
10284 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10285 */
10286 @Override
10287 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10288 enforceModifyPermission();
10289
10290 final long identity = Binder.clearCallingIdentity();
10291 try {
10292 return getGbaManager(subId).overrideServicePackage(packageName);
10293 } finally {
10294 Binder.restoreCallingIdentity(identity);
10295 }
10296 }
10297
10298 /**
10299 * Return the package name of the currently bound GbaService.
10300 *
10301 * @param subId The sim that the GbaService is associated with.
10302 * @return the package name of the GbaService configuration, null if GBA is not supported.
10303 */
10304 @Override
10305 public String getBoundGbaService(int subId) {
10306 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10307
10308 final long identity = Binder.clearCallingIdentity();
10309 try {
10310 return getGbaManager(subId).getServicePackage();
10311 } finally {
10312 Binder.restoreCallingIdentity(identity);
10313 }
10314 }
10315
10316 /**
10317 * Set the release time for telephony to unbind GbaService.
10318 *
10319 * @param subId The sim that the GbaService is associated with.
10320 * @param interval The release time to unbind GbaService by millisecond.
10321 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10322 */
10323 @Override
10324 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10325 enforceModifyPermission();
10326
10327 final long identity = Binder.clearCallingIdentity();
10328 try {
10329 return getGbaManager(subId).overrideReleaseTime(interval);
10330 } finally {
10331 Binder.restoreCallingIdentity(identity);
10332 }
10333 }
10334
10335 /**
10336 * Return the release time for telephony to unbind GbaService.
10337 *
10338 * @param subId The sim that the GbaService is associated with.
10339 * @return The release time to unbind GbaService by millisecond.
10340 */
10341 @Override
10342 public int getGbaReleaseTime(int subId) {
10343 enforceReadPrivilegedPermission("getGbaReleaseTime");
10344
10345 final long identity = Binder.clearCallingIdentity();
10346 try {
10347 return getGbaManager(subId).getReleaseTime();
10348 } finally {
10349 Binder.restoreCallingIdentity(identity);
10350 }
10351 }
10352
10353 private GbaManager getGbaManager(int subId) {
10354 GbaManager instance = GbaManager.getInstance(subId);
10355 if (instance == null) {
10356 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10357 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10358 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10359 }
10360 return instance;
10361 }
Hui Wang761a6682020-10-31 05:12:53 +000010362
10363 /**
10364 * indicate whether the device and the carrier can support
10365 * RCS VoLTE single registration.
10366 */
10367 @Override
10368 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010369 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10370 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10371 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10372 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010373
10374 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10375 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10376 }
10377
10378 final long identity = Binder.clearCallingIdentity();
10379 try {
10380 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10381 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010382 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10383 if (isCapable != null) {
10384 return isCapable;
10385 }
Hui Wang761a6682020-10-31 05:12:53 +000010386 }
Hui Wang67af90e2021-06-04 16:57:15 -070010387 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10388 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010389 } finally {
10390 Binder.restoreCallingIdentity(identity);
10391 }
10392 }
10393
10394 /**
10395 * Register RCS provisioning callback.
10396 */
10397 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010398 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010399 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010400 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010401 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010402 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10403 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010404
10405 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10406 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10407 }
10408 if (!isImsAvailableOnDevice()) {
10409 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10410 "IMS not available on device.");
10411 }
10412
10413 final long identity = Binder.clearCallingIdentity();
10414 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010415 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010416 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010417 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10418 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010419 }
Hui Wang761a6682020-10-31 05:12:53 +000010420 } finally {
10421 Binder.restoreCallingIdentity(identity);
10422 }
10423 }
10424
10425 /**
10426 * Unregister RCS provisioning callback.
10427 */
10428 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010429 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010430 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010431 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010432 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010433 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10434 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010435
10436 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10437 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10438 }
10439 if (!isImsAvailableOnDevice()) {
10440 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10441 "IMS not available on device.");
10442 }
10443
10444 final long identity = Binder.clearCallingIdentity();
10445 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010446 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010447 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010448 } finally {
10449 Binder.restoreCallingIdentity(identity);
10450 }
10451 }
10452
10453 /**
10454 * trigger RCS reconfiguration.
10455 */
10456 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010457 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10458 "triggerRcsReconfiguration",
10459 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010460
10461 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10462 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10463 }
10464 if (!isImsAvailableOnDevice()) {
10465 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10466 "IMS not available on device.");
10467 }
10468
10469 final long identity = Binder.clearCallingIdentity();
10470 try {
10471 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10472 } finally {
10473 Binder.restoreCallingIdentity(identity);
10474 }
10475 }
10476
10477 /**
10478 * Provide the client configuration parameters of the RCS application.
10479 */
10480 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010481 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10482 "setRcsClientConfiguration",
10483 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010484
10485 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10486 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10487 }
10488 if (!isImsAvailableOnDevice()) {
10489 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10490 "IMS not available on device.");
10491 }
10492
10493 final long identity = Binder.clearCallingIdentity();
10494
10495 try {
10496 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10497 if (configBinder == null) {
10498 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010499 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10500 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010501 } else {
10502 configBinder.setRcsClientConfiguration(rcc);
10503 }
10504 } catch (RemoteException e) {
10505 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010506 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10507 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010508 } finally {
10509 Binder.restoreCallingIdentity(identity);
10510 }
10511 }
10512
10513 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010514 * Enables or disables the test mode for RCS VoLTE single registration.
10515 */
10516 @Override
10517 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10518 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10519 "setRcsSingleRegistrationTestModeEnabled");
10520
10521 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10522 }
10523
10524 /**
10525 * Gets the test mode for RCS VoLTE single registration.
10526 */
10527 @Override
10528 public boolean getRcsSingleRegistrationTestModeEnabled() {
10529 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10530 "getRcsSingleRegistrationTestModeEnabled");
10531
10532 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10533 }
10534
10535 /**
Hui Wang761a6682020-10-31 05:12:53 +000010536 * Overrides the config of RCS VoLTE single registration enabled for the device.
10537 */
10538 @Override
10539 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10540 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10541 "setDeviceSingleRegistrationEnabledOverride");
10542 enforceModifyPermission();
10543
10544 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10545 : Boolean.parseBoolean(enabledStr);
10546 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010547 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010548 }
10549
10550 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010551 * Sends a device to device communication message. Only usable via shell.
10552 * @param message message to send.
10553 * @param value message value.
10554 */
10555 @Override
10556 public void sendDeviceToDeviceMessage(int message, int value) {
10557 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010558 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010559 enforceModifyPermission();
10560
10561 final long identity = Binder.clearCallingIdentity();
10562 try {
10563 TelephonyConnectionService service =
10564 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10565 if (service == null) {
10566 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10567 return;
10568 }
10569 service.sendTestDeviceToDeviceMessage(message, value);
10570 } finally {
10571 Binder.restoreCallingIdentity(identity);
10572 }
10573 }
10574
Tyler Gunnbabbda02021-02-10 11:05:02 -080010575 /**
10576 * Sets the specified device to device transport active.
10577 * @param transport The transport to set active.
10578 */
10579 @Override
10580 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10581 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10582 "setActiveDeviceToDeviceTransport");
10583 enforceModifyPermission();
10584
10585 final long identity = Binder.clearCallingIdentity();
10586 try {
10587 TelephonyConnectionService service =
10588 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10589 if (service == null) {
10590 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10591 return;
10592 }
10593 service.setActiveDeviceToDeviceTransport(transport);
10594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
Tyler Gunn92479152021-01-20 16:30:10 -080010598
Tyler Gunnd4575212021-05-03 14:46:49 -070010599 @Override
10600 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10601 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10602 "setDeviceToDeviceForceEnabled");
10603
10604 final long identity = Binder.clearCallingIdentity();
10605 try {
10606 Arrays.stream(PhoneFactory.getPhones()).forEach(
10607 p -> {
10608 Phone thePhone = p.getImsPhone();
10609 if (thePhone != null && thePhone instanceof ImsPhone) {
10610 ImsPhone imsPhone = (ImsPhone) thePhone;
10611 CallTracker tracker = imsPhone.getCallTracker();
10612 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10613 ImsPhoneCallTracker imsPhoneCallTracker =
10614 (ImsPhoneCallTracker) tracker;
10615 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10616 }
10617 }
10618 }
10619 );
10620 } finally {
10621 Binder.restoreCallingIdentity(identity);
10622 }
10623 }
10624
Tyler Gunn92479152021-01-20 16:30:10 -080010625 /**
Hui Wang761a6682020-10-31 05:12:53 +000010626 * Gets the config of RCS VoLTE single registration enabled for the device.
10627 */
10628 @Override
10629 public boolean getDeviceSingleRegistrationEnabled() {
10630 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10631 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10632 }
10633
10634 /**
10635 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10636 */
10637 @Override
10638 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10639 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10640 "setCarrierSingleRegistrationEnabledOverride");
10641 enforceModifyPermission();
10642
10643 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10644 : Boolean.parseBoolean(enabledStr);
10645 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10646 subId, enabled);
10647 }
10648
10649 /**
10650 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10651 */
10652 @Override
10653 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10654 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10655 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10656 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010657
10658 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010659 * Overrides the ims feature validation result
10660 */
10661 @Override
10662 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10663 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10664 "setImsFeatureValidationOverride");
10665
10666 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10667 : Boolean.parseBoolean(enabledStr);
10668 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10669 subId, enabled);
10670 }
10671
10672 /**
10673 * Gets the ims feature validation override value
10674 */
10675 @Override
10676 public boolean getImsFeatureValidationOverride(int subId) {
10677 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10678 "getImsFeatureValidationOverride");
10679 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10680 }
10681
10682 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010683 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10684 * their mobile plan.
10685 */
10686 @Override
10687 public String getMobileProvisioningUrl() {
10688 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10689 final long identity = Binder.clearCallingIdentity();
10690 try {
10691 return getDefaultPhone().getMobileProvisioningUrl();
10692 } finally {
10693 Binder.restoreCallingIdentity(identity);
10694 }
10695 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010696
James.cf Linbcdf8b32021-01-14 16:44:13 +080010697 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010698 * Get the EAB contact from the EAB database.
10699 */
10700 @Override
10701 public String getContactFromEab(String contact) {
10702 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10703 enforceModifyPermission();
10704 final long identity = Binder.clearCallingIdentity();
10705 try {
10706 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10707 } finally {
10708 Binder.restoreCallingIdentity(identity);
10709 }
10710 }
10711
10712 /**
Calvin Pana1434322021-07-01 19:27:01 +080010713 * Get the EAB capability from the EAB database.
10714 */
10715 @Override
10716 public String getCapabilityFromEab(String contact) {
10717 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10718 enforceModifyPermission();
10719 final long identity = Binder.clearCallingIdentity();
10720 try {
10721 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10722 } finally {
10723 Binder.restoreCallingIdentity(identity);
10724 }
10725 }
10726
10727 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010728 * Remove the EAB contacts from the EAB database.
10729 */
10730 @Override
10731 public int removeContactFromEab(int subId, String contacts) {
10732 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10733 enforceModifyPermission();
10734 final long identity = Binder.clearCallingIdentity();
10735 try {
10736 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10737 } finally {
10738 Binder.restoreCallingIdentity(identity);
10739 }
10740 }
10741
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010742 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010743 public boolean getDeviceUceEnabled() {
10744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10745 final long identity = Binder.clearCallingIdentity();
10746 try {
10747 return mApp.getDeviceUceEnabled();
10748 } finally {
10749 Binder.restoreCallingIdentity(identity);
10750 }
10751 }
10752
10753 @Override
10754 public void setDeviceUceEnabled(boolean isEnabled) {
10755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10756 final long identity = Binder.clearCallingIdentity();
10757 try {
10758 mApp.setDeviceUceEnabled(isEnabled);
10759 } finally {
10760 Binder.restoreCallingIdentity(identity);
10761 }
10762 }
10763
Brad Ebinger14d467f2021-02-12 06:18:28 +000010764 /**
10765 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10766 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10767 */
10768 // Used for SHELL command only right now.
10769 @Override
10770 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10771 List<String> featureTags) {
10772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10773 "addUceRegistrationOverrideShell");
10774 final long identity = Binder.clearCallingIdentity();
10775 try {
10776 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10777 new ArraySet<>(featureTags));
10778 } catch (ImsException e) {
10779 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10780 } finally {
10781 Binder.restoreCallingIdentity(identity);
10782 }
10783 }
10784
10785 /**
10786 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10787 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10788 */
10789 // Used for SHELL command only right now.
10790 @Override
10791 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10792 List<String> featureTags) {
10793 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10794 "removeUceRegistrationOverrideShell");
10795 final long identity = Binder.clearCallingIdentity();
10796 try {
10797 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10798 new ArraySet<>(featureTags));
10799 } catch (ImsException e) {
10800 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10801 } finally {
10802 Binder.restoreCallingIdentity(identity);
10803 }
10804 }
10805
10806 /**
10807 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10808 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10809 */
10810 // Used for SHELL command only right now.
10811 @Override
10812 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10813 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10814 "clearUceRegistrationOverrideShell");
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10818 } catch (ImsException e) {
10819 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10820 } finally {
10821 Binder.restoreCallingIdentity(identity);
10822 }
10823 }
10824
10825 /**
10826 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10827 */
10828 // Used for SHELL command only right now.
10829 @Override
10830 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10831 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10832 "getLatestRcsContactUceCapabilityShell");
10833 final long identity = Binder.clearCallingIdentity();
10834 try {
10835 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10836 } catch (ImsException e) {
10837 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10838 } finally {
10839 Binder.restoreCallingIdentity(identity);
10840 }
10841 }
10842
10843 /**
10844 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10845 * device does not have an active PUBLISH.
10846 */
10847 // Used for SHELL command only right now.
10848 @Override
10849 public String getLastUcePidfXmlShell(int subId) {
10850 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10851 final long identity = Binder.clearCallingIdentity();
10852 try {
10853 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10854 } catch (ImsException e) {
10855 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10856 } finally {
10857 Binder.restoreCallingIdentity(identity);
10858 }
10859 }
10860
James.cf Line8713a42021-04-29 16:04:26 +080010861 /**
10862 * Remove UCE requests cannot be sent to the network status.
10863 */
10864 // Used for SHELL command only right now.
10865 @Override
10866 public boolean removeUceRequestDisallowedStatus(int subId) {
10867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10868 final long identity = Binder.clearCallingIdentity();
10869 try {
10870 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10871 } catch (ImsException e) {
10872 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10873 } finally {
10874 Binder.restoreCallingIdentity(identity);
10875 }
10876 }
10877
James.cf Lin0fc71b02021-05-25 01:37:38 +080010878 /**
10879 * Remove UCE requests cannot be sent to the network status.
10880 */
10881 // Used for SHELL command only.
10882 @Override
10883 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10884 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10885 final long identity = Binder.clearCallingIdentity();
10886 try {
10887 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10888 } catch (ImsException e) {
10889 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10890 } finally {
10891 Binder.restoreCallingIdentity(identity);
10892 }
10893 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010894
James.cf Lin4b784aa2021-01-31 03:25:15 +080010895 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010896 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10897 String callingPackage) {
10898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10899 mApp, subId, "setSignalStrengthUpdateRequest");
10900
10901 final int callingUid = Binder.getCallingUid();
10902 // Verify that tha callingPackage belongs to the calling UID
10903 mApp.getSystemService(AppOpsManager.class)
10904 .checkPackage(callingUid, callingPackage);
10905
Rambo Wang3607f502021-02-01 21:51:40 -080010906 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010907
10908 final long identity = Binder.clearCallingIdentity();
10909 try {
10910 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10911 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10912
10913 if (result instanceof IllegalStateException) {
10914 throw (IllegalStateException) result;
10915 }
10916 } finally {
10917 Binder.restoreCallingIdentity(identity);
10918 }
10919 }
10920
10921 @Override
10922 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10923 String callingPackage) {
10924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10925 mApp, subId, "clearSignalStrengthUpdateRequest");
10926
10927 final int callingUid = Binder.getCallingUid();
10928 // Verify that tha callingPackage belongs to the calling UID
10929 mApp.getSystemService(AppOpsManager.class)
10930 .checkPackage(callingUid, callingPackage);
10931
10932 final long identity = Binder.clearCallingIdentity();
10933 try {
10934 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10935 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10936
10937 if (result instanceof IllegalStateException) {
10938 throw (IllegalStateException) result;
10939 }
10940 } finally {
10941 Binder.restoreCallingIdentity(identity);
10942 }
10943 }
10944
Rambo Wang3607f502021-02-01 21:51:40 -080010945 private static void validateSignalStrengthUpdateRequest(Context context,
10946 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010947 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10948 // phone/system process do not have further restriction on request
10949 return;
10950 }
10951
10952 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010953 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010954 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010955 context.enforceCallingOrSelfPermission(
10956 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10957 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010958 }
10959
10960 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10961 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10962 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10963 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10964 || info.isEnabled()) {
10965 throw new IllegalArgumentException(
10966 "Only system can set hide fields in SignalThresholdInfo");
10967 }
10968
10969 // Thresholds length for each RAN need in range. This has been validated in
10970 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10971 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10972 final int[] thresholds = info.getThresholds();
10973 Objects.requireNonNull(thresholds);
10974 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10975 || thresholds.length
10976 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10977 throw new IllegalArgumentException(
10978 "thresholds length is out of range: " + thresholds.length);
10979 }
10980 }
10981 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010982
10983 /**
10984 * Gets the current phone capability.
10985 *
10986 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10987 * @return the PhoneCapability which describes the data connection capability of modem.
10988 * It's used to evaluate possible phone config change, for example from single
10989 * SIM device to multi-SIM device.
10990 */
10991 @Override
10992 public PhoneCapability getPhoneCapability() {
10993 enforceReadPrivilegedPermission("getPhoneCapability");
10994 final long identity = Binder.clearCallingIdentity();
10995 try {
10996 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10997 } finally {
10998 Binder.restoreCallingIdentity(identity);
10999 }
11000 }
Michele Berionne5e411512020-11-13 02:36:59 +000011001
11002 /**
11003 * Prepare TelephonyManager for an unattended reboot. The reboot is
11004 * required to be done shortly after the API is invoked.
11005 */
11006 @Override
11007 @TelephonyManager.PrepareUnattendedRebootResult
11008 public int prepareForUnattendedReboot() {
11009 enforceRebootPermission();
11010
11011 final long identity = Binder.clearCallingIdentity();
11012 try {
11013 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
11014 } finally {
11015 Binder.restoreCallingIdentity(identity);
11016 }
11017 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011018
11019 /**
11020 * Request to get the current slicing configuration including URSP rules and
11021 * NSSAIs (configured, allowed and rejected).
11022 *
11023 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11024 */
11025 @Override
11026 public void getSlicingConfig(ResultReceiver callback) {
11027 enforceReadPrivilegedPermission("getSlicingConfig");
11028
11029 final long identity = Binder.clearCallingIdentity();
11030 try {
11031 Phone phone = getDefaultPhone();
11032 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11033 } finally {
11034 Binder.restoreCallingIdentity(identity);
11035 }
11036 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011037
11038 /**
11039 * Register an IMS connection state callback
11040 */
11041 @Override
11042 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11043 String callingPackage) {
11044 if (feature == ImsFeature.FEATURE_MMTEL) {
11045 // ImsMmTelManager
11046 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11047 TelephonyPermissions
11048 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11049 mApp, subId, "registerImsStateCallback");
11050 } else if (feature == ImsFeature.FEATURE_RCS) {
11051 // ImsRcsManager or SipDelegateManager
11052 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11053 Binder.getCallingUid(), "registerImsStateCallback",
11054 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11055 Manifest.permission.READ_PRECISE_PHONE_STATE,
11056 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11057 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11058 }
11059
11060 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11061 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11062 "IMS not available on device.");
11063 }
11064
11065 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11066 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11067 }
11068
11069 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11070 if (controller == null) {
11071 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11072 "IMS not available on device.");
11073 }
11074
11075 if (callingPackage == null) {
11076 callingPackage = getCurrentPackageName();
11077 }
11078
11079 final long token = Binder.clearCallingIdentity();
11080 try {
11081 int slotId = getSlotIndexOrException(subId);
11082 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11083 } catch (ImsException e) {
11084 throw new ServiceSpecificException(e.getCode());
11085 } finally {
11086 Binder.restoreCallingIdentity(token);
11087 }
11088 }
11089
11090 /**
11091 * Unregister an IMS connection state callback
11092 */
11093 @Override
11094 public void unregisterImsStateCallback(IImsStateCallback cb) {
11095 final long token = Binder.clearCallingIdentity();
11096 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11097 if (controller == null) {
11098 return;
11099 }
11100 try {
11101 controller.unregisterImsStateCallback(cb);
11102 } finally {
11103 Binder.restoreCallingIdentity(token);
11104 }
11105 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011106
11107 /**
11108 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11109 *
11110 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11111 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11112 * SecurityException.
11113 * If there is current registered network this value will be same as the registered cell
11114 * identity. If the device goes out of service the previous cell identity is cached and
11115 * will be returned. If the cache age of the Cell identity is more than 24 hours
11116 * it will be cleared and null will be returned.
11117 *
11118 */
11119 @Override
11120 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11121 String callingFeatureId) {
11122 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11123 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11124 LocationAccessPolicy.checkLocationPermission(mApp,
11125 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11126 .setCallingPackage(callingPackage)
11127 .setCallingFeatureId(callingFeatureId)
11128 .setCallingPid(Binder.getCallingPid())
11129 .setCallingUid(Binder.getCallingUid())
11130 .setMethod("getLastKnownCellIdentity")
11131 .setLogAsInfo(true)
11132 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11133 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11134 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11135 .build());
11136
11137 boolean hasFinePermission =
11138 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11139 if (!hasFinePermission
11140 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11141 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11142 + "and BIND_CONNECTION_SERVICE permission.");
11143 }
11144
11145 final long identity = Binder.clearCallingIdentity();
11146 try {
11147 Phone phone = getPhone(subId);
11148 if (phone == null) return null;
11149 ServiceStateTracker sst = phone.getServiceStateTracker();
11150 if (sst == null) return null;
11151 return sst.getLastKnownCellIdentity();
11152 } finally {
11153 Binder.restoreCallingIdentity(identity);
11154 }
11155 }
jimsun38340bf2021-10-26 15:01:23 +080011156
11157 /**
11158 * Sets the modem service class Name that Telephony will bind to.
11159 *
11160 * @param serviceName The class name of the modem service.
11161 * @return true if the operation is succeed, otherwise false.
11162 */
11163 public boolean setModemService(String serviceName) {
11164 Log.d(LOG_TAG, "setModemService - " + serviceName);
11165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11167 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11168 "setModemService");
11169 return mPhoneConfigurationManager.setModemService(serviceName);
11170 }
11171
11172 /**
11173 * Return the class name of the currently bounded modem service.
11174 *
11175 * @return the class name of the modem service.
11176 */
11177 public String getModemService() {
11178 String result;
11179 Log.d(LOG_TAG, "getModemService");
11180 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11181 TelephonyPermissions
11182 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11183 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11184 "getModemService");
11185 result = mPhoneConfigurationManager.getModemService();
11186 Log.d(LOG_TAG, "result = " + result);
11187 return result;
11188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011189}