blob: 2dce7e9a29255a1b984297c0af083c584cfa93aa [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
sandeepjs0a502c42021-09-27 15:34:44 +000030import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080032import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000033import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080034import android.app.role.RoleManager;
sandeepjs0a502c42021-09-27 15:34:44 +000035import android.compat.annotation.ChangeId;
36import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070037import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070038import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.content.Context;
40import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070041import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070042import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080043import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070044import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.net.Uri;
46import android.os.AsyncResult;
47import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080048import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Bundle;
50import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Looper;
53import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080055import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070056import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070057import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080058import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080059import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070060import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070061import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080062import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070064import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070066import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070067import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080068import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070069import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090070import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080071import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080072import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070073import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070074import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080075import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080076import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070077import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080078import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070079import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080080import android.telephony.CellIdentityCdma;
81import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070083import android.telephony.CellInfoGsm;
84import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070085import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070087import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070088import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070089import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080090import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070091import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080092import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070093import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080094import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080095import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070096import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080097import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080099import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800100import android.telephony.SignalStrengthUpdateRequest;
101import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800102import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800104import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700105import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800107import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800109import android.telephony.UiccCardInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000110import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000111import android.telephony.UiccSlotInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000112import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700113import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700114import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800115import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800116import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800117import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700118import android.telephony.gba.GbaAuthRequest;
119import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700120import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000122import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000123import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700124import android.telephony.ims.RegistrationManager;
joonhunshin2c3e4232021-11-28 07:32:01 +0000125import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700126import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800127import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700128import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000131import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700132import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800133import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800134import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800136import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700139import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800141import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142
Andrew Lee312e8172014-10-23 17:01:36 -0700143import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800144import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800145import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800146import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800147import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700149import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700150import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800151import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700152import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800154import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700156import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800157import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800158import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800159import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700160import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +0000161import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800163import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800165import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700166import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700167import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700168import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700170import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800171import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700172import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700173import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700174import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700175import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800176import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800177import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700178import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700179import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700180import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800181import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800182import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700184import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700186import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800187import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700188import com.android.internal.telephony.imsphone.ImsPhone;
189import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800190import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700191import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700192import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800193import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700194import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800195import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700196import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000199import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800200import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000201import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800202import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700203import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700204import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800205import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800206import com.android.phone.callcomposer.CallComposerPictureManager;
207import com.android.phone.callcomposer.CallComposerPictureTransfer;
208import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700209import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700210import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800211import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700212import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700213import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800214import com.android.services.telephony.TelecomAccountRegistry;
215import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800216import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800217
Hall Liu82694d52020-12-11 18:22:04 -0800218import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700219import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800220import java.io.IOException;
221import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700222import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800224import java.util.Arrays;
sandeepjs0a502c42021-09-27 15:34:44 +0000225import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800226import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800227import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800228import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100229import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800230import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700231import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800232import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800233import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800235import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800236import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238/**
239 * Implementation of the ITelephony interface.
240 */
Santos Cordon117fee72014-05-16 17:56:12 -0700241public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242 private static final String LOG_TAG = "PhoneInterfaceManager";
243 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
244 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800245 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246
247 // Message codes used with mMainThreadHandler
248 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700249 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
250 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700251 private static final int CMD_OPEN_CHANNEL = 9;
252 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
253 private static final int CMD_CLOSE_CHANNEL = 11;
254 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800255 private static final int CMD_NV_READ_ITEM = 13;
256 private static final int EVENT_NV_READ_ITEM_DONE = 14;
257 private static final int CMD_NV_WRITE_ITEM = 15;
258 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
259 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
260 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700261 private static final int CMD_RESET_MODEM_CONFIG = 19;
262 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800263 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
264 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800265 private static final int CMD_SEND_ENVELOPE = 25;
266 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000267 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
268 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700269 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
270 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
271 private static final int CMD_EXCHANGE_SIM_IO = 31;
272 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800273 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
274 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700275 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
276 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700277 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
278 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700279 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
280 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
281 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
282 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700283 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
284 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
285 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
286 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700287 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800288 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
289 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000290 private static final int CMD_SWITCH_SLOTS = 50;
291 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700292 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
293 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
294 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
295 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
296 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
297 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
298 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
299 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700300 private static final int CMD_GET_ALL_CELL_INFO = 60;
301 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
302 private static final int CMD_GET_CELL_LOCATION = 62;
303 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700304 private static final int CMD_MODEM_REBOOT = 64;
305 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700306 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
307 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800308 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
309 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700310 private static final int CMD_GET_MODEM_STATUS = 70;
311 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700312 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
313 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700314 private static final int CMD_ERASE_MODEM_CONFIG = 74;
315 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800316 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
317 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
318 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
319 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800320 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
321 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800322 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800323 private static final int CMD_GET_CALL_FORWARDING = 83;
324 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
325 private static final int CMD_SET_CALL_FORWARDING = 85;
326 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
327 private static final int CMD_GET_CALL_WAITING = 87;
328 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
329 private static final int CMD_SET_CALL_WAITING = 89;
330 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700331 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
332 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
333 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
334 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700335 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
336 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800337 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
338 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800339 private static final int CMD_SET_DATA_THROTTLING = 99;
340 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800341 private static final int CMD_SET_SIM_POWER = 101;
342 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800343 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
344 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
345 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
346 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800347 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
348 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000349 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800350 private static final int CMD_GET_SLICING_CONFIG = 110;
351 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800352 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700353 private static final int CMD_ENABLE_VONR = 113;
354 private static final int EVENT_ENABLE_VONR_DONE = 114;
355 private static final int CMD_IS_VONR_ENABLED = 115;
356 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800358 // Parameters of select command.
359 private static final int SELECT_COMMAND = 0xA4;
360 private static final int SELECT_P1 = 0x04;
361 private static final int SELECT_P2 = 0;
362 private static final int SELECT_P3 = 0x10;
363
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 /** The singleton instance. */
365 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800366 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367
Wink Saville3ab207e2014-11-20 13:07:20 -0800368 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800370 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700371 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700373 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800375 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700377 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800378 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379
Peter Wangdafb9ac2020-01-15 14:13:38 -0800380 /** User Activity */
381 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800382 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
383
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700384 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
385
Derek Tan97ebb422014-09-05 16:55:38 -0700386 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
387 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800388 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800389 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700390
Michelecea4cf22018-12-21 15:00:11 -0800391 // String to store multi SIM allowed
392 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
393
Derek Tan740e1672017-06-27 14:56:27 -0700394 // The AID of ISD-R.
395 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
396
yinxub1bed742017-04-17 11:45:04 -0700397 private NetworkScanRequestTracker mNetworkScanRequestTracker;
398
David Kelly5e06a7f2018-03-12 14:10:59 +0000399 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
400 private static final int MANUFACTURER_CODE_LENGTH = 8;
401
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800402 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800403 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800404
Derek Tan89e89d42014-07-08 17:00:10 -0700405 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700406 * Experiment flag to enable erase modem config on reset network, default value is false
407 */
408 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
409 "reset_network_erase_modem_config_enabled";
410
Rambo Wang0f050d82021-02-12 11:43:36 -0800411 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjs0a502c42021-09-27 15:34:44 +0000412 /**
413 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
414 * one ICCID active at the same time.
415 * Apps should use below API signatures if targeting SDK is T and beyond.
416 *
417 * @hide
418 */
419 @ChangeId
420 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
421 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800422
Naina Nallurid63128d2019-09-17 14:10:30 -0700423 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 * A request object to use for transmitting data to an ICC.
425 */
426 private static final class IccAPDUArgument {
427 public int channel, cla, command, p1, p2, p3;
428 public String data;
429
430 public IccAPDUArgument(int channel, int cla, int command,
431 int p1, int p2, int p3, String data) {
432 this.channel = channel;
433 this.cla = cla;
434 this.command = command;
435 this.p1 = p1;
436 this.p2 = p2;
437 this.p3 = p3;
438 this.data = data;
439 }
440 }
441
442 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700443 * A request object to use for transmitting data to an ICC.
444 */
445 private static final class ManualNetworkSelectionArgument {
446 public OperatorInfo operatorInfo;
447 public boolean persistSelection;
448
449 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
450 this.operatorInfo = operatorInfo;
451 this.persistSelection = persistSelection;
452 }
453 }
454
455 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
457 * request after sending. The main thread will notify the request when it is complete.
458 */
459 private static final class MainThreadRequest {
460 /** The argument to use for the request */
461 public Object argument;
462 /** The result of the request that is run on the main thread */
463 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800464 // The subscriber id that this request applies to. Defaults to
465 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
466 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467
Nathan Harold92bed182018-10-12 18:16:49 -0700468 // In cases where subId is unavailable, the caller needs to specify the phone.
469 public Phone phone;
470
vagdeviaf9a5b92018-08-15 16:01:53 -0700471 public WorkSource workSource;
472
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 public MainThreadRequest(Object argument) {
474 this.argument = argument;
475 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800476
Nathan Harold92bed182018-10-12 18:16:49 -0700477 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
478 this.argument = argument;
479 if (phone != null) {
480 this.phone = phone;
481 }
482 this.workSource = workSource;
483 }
484
vagdeviaf9a5b92018-08-15 16:01:53 -0700485 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800486 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800487 if (subId != null) {
488 this.subId = subId;
489 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700490 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 }
493
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800494 private static final class IncomingThirdPartyCallArgs {
495 public final ComponentName component;
496 public final String callId;
497 public final String callerDisplayName;
498
499 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
500 String callerDisplayName) {
501 this.component = component;
502 this.callId = callId;
503 this.callerDisplayName = callerDisplayName;
504 }
505 }
506
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 /**
508 * A handler that processes messages on the main thread in the phone process. Since many
509 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
510 * inbound binder threads to the main thread in the phone process. The Binder thread
511 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
512 * on, which will be notified when the operation completes and will contain the result of the
513 * request.
514 *
515 * <p>If a MainThreadRequest object is provided in the msg.obj field,
516 * note that request.result must be set to something non-null for the calling thread to
517 * unblock.
518 */
519 private final class MainThreadHandler extends Handler {
520 @Override
521 public void handleMessage(Message msg) {
522 MainThreadRequest request;
523 Message onCompleted;
524 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000525 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800527 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528
529 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 case CMD_HANDLE_USSD_REQUEST: {
531 request = (MainThreadRequest) msg.obj;
532 final Phone phone = getPhoneFromRequest(request);
533 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
534 String ussdRequest = ussdObject.first;
535 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700536
Pengquan Menga1bb6272018-09-06 09:59:22 -0700537 if (!isUssdApiAllowed(request.subId)) {
538 // Carrier does not support use of this API, return failure.
539 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
540 UssdResponse response = new UssdResponse(ussdRequest, null);
541 Bundle returnData = new Bundle();
542 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
543 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700544
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 request.result = true;
546 notifyRequester(request);
547 return;
548 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700549
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 try {
551 request.result = phone != null
552 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
553 } catch (CallStateException cse) {
554 request.result = false;
555 }
556 // Wake up the requesting thread
557 notifyRequester(request);
558 break;
pkanwar32d516d2016-10-14 19:37:38 -0700559 }
560
Yorke Lee716f67e2015-06-17 15:39:16 -0700561 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700563 final Phone phone = getPhoneFromRequest(request);
564 request.result = phone != null ?
565 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
566 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000575 uiccPort = getUiccPortFromRequest(request);
576 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 loge("iccTransmitApduLogicalChannel: No UICC");
578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
582 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000583 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 iccArgument.channel, iccArgument.cla, iccArgument.command,
585 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 ar = (AsyncResult) msg.obj;
592 request = (MainThreadRequest) ar.userObj;
593 if (ar.exception == null && ar.result != null) {
594 request.result = ar.result;
595 } else {
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
597 if (ar.result == null) {
598 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800599 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800601 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 } else {
603 loge("iccTransmitApduLogicalChannel: Unknown exception");
604 }
605 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 break;
608
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
610 request = (MainThreadRequest) msg.obj;
611 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000612 uiccPort = getUiccPortFromRequest(request);
613 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 loge("iccTransmitApduBasicChannel: No UICC");
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 } else {
618 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
619 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000620 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
622 iccArgument.p3, iccArgument.data, onCompleted);
623 }
624 break;
625
626 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
627 ar = (AsyncResult) msg.obj;
628 request = (MainThreadRequest) ar.userObj;
629 if (ar.exception == null && ar.result != null) {
630 request.result = ar.result;
631 } else {
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
633 if (ar.result == null) {
634 loge("iccTransmitApduBasicChannel: Empty response");
635 } else if (ar.exception instanceof CommandException) {
636 loge("iccTransmitApduBasicChannel: CommandException: " +
637 ar.exception);
638 } else {
639 loge("iccTransmitApduBasicChannel: Unknown exception");
640 }
641 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 break;
644
645 case CMD_EXCHANGE_SIM_IO:
646 request = (MainThreadRequest) msg.obj;
647 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000648 uiccPort = getUiccPortFromRequest(request);
649 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 loge("iccExchangeSimIO: No UICC");
651 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 } else {
654 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
655 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000656 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
658 iccArgument.data, onCompleted);
659 }
660 break;
661
662 case EVENT_EXCHANGE_SIM_IO_DONE:
663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result;
667 } else {
668 request.result = new IccIoResult(0x6f, 0, (byte[])null);
669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 break;
672
Derek Tan4d5e5c12014-02-04 11:54:58 -0800673 case CMD_SEND_ENVELOPE:
674 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000675 uiccPort = getUiccPortFromRequest(request);
676 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 loge("sendEnvelopeWithStatus: No UICC");
678 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 } else {
681 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000682 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 break;
685
686 case EVENT_SEND_ENVELOPE_DONE:
687 ar = (AsyncResult) msg.obj;
688 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700689 if (ar.exception == null && ar.result != null) {
690 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800691 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700692 request.result = new IccIoResult(0x6F, 0, (byte[])null);
693 if (ar.result == null) {
694 loge("sendEnvelopeWithStatus: Empty response");
695 } else if (ar.exception instanceof CommandException) {
696 loge("sendEnvelopeWithStatus: CommandException: " +
697 ar.exception);
698 } else {
699 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
700 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800701 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700702 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 break;
704
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 case CMD_OPEN_CHANNEL:
706 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000707 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800708 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000709 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700710 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800711 request.result = new IccOpenLogicalChannelResponse(-1,
712 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700714 } else {
715 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000716 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800717 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 break;
720
721 case EVENT_OPEN_CHANNEL_DONE:
722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 int[] result = (int[]) ar.result;
727 int channelId = result[0];
728 byte[] selectResponse = null;
729 if (result.length > 1) {
730 selectResponse = new byte[result.length - 1];
731 for (int i = 1; i < result.length; ++i) {
732 selectResponse[i - 1] = (byte) result[i];
733 }
734 }
735 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700736 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 if (ar.result == null) {
739 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 if (ar.exception != null) {
742 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
743 }
744
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700745 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700746 if (ar.exception instanceof CommandException) {
747 CommandException.Error error =
748 ((CommandException) (ar.exception)).getCommandError();
749 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700750 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700751 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700752 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700753 }
754 }
755 openChannelResp = new IccOpenLogicalChannelResponse(
756 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700758 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 break;
761
762 case CMD_CLOSE_CHANNEL:
763 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000764 uiccPort = getUiccPortFromRequest(request);
765 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700766 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900767 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700768 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 } else {
770 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000771 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 break;
774
775 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800776 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
777 break;
778
779 case CMD_NV_READ_ITEM:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
783 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800784 break;
785
786 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800789 if (ar.exception == null && ar.result != null) {
790 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800792 request.result = "";
793 if (ar.result == null) {
794 loge("nvReadItem: Empty response");
795 } else if (ar.exception instanceof CommandException) {
796 loge("nvReadItem: CommandException: " +
797 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800799 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 }
801 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700802 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 break;
804
Jake Hambye994d462014-02-03 13:10:13 -0800805 case CMD_NV_WRITE_ITEM:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
808 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800809 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700810 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800811 break;
812
813 case EVENT_NV_WRITE_ITEM_DONE:
814 handleNullReturnEvent(msg, "nvWriteItem");
815 break;
816
817 case CMD_NV_WRITE_CDMA_PRL:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800820 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800821 break;
822
823 case EVENT_NV_WRITE_CDMA_PRL_DONE:
824 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
825 break;
826
chen xu6dac5ab2018-10-26 17:39:23 -0700827 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800828 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700829 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800830 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800831 break;
832
chen xu6dac5ab2018-10-26 17:39:23 -0700833 case EVENT_RESET_MODEM_CONFIG_DONE:
834 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800835 break;
836
Sooraj Sasindran37444802020-08-11 10:40:43 -0700837 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
838 request = (MainThreadRequest) msg.obj;
839 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
840 request);
841 Phone phone = getPhoneFromRequest(request);
842 if (phone != null) {
843 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
844 } else {
845 loge("isNRDualConnectivityEnabled: No phone object");
846 request.result = false;
847 notifyRequester(request);
848 }
849 break;
850 }
851
852 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 // request.result must be set to something non-null
859 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700860 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700861 request.result = ar.result;
862 } else {
863 request.result = false;
864 }
865 if (ar.result == null) {
866 loge("isNRDualConnectivityEnabled: Empty response");
867 } else if (ar.exception instanceof CommandException) {
868 loge("isNRDualConnectivityEnabled: CommandException: "
869 + ar.exception);
870 } else {
871 loge("isNRDualConnectivityEnabled: Unknown exception");
872 }
873 }
874 notifyRequester(request);
875 break;
876
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700877 case CMD_IS_VONR_ENABLED: {
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
880 request);
881 Phone phone = getPhoneFromRequest(request);
882 if (phone != null) {
883 phone.isVoNrEnabled(onCompleted, request.workSource);
884 } else {
885 loge("isVoNrEnabled: No phone object");
886 request.result = false;
887 notifyRequester(request);
888 }
889 break;
890 }
891
892 case EVENT_IS_VONR_ENABLED_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result;
897 } else {
898 // request.result must be set to something non-null
899 // for the calling thread to unblock
900 if (ar.result != null) {
901 request.result = ar.result;
902 } else {
903 request.result = false;
904 }
905 if (ar.result == null) {
906 loge("isVoNrEnabled: Empty response");
907 } else if (ar.exception instanceof CommandException) {
908 loge("isVoNrEnabled: CommandException: "
909 + ar.exception);
910 } else {
911 loge("isVoNrEnabled: Unknown exception");
912 }
913 }
914 notifyRequester(request);
915 break;
916
Sooraj Sasindran37444802020-08-11 10:40:43 -0700917 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
920 Phone phone = getPhoneFromRequest(request);
921 if (phone != null) {
922 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
923 request.workSource);
924 } else {
925 loge("enableNrDualConnectivity: No phone object");
926 request.result =
927 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
928 notifyRequester(request);
929 }
930 break;
931 }
932
933 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 if (ar.exception == null) {
937 request.result =
938 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
939 } else {
940 request.result =
941 TelephonyManager
942 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
943 if (ar.exception instanceof CommandException) {
944 CommandException.Error error =
945 ((CommandException) (ar.exception)).getCommandError();
946 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
947 request.result =
948 TelephonyManager
949 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000950 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
951 request.result =
952 TelephonyManager
953 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700954 }
955 loge("enableNrDualConnectivity" + ": CommandException: "
956 + ar.exception);
957 } else {
958 loge("enableNrDualConnectivity" + ": Unknown exception");
959 }
960 }
961 notifyRequester(request);
962 break;
963 }
964
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700965 case CMD_ENABLE_VONR: {
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
971 request.workSource);
972 } else {
973 loge("setVoNrEnabled: No phone object");
974 request.result =
975 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
976 notifyRequester(request);
977 }
978 break;
979 }
980
981 case EVENT_ENABLE_VONR_DONE: {
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception == null) {
985 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
986 } else {
987 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
988 if (ar.exception instanceof CommandException) {
989 CommandException.Error error =
990 ((CommandException) (ar.exception)).getCommandError();
991 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
992 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
993 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
994 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
995 } else {
996 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
997 }
998 loge("setVoNrEnabled" + ": CommandException: "
999 + ar.exception);
1000 } else {
1001 loge("setVoNrEnabled" + ": Unknown exception");
1002 }
1003 }
1004 notifyRequester(request);
1005 break;
1006 }
1007
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001009 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1011 request);
1012 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001013 break;
1014
SongFerngWang3ef3e072020-12-21 16:41:52 +08001015 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception == null && ar.result != null) {
1019 request.result = ar.result; // Integer
1020 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301021 // request.result must be set to something non-null
1022 // for the calling thread to unblock
1023 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001024 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001025 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001026 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001027 loge("getAllowedNetworkTypesBitmask: CommandException: "
1028 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 }
1032 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001033 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001034 break;
1035
SongFerngWang3ef3e072020-12-21 16:41:52 +08001036 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001037 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001038 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1039 request);
1040 Pair<Integer, Long> reasonWithNetworkTypes =
1041 (Pair<Integer, Long>) request.argument;
1042 getPhoneFromRequest(request).setAllowedNetworkTypes(
1043 reasonWithNetworkTypes.first,
1044 reasonWithNetworkTypes.second,
1045 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001046 break;
1047
SongFerngWang3ef3e072020-12-21 16:41:52 +08001048 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1049 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001050 break;
1051
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001052 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1053 request = (MainThreadRequest)msg.obj;
1054 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001055 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001056 break;
1057
1058 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1059 ar = (AsyncResult)msg.obj;
1060 request = (MainThreadRequest)ar.userObj;
1061 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001062 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001063 break;
1064
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001065 case CMD_SET_VOICEMAIL_NUMBER:
1066 request = (MainThreadRequest) msg.obj;
1067 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1068 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001069 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1070 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001071 break;
1072
1073 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1074 handleNullReturnEvent(msg, "setVoicemailNumber");
1075 break;
1076
Stuart Scott54788802015-03-30 13:18:01 -07001077 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1080 request);
1081 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1082 break;
1083
1084 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1085 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1086 break;
1087
Shishir Agrawal302c8692015-06-19 13:49:39 -07001088 case CMD_PERFORM_NETWORK_SCAN:
1089 request = (MainThreadRequest) msg.obj;
1090 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1091 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1092 break;
1093
Hall Liu27d24262020-09-18 19:04:59 -07001094 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001095 request = (MainThreadRequest) msg.obj;
1096 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001097 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1098 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1099 request.argument;
1100 int callForwardingReason = args.first;
1101 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001102 break;
Hall Liu27d24262020-09-18 19:04:59 -07001103 }
1104 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001107 TelephonyManager.CallForwardingInfoCallback callback =
1108 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1109 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001110 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001111 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001112 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1113 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1114 // Service Class is a bit mask per 3gpp 27.007. Search for
1115 // any service for voice call.
1116 if ((callForwardInfo.serviceClass
1117 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001118 callForwardingInfo = new CallForwardingInfo(
1119 callForwardInfo.status
1120 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001121 callForwardInfo.reason,
1122 callForwardInfo.number,
1123 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001124 break;
1125 }
1126 }
1127 // Didn't find a call forward info for voice call.
1128 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001129 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1130 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001131 }
Hall Liu27d24262020-09-18 19:04:59 -07001132 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 } else {
1134 if (ar.result == null) {
1135 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1136 }
1137 if (ar.exception != null) {
1138 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1139 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001140 int errorCode = TelephonyManager
1141 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001142 if (ar.exception instanceof CommandException) {
1143 CommandException.Error error =
1144 ((CommandException) (ar.exception)).getCommandError();
1145 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001146 errorCode = TelephonyManager
1147 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001148 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001149 errorCode = TelephonyManager
1150 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001151 }
1152 }
Hall Liu27d24262020-09-18 19:04:59 -07001153 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001154 }
Shuo Qian4a594052020-01-23 11:59:30 -08001155 break;
Hall Liu27d24262020-09-18 19:04:59 -07001156 }
Shuo Qian4a594052020-01-23 11:59:30 -08001157
Hall Liu27d24262020-09-18 19:04:59 -07001158 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001161 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001162 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001163 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1164 request.argument).first;
1165 request.phone.setCallForwardingOption(
1166 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001167 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001168 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001169 callForwardingInfoToSet.getReason(),
1170 callForwardingInfoToSet.getNumber(),
1171 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1172 break;
Hall Liu27d24262020-09-18 19:04:59 -07001173 }
Shuo Qian4a594052020-01-23 11:59:30 -08001174
Hall Liu27d24262020-09-18 19:04:59 -07001175 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001176 ar = (AsyncResult) msg.obj;
1177 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001178 Consumer<Integer> callback =
1179 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1180 request.argument).second;
1181 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001182 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001183 int errorCode = TelephonyManager.CallForwardingInfoCallback
1184 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001185 if (ar.exception instanceof CommandException) {
1186 CommandException.Error error =
1187 ((CommandException) (ar.exception)).getCommandError();
1188 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001189 errorCode = TelephonyManager.CallForwardingInfoCallback
1190 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001191 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001192 errorCode = TelephonyManager.CallForwardingInfoCallback
1193 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001194 }
1195 }
1196 callback.accept(errorCode);
1197 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001198 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001199 }
Shuo Qian4a594052020-01-23 11:59:30 -08001200 break;
Hall Liu27d24262020-09-18 19:04:59 -07001201 }
Shuo Qian4a594052020-01-23 11:59:30 -08001202
Hall Liu27d24262020-09-18 19:04:59 -07001203 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1206 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1207 break;
Hall Liu27d24262020-09-18 19:04:59 -07001208 }
Shuo Qian4a594052020-01-23 11:59:30 -08001209
Hall Liu27d24262020-09-18 19:04:59 -07001210 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001213 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001214 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1215 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001216 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001217 // Service Class is a bit mask per 3gpp 27.007.
1218 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001219 if (callForwardResults.length > 1
1220 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001221 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001222 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001223 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1224 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001226 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 }
1228 } else {
1229 if (ar.result == null) {
1230 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1231 }
1232 if (ar.exception != null) {
1233 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1234 }
1235 if (ar.exception instanceof CommandException) {
1236 CommandException.Error error =
1237 ((CommandException) (ar.exception)).getCommandError();
1238 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1239 callForwardingStatus =
1240 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1241 }
1242 }
1243 }
Hall Liu27d24262020-09-18 19:04:59 -07001244 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 break;
Hall Liu27d24262020-09-18 19:04:59 -07001246 }
Shuo Qian4a594052020-01-23 11:59:30 -08001247
Hall Liu27d24262020-09-18 19:04:59 -07001248 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001249 request = (MainThreadRequest) msg.obj;
1250 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001251 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1252 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001253 break;
Hall Liu27d24262020-09-18 19:04:59 -07001254 }
Shuo Qian4a594052020-01-23 11:59:30 -08001255
Hall Liu27d24262020-09-18 19:04:59 -07001256 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001257 ar = (AsyncResult) msg.obj;
1258 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001259 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1260 Consumer<Integer> callback =
1261 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1262 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001263 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001264 if (ar.exception instanceof CommandException) {
1265 CommandException.Error error =
1266 ((CommandException) (ar.exception)).getCommandError();
1267 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1268 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1269 } else {
1270 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1271 }
1272 } else {
1273 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1274 }
1275 } else {
1276 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1277 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279 break;
Hall Liu27d24262020-09-18 19:04:59 -07001280 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001281 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 CellNetworkScanResult cellScanResult;
1285 if (ar.exception == null && ar.result != null) {
1286 cellScanResult = new CellNetworkScanResult(
1287 CellNetworkScanResult.STATUS_SUCCESS,
1288 (List<OperatorInfo>) ar.result);
1289 } else {
1290 if (ar.result == null) {
1291 loge("getCellNetworkScanResults: Empty response");
1292 }
1293 if (ar.exception != null) {
1294 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1295 }
1296 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1297 if (ar.exception instanceof CommandException) {
1298 CommandException.Error error =
1299 ((CommandException) (ar.exception)).getCommandError();
1300 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1301 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1302 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1303 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1304 }
1305 }
1306 cellScanResult = new CellNetworkScanResult(errorCode, null);
1307 }
1308 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001309 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001310 break;
1311
1312 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1313 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001314 ManualNetworkSelectionArgument selArg =
1315 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001316 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1317 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001318 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1319 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001320 break;
1321
1322 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001323 ar = (AsyncResult) msg.obj;
1324 request = (MainThreadRequest) ar.userObj;
1325 if (ar.exception == null) {
1326 request.result = true;
1327 } else {
1328 request.result = false;
1329 loge("setNetworkSelectionModeManual " + ar.exception);
1330 }
1331 notifyRequester(request);
1332 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001333 break;
1334
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001335 case CMD_GET_MODEM_ACTIVITY_INFO:
1336 request = (MainThreadRequest) msg.obj;
1337 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001338 if (defaultPhone != null) {
1339 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001340 } else {
1341 ResultReceiver result = (ResultReceiver) request.argument;
1342 Bundle bundle = new Bundle();
1343 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001344 new ModemActivityInfo(0, 0, 0,
1345 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001346 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001347 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001348 break;
1349
Hall Liud0f208c2020-10-14 16:54:44 -07001350 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001351 ar = (AsyncResult) msg.obj;
1352 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001353 ResultReceiver result = (ResultReceiver) request.argument;
1354
Hall Liud0f208c2020-10-14 16:54:44 -07001355 ModemActivityInfo ret = null;
1356 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001357 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001358 // Update the last modem activity info and the result of the request.
1359 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1360 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001361 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001362 int[] txTimeMs = info.getTransmitTimeMillis();
1363 int[] lastModemTxTimeMs = mLastModemActivityInfo
1364 .getTransmitTimeMillis();
1365 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1366 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1367 }
Hall Liu49656c02020-10-09 19:00:11 -07001368 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001369 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1370 + mLastModemActivityInfo.getSleepTimeMillis());
1371 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1372 + mLastModemActivityInfo.getIdleTimeMillis());
1373 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1374 mLastModemActivityInfo.setReceiveTimeMillis(
1375 info.getReceiveTimeMillis()
1376 + mLastModemActivityInfo.getReceiveTimeMillis());
1377 }
Hall Liu49656c02020-10-09 19:00:11 -07001378 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001379 mLastModemActivityInfo.getSleepTimeMillis(),
1380 mLastModemActivityInfo.getIdleTimeMillis(),
1381 mLastModemActivityInfo.getTransmitTimeMillis(),
1382 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001383 } else {
1384 if (ar.result == null) {
1385 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001386 error = TelephonyManager.ModemActivityInfoException
1387 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388 } else if (ar.exception instanceof CommandException) {
1389 loge("queryModemActivityInfo: CommandException: " +
1390 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001391 error = TelephonyManager.ModemActivityInfoException
1392 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001393 } else {
1394 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001395 error = TelephonyManager.ModemActivityInfoException
1396 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001397 }
1398 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001399 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001400 if (ret != null) {
1401 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1402 } else {
1403 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1404 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001405 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001406 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001407 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001408 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001409
Meng Wang1a7c35a2016-05-05 20:56:15 -07001410 case CMD_SET_ALLOWED_CARRIERS:
1411 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001412 CarrierRestrictionRules argument =
1413 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001414 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001415 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001416 break;
1417
1418 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception == null && ar.result != null) {
1422 request.result = ar.result;
1423 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001424 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1425 if (ar.exception instanceof CommandException) {
1426 loge("setAllowedCarriers: CommandException: " + ar.exception);
1427 CommandException.Error error =
1428 ((CommandException) (ar.exception)).getCommandError();
1429 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1430 request.result =
1431 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1432 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001433 } else {
1434 loge("setAllowedCarriers: Unknown exception");
1435 }
1436 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001437 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001438 break;
1439
1440 case CMD_GET_ALLOWED_CARRIERS:
1441 request = (MainThreadRequest) msg.obj;
1442 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001443 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001444 break;
1445
1446 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 if (ar.exception == null && ar.result != null) {
1450 request.result = ar.result;
1451 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001452 request.result = new IllegalStateException(
1453 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001454 if (ar.result == null) {
1455 loge("getAllowedCarriers: Empty response");
1456 } else if (ar.exception instanceof CommandException) {
1457 loge("getAllowedCarriers: CommandException: " +
1458 ar.exception);
1459 } else {
1460 loge("getAllowedCarriers: Unknown exception");
1461 }
1462 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001463 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001464 break;
1465
Nathan Haroldb3014052017-01-25 15:57:32 -08001466 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 if (ar.exception == null && ar.result != null) {
1470 request.result = ar.result;
1471 } else {
1472 request.result = new IllegalArgumentException(
1473 "Failed to retrieve Forbidden Plmns");
1474 if (ar.result == null) {
1475 loge("getForbiddenPlmns: Empty response");
1476 } else {
1477 loge("getForbiddenPlmns: Unknown exception");
1478 }
1479 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001481 break;
1482
1483 case CMD_GET_FORBIDDEN_PLMNS:
1484 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001485 uiccPort = getUiccPortFromRequest(request);
1486 if (uiccPort == null) {
1487 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001488 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001489 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001490 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001491 break;
1492 }
1493 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001494 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001495 if (uiccApp == null) {
1496 loge("getForbiddenPlmns() no app with specified type -- "
1497 + appType);
1498 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001499 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001500 break;
1501 } else {
1502 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1503 + " specified type -- " + appType);
1504 }
1505 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1506 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1507 onCompleted);
1508 break;
1509
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001510 case CMD_SWITCH_SLOTS:
1511 request = (MainThreadRequest) msg.obj;
1512 int[] physicalSlots = (int[]) request.argument;
1513 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1514 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1515 break;
1516
1517 case EVENT_SWITCH_SLOTS_DONE:
1518 ar = (AsyncResult) msg.obj;
1519 request = (MainThreadRequest) ar.userObj;
1520 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
1522 break;
1523 case CMD_GET_NETWORK_SELECTION_MODE:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1526 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1527 break;
1528
1529 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 if (ar.exception != null) {
1533 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1534 } else {
1535 int mode = ((int[]) ar.result)[0];
1536 if (mode == 0) {
1537 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1538 } else {
1539 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1540 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001541 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001542 notifyRequester(request);
1543 break;
1544 case CMD_GET_CDMA_ROAMING_MODE:
1545 request = (MainThreadRequest) msg.obj;
1546 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1547 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1548 break;
1549 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception != null) {
1553 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1554 } else {
1555 request.result = ((int[]) ar.result)[0];
1556 }
1557 notifyRequester(request);
1558 break;
1559 case CMD_SET_CDMA_ROAMING_MODE:
1560 request = (MainThreadRequest) msg.obj;
1561 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1562 int mode = (int) request.argument;
1563 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1564 break;
1565 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 request.result = ar.exception == null;
1569 notifyRequester(request);
1570 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001571 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1574 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1575 break;
1576 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 if (ar.exception != null) {
1580 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1581 } else {
1582 request.result = ((int[]) ar.result)[0];
1583 }
1584 notifyRequester(request);
1585 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001586 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1587 request = (MainThreadRequest) msg.obj;
1588 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1589 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001590 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1591 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001592 break;
1593 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1594 ar = (AsyncResult) msg.obj;
1595 request = (MainThreadRequest) ar.userObj;
1596 request.result = ar.exception == null;
1597 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001598 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001599 case CMD_GET_ALL_CELL_INFO:
1600 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001601 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001602 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001603 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 case EVENT_GET_ALL_CELL_INFO_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001607 // If a timeout occurs, the response will be null
1608 request.result = (ar.exception == null && ar.result != null)
1609 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001610 synchronized (request) {
1611 request.notifyAll();
1612 }
1613 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001614 case CMD_REQUEST_CELL_INFO_UPDATE:
1615 request = (MainThreadRequest) msg.obj;
1616 request.phone.requestCellInfoUpdate(request.workSource,
1617 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1618 break;
1619 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1623 try {
1624 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001625 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001626 cb.onError(
1627 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1628 ar.exception.getClass().getName(),
1629 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001630 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001631 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001632 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001633 } else {
1634 // use the result as returned
1635 cb.onCellInfo((List<CellInfo>) ar.result);
1636 }
1637 } catch (RemoteException re) {
1638 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1639 }
1640 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001641 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001642 request = (MainThreadRequest) msg.obj;
1643 WorkSource ws = (WorkSource) request.argument;
1644 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001645 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001646 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001647 }
1648 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 ar = (AsyncResult) msg.obj;
1650 request = (MainThreadRequest) ar.userObj;
1651 if (ar.exception == null) {
1652 request.result = ar.result;
1653 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001654 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001655 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001656 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001657 }
1658
1659 synchronized (request) {
1660 request.notifyAll();
1661 }
1662 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001663 }
chen xu6dac5ab2018-10-26 17:39:23 -07001664 case CMD_MODEM_REBOOT:
1665 request = (MainThreadRequest) msg.obj;
1666 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001667 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001668 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001669 case EVENT_CMD_MODEM_REBOOT_DONE:
1670 handleNullReturnEvent(msg, "rebootModem");
1671 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001672 case CMD_REQUEST_ENABLE_MODEM:
1673 request = (MainThreadRequest) msg.obj;
1674 boolean enable = (boolean) request.argument;
1675 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001676 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001677 PhoneConfigurationManager.getInstance()
1678 .enablePhone(request.phone, enable, onCompleted);
1679 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001680 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001684 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001685 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001686 if ((boolean) request.result) {
1687 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1688 updateModemStateMetrics();
1689 } else {
1690 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1691 + ar.exception);
1692 }
1693 notifyRequester(request);
1694 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001695 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001696 case CMD_GET_MODEM_STATUS:
1697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1699 PhoneConfigurationManager.getInstance()
1700 .getPhoneStatusFromModem(request.phone, onCompleted);
1701 break;
1702 case EVENT_GET_MODEM_STATUS_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 int id = request.phone.getPhoneId();
1706 if (ar.exception == null && ar.result != null) {
1707 request.result = ar.result;
1708 //update the cache as modem status has changed
1709 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1710 (boolean) request.result);
1711 } else {
1712 // Return true if modem status cannot be retrieved. For most cases,
1713 // modem status is on. And for older version modems, GET_MODEM_STATUS
1714 // and disable modem are not supported. Modem is always on.
1715 // TODO: this should be fixed in R to support a third
1716 // status UNKNOWN b/131631629
1717 request.result = true;
1718 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1719 + ar.exception);
1720 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001721 notifyRequester(request);
1722 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001723 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1726 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1727 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1728 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1729 break;
1730 }
1731 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1732 ar = (AsyncResult) msg.obj;
1733 request = (MainThreadRequest) ar.userObj;
1734 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1735 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1736 args.second.accept(ar.exception == null);
1737 notifyRequester(request);
1738 break;
1739 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001740 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1741 request = (MainThreadRequest) msg.obj;
1742 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1743 Phone phone = getPhoneFromRequest(request);
1744 if (phone != null) {
1745 phone.getSystemSelectionChannels(onCompleted);
1746 } else {
1747 loge("getSystemSelectionChannels: No phone object");
1748 request.result = new ArrayList<RadioAccessSpecifier>();
1749 notifyRequester(request);
1750 }
1751 break;
1752 }
1753 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756 if (ar.exception == null && ar.result != null) {
1757 request.result = ar.result;
1758 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001759 request.result = new IllegalStateException(
1760 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001761 if (ar.result == null) {
1762 loge("getSystemSelectionChannels: Empty response");
1763 } else {
1764 loge("getSystemSelectionChannels: Unknown exception");
1765 }
1766 }
1767 notifyRequester(request);
1768 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001769 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1770 ar = (AsyncResult) msg.obj;
1771 request = (MainThreadRequest) ar.userObj;
1772 if (ar.exception == null && ar.result != null) {
1773 request.result = ar.result;
1774 } else {
1775 request.result = -1;
1776 loge("Failed to set Forbidden Plmns");
1777 if (ar.result == null) {
1778 loge("setForbidenPlmns: Empty response");
1779 } else if (ar.exception != null) {
1780 loge("setForbiddenPlmns: Exception: " + ar.exception);
1781 request.result = -1;
1782 } else {
1783 loge("setForbiddenPlmns: Unknown exception");
1784 }
1785 }
1786 notifyRequester(request);
1787 break;
1788 case CMD_SET_FORBIDDEN_PLMNS:
1789 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001790 uiccPort = getUiccPortFromRequest(request);
1791 if (uiccPort == null) {
1792 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001793 request.result = -1;
1794 notifyRequester(request);
1795 break;
1796 }
1797 Pair<Integer, List<String>> setFplmnsArgs =
1798 (Pair<Integer, List<String>>) request.argument;
1799 appType = setFplmnsArgs.first;
1800 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001801 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001802 if (uiccApp == null) {
1803 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1804 request.result = -1;
1805 loge("Failed to get UICC App");
1806 notifyRequester(request);
1807 } else {
1808 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1809 ((SIMRecords) uiccApp.getIccRecords())
1810 .setForbiddenPlmns(onCompleted, fplmns);
1811 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001812 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001813 case CMD_ERASE_MODEM_CONFIG:
1814 request = (MainThreadRequest) msg.obj;
1815 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1816 defaultPhone.eraseModemConfig(onCompleted);
1817 break;
1818 case EVENT_ERASE_MODEM_CONFIG_DONE:
1819 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001820 break;
zoey chene02881a2019-12-30 16:11:23 +08001821
Kai Shif70f46f2021-03-03 13:59:46 -08001822 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1823 request = (MainThreadRequest) msg.obj;
1824 request.result = defaultPhone.eraseDataInSharedPreferences();
1825 notifyRequester(request);
1826 break;
1827
zoey chene02881a2019-12-30 16:11:23 +08001828 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1829 request = (MainThreadRequest) msg.obj;
1830 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1831 Pair<String, String> changed = (Pair<String, String>) request.argument;
1832 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1833 changed.first, changed.second, onCompleted);
1834 break;
1835 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 if (ar.exception == null) {
1839 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001840 // If the operation is successful, update the PIN storage
1841 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1842 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001843 UiccController.getInstance().getPinStorage()
1844 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001845 } else {
1846 request.result = msg.arg1;
1847 }
1848 notifyRequester(request);
1849 break;
1850
Michele Berionne5e411512020-11-13 02:36:59 +00001851 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001852 request = (MainThreadRequest) msg.obj;
1853 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1854 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1855 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1856 enabled.first, enabled.second, onCompleted);
1857 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001858 }
zoey chene02881a2019-12-30 16:11:23 +08001859 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1860 ar = (AsyncResult) msg.obj;
1861 request = (MainThreadRequest) ar.userObj;
1862 if (ar.exception == null) {
1863 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001864 // If the operation is successful, update the PIN storage
1865 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1866 int phoneId = getPhoneFromRequest(request).getPhoneId();
1867 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001868 UiccController.getInstance().getPinStorage()
1869 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001870 } else {
1871 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1872 }
zoey chene02881a2019-12-30 16:11:23 +08001873 } else {
1874 request.result = msg.arg1;
1875 }
Michele Berionne5e411512020-11-13 02:36:59 +00001876
1877
zoey chene02881a2019-12-30 16:11:23 +08001878 notifyRequester(request);
1879 break;
1880
Peter Wangdafb9ac2020-01-15 14:13:38 -08001881 case MSG_NOTIFY_USER_ACTIVITY:
1882 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001883 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001884 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1885 getDefaultPhone().getContext().sendBroadcastAsUser(
1886 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1887 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001888
1889 case CMD_SET_DATA_THROTTLING: {
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1892 DataThrottlingRequest dataThrottlingRequest =
1893 (DataThrottlingRequest) request.argument;
1894 Phone phone = getPhoneFromRequest(request);
1895 if (phone != null) {
1896 phone.setDataThrottling(onCompleted,
1897 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1898 dataThrottlingRequest.getCompletionDurationMillis());
1899 } else {
1900 loge("setDataThrottling: No phone object");
1901 request.result =
1902 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1903 notifyRequester(request);
1904 }
1905
1906 break;
1907 }
1908 case EVENT_SET_DATA_THROTTLING_DONE:
1909 ar = (AsyncResult) msg.obj;
1910 request = (MainThreadRequest) ar.userObj;
1911
1912 if (ar.exception == null) {
1913 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1914 } else if (ar.exception instanceof CommandException) {
1915 loge("setDataThrottling: CommandException: " + ar.exception);
1916 CommandException.Error error =
1917 ((CommandException) (ar.exception)).getCommandError();
1918
1919 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1920 request.result = TelephonyManager
1921 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1922 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1923 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001924 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1925 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001926 } else {
1927 request.result =
1928 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1929 }
1930 } else {
1931 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1932 }
1933 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1934 notifyRequester(request);
1935 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001936
1937 case CMD_SET_SIM_POWER: {
1938 request = (MainThreadRequest) msg.obj;
1939 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1940 request = (MainThreadRequest) msg.obj;
1941 int stateToSet =
1942 ((Pair<Integer, IIntegerConsumer>)
1943 request.argument).first;
1944 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1945 break;
1946 }
1947 case EVENT_SET_SIM_POWER_DONE: {
1948 ar = (AsyncResult) msg.obj;
1949 request = (MainThreadRequest) ar.userObj;
1950 IIntegerConsumer callback =
1951 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1952 if (ar.exception != null) {
1953 loge("setSimPower exception: " + ar.exception);
1954 int errorCode = TelephonyManager.CallForwardingInfoCallback
1955 .RESULT_ERROR_UNKNOWN;
1956 if (ar.exception instanceof CommandException) {
1957 CommandException.Error error =
1958 ((CommandException) (ar.exception)).getCommandError();
1959 if (error == CommandException.Error.SIM_ERR) {
1960 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1961 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1962 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1963 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1964 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1965 } else {
1966 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1967 }
1968 }
1969 try {
1970 callback.accept(errorCode);
1971 } catch (RemoteException e) {
1972 // Ignore if the remote process is no longer available to call back.
1973 Log.w(LOG_TAG, "setSimPower: callback not available.");
1974 }
1975 } else {
1976 try {
1977 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1978 } catch (RemoteException e) {
1979 // Ignore if the remote process is no longer available to call back.
1980 Log.w(LOG_TAG, "setSimPower: callback not available.");
1981 }
1982 }
1983 break;
1984 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001985 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1986 request = (MainThreadRequest) msg.obj;
1987
1988 final Phone phone = getPhoneFromRequest(request);
1989 if (phone == null || phone.getServiceStateTracker() == null) {
1990 request.result = new IllegalStateException("Phone or SST is null");
1991 notifyRequester(request);
1992 break;
1993 }
1994
1995 Pair<Integer, SignalStrengthUpdateRequest> pair =
1996 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1997 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1998 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001999 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002000 request.subId, pair.first /*callingUid*/,
2001 pair.second /*request*/, onCompleted);
2002 break;
2003 }
2004 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2005 ar = (AsyncResult) msg.obj;
2006 request = (MainThreadRequest) ar.userObj;
2007 // request.result will be the exception of ar if present, true otherwise.
2008 // Be cautious not to leave result null which will wait() forever
2009 request.result = ar.exception != null ? ar.exception : true;
2010 notifyRequester(request);
2011 break;
2012 }
2013 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2014 request = (MainThreadRequest) msg.obj;
2015
2016 Phone phone = getPhoneFromRequest(request);
2017 if (phone == null || phone.getServiceStateTracker() == null) {
2018 request.result = new IllegalStateException("Phone or SST is null");
2019 notifyRequester(request);
2020 break;
2021 }
2022
2023 Pair<Integer, SignalStrengthUpdateRequest> pair =
2024 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2025 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2026 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002027 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002028 request.subId, pair.first /*callingUid*/,
2029 pair.second /*request*/, onCompleted);
2030 break;
2031 }
2032 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2033 ar = (AsyncResult) msg.obj;
2034 request = (MainThreadRequest) ar.userObj;
2035 request.result = ar.exception != null ? ar.exception : true;
2036 notifyRequester(request);
2037 break;
2038 }
Jordan Liu109698e2020-11-24 14:50:34 -08002039
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002040 case CMD_GET_SLICING_CONFIG: {
2041 request = (MainThreadRequest) msg.obj;
2042 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2043 request.phone.getSlicingConfig(onCompleted);
2044 break;
2045 }
2046 case EVENT_GET_SLICING_CONFIG_DONE: {
2047 ar = (AsyncResult) msg.obj;
2048 request = (MainThreadRequest) ar.userObj;
2049 ResultReceiver result = (ResultReceiver) request.argument;
2050
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002051 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002052 Bundle bundle = new Bundle();
2053 int resultCode = 0;
2054 if (ar.exception != null) {
2055 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2056 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002057 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002058 } else if (ar.result == null) {
2059 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002060 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002061 } else {
2062 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002063 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2064 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002065 }
2066
2067 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002068 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002069 }
2070 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2071 result.send(resultCode, bundle);
2072 notifyRequester(request);
2073 break;
2074 }
2075
Michele Berionne5e411512020-11-13 02:36:59 +00002076 case CMD_PREPARE_UNATTENDED_REBOOT:
2077 request = (MainThreadRequest) msg.obj;
2078 request.result =
2079 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2080 notifyRequester(request);
2081 break;
2082
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 default:
2084 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2085 break;
2086 }
2087 }
Jake Hambye994d462014-02-03 13:10:13 -08002088
Pengquan Menga1bb6272018-09-06 09:59:22 -07002089 private void notifyRequester(MainThreadRequest request) {
2090 synchronized (request) {
2091 request.notifyAll();
2092 }
2093 }
2094
Jake Hambye994d462014-02-03 13:10:13 -08002095 private void handleNullReturnEvent(Message msg, String command) {
2096 AsyncResult ar = (AsyncResult) msg.obj;
2097 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2098 if (ar.exception == null) {
2099 request.result = true;
2100 } else {
2101 request.result = false;
2102 if (ar.exception instanceof CommandException) {
2103 loge(command + ": CommandException: " + ar.exception);
2104 } else {
2105 loge(command + ": Unknown exception");
2106 }
2107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002108 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111
2112 /**
2113 * Posts the specified command to be executed on the main thread,
2114 * waits for the request to complete, and returns the result.
2115 * @see #sendRequestAsync
2116 */
2117 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002118 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2119 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002120 }
2121
2122 /**
2123 * Posts the specified command to be executed on the main thread,
2124 * waits for the request to complete, and returns the result.
2125 * @see #sendRequestAsync
2126 */
2127 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2128 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002129 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002130 }
2131
2132 /**
2133 * Posts the specified command to be executed on the main thread,
2134 * waits for the request to complete, and returns the result.
2135 * @see #sendRequestAsync
2136 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002137 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002138 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2139 }
2140
2141 /**
2142 * Posts the specified command to be executed on the main thread,
2143 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2144 * if not timeout or null otherwise.
2145 * @see #sendRequestAsync
2146 */
2147 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2148 long timeoutInMs) {
2149 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002150 }
2151
2152 /**
2153 * Posts the specified command to be executed on the main thread,
2154 * waits for the request to complete, and returns the result.
2155 * @see #sendRequestAsync
2156 */
Nathan Harold92bed182018-10-12 18:16:49 -07002157 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002158 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002159 }
2160
2161 /**
2162 * Posts the specified command to be executed on the main thread,
2163 * waits for the request to complete, and returns the result.
2164 * @see #sendRequestAsync
2165 */
2166 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002167 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2168 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002169 }
2170
2171 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002172 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2173 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2174 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002175 * @see #sendRequestAsync
2176 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002177 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2178 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2180 throw new RuntimeException("This method will deadlock if called from the main thread.");
2181 }
2182
Nathan Harold92bed182018-10-12 18:16:49 -07002183 MainThreadRequest request = null;
2184 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2185 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2186 } else if (phone != null) {
2187 request = new MainThreadRequest(argument, phone, workSource);
2188 } else {
2189 request = new MainThreadRequest(argument, subId, workSource);
2190 }
2191
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 Message msg = mMainThreadHandler.obtainMessage(command, request);
2193 msg.sendToTarget();
2194
Rambo Wang0f050d82021-02-12 11:43:36 -08002195
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002197 if (timeoutInMs >= 0) {
2198 // Wait for at least timeoutInMs before returning null request result
2199 long now = SystemClock.elapsedRealtime();
2200 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002201 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002202 try {
2203 request.wait(deadline - now);
2204 } catch (InterruptedException e) {
2205 // Do nothing, go back and check if request is completed or timeout
2206 } finally {
2207 now = SystemClock.elapsedRealtime();
2208 }
2209 }
2210 } else {
2211 // Wait for the request to complete
2212 while (request.result == null) {
2213 try {
2214 request.wait();
2215 } catch (InterruptedException e) {
2216 // Do nothing, go back and wait until the request is complete
2217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219 }
2220 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002221 if (request.result == null) {
2222 Log.wtf(LOG_TAG,
2223 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 return request.result;
2226 }
2227
2228 /**
2229 * Asynchronous ("fire and forget") version of sendRequest():
2230 * Posts the specified command to be executed on the main thread, and
2231 * returns immediately.
2232 * @see #sendRequest
2233 */
2234 private void sendRequestAsync(int command) {
2235 mMainThreadHandler.sendEmptyMessage(command);
2236 }
2237
2238 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002239 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002240 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002241 */
2242 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 sendRequestAsync(command, argument, null, null);
2244 }
2245
2246 /**
2247 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2248 * @see {@link #sendRequest(int,Object)}
2249 */
2250 private void sendRequestAsync(
2251 int command, Object argument, Phone phone, WorkSource workSource) {
2252 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002253 Message msg = mMainThreadHandler.obtainMessage(command, request);
2254 msg.sendToTarget();
2255 }
2256
2257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 * Initialize the singleton PhoneInterfaceManager instance.
2259 * This is only done once, at startup, from PhoneApp.onCreate().
2260 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002261 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 synchronized (PhoneInterfaceManager.class) {
2263 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002264 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 } else {
2266 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2267 }
2268 return sInstance;
2269 }
2270 }
2271
2272 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002273 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002276 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002277 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002279 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002281 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002282 mTelephonySharedPreferences =
2283 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002284 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002285 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002286 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002287 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002288
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 publish();
2290 }
2291
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002292 private Phone getDefaultPhone() {
2293 Phone thePhone = getPhone(getDefaultSubscription());
2294 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2295 }
2296
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 private void publish() {
2298 if (DBG) log("publish: " + this);
2299
Peter Wangc035ce42020-01-08 21:00:22 -08002300 TelephonyFrameworkInitializer
2301 .getTelephonyServiceManager()
2302 .getTelephonyServiceRegisterer()
2303 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 }
2305
Stuart Scott584921c2015-01-15 17:10:34 -08002306 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002307 if (request.phone != null) {
2308 return request.phone;
2309 } else {
2310 return getPhoneFromSubId(request.subId);
2311 }
2312 }
2313
2314 private Phone getPhoneFromSubId(int subId) {
2315 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2316 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002317 }
2318
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002319 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002320 Phone phone = getPhoneFromRequest(request);
2321 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002322 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002323 }
2324
Wink Saville36469e72014-06-11 15:17:00 -07002325 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002326 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002327 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329
Kai Shif70f46f2021-03-03 13:59:46 -08002330 private void sendEraseModemConfig(@NonNull Phone phone) {
2331 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2332 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2333 }
2334
2335 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2336 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2337 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002338 }
2339
Peter Wang44b186e2020-01-13 23:33:09 -08002340 private boolean isImsAvailableOnDevice() {
2341 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2342 if (pm == null) {
2343 // For some reason package manger is not available.. This will fail internally anyway,
2344 // so do not throw error and allow.
2345 return true;
2346 }
2347 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2348 }
2349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002351 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002352 }
2353
Wink Savilleb564aae2014-10-23 10:18:09 -07002354 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 if (DBG) log("dial: " + number);
2356 // No permission check needed here: This is just a wrapper around the
2357 // ACTION_DIAL intent, which is available to any app since it puts up
2358 // the UI before it does anything.
2359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 String url = createTelUrl(number);
2363 if (url == null) {
2364 return;
2365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367 // PENDING: should we just silently fail if phone is offhook or ringing?
2368 PhoneConstants.State state = mCM.getState(subId);
2369 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2370 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2371 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2372 mApp.startActivity(intent);
2373 }
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 }
2377 }
2378
2379 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002380 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
2382
Wink Savilleb564aae2014-10-23 10:18:09 -07002383 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 if (DBG) log("call: " + number);
2385
2386 // This is just a wrapper around the ACTION_CALL intent, but we still
2387 // need to do a permission check since we're calling startActivity()
2388 // from the context of the phone app.
2389 enforceCallPermission();
2390
Jordan Liu1617b712019-07-10 15:06:26 -07002391 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 != AppOpsManager.MODE_ALLOWED) {
2393 return;
2394 }
2395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 String url = createTelUrl(number);
2399 if (url == null) {
2400 return;
2401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002403 boolean isValid = false;
2404 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2405 if (slist != null) {
2406 for (SubscriptionInfo subInfoRecord : slist) {
2407 if (subInfoRecord.getSubscriptionId() == subId) {
2408 isValid = true;
2409 break;
2410 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002411 }
Wink Saville08874612014-08-31 19:19:58 -07002412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002413 if (!isValid) {
2414 return;
2415 }
Wink Saville08874612014-08-31 19:19:58 -07002416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2418 intent.putExtra(SUBSCRIPTION_KEY, subId);
2419 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2420 mApp.startActivity(intent);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
2423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
2425
Wink Savilleb564aae2014-10-23 10:18:09 -07002426 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002427 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002428 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2429 }
2430
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002432 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002433 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2434 }
2435
Wink Savilleb564aae2014-10-23 10:18:09 -07002436 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438
2439 final long identity = Binder.clearCallingIdentity();
2440 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002441 Phone phone = getPhone(subId);
2442 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443 checkSimPin.start();
2444 return checkSimPin.unlockSim(null, pin);
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
2447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
2449
Wink Savilleb564aae2014-10-23 10:18:09 -07002450 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002455 Phone phone = getPhone(subId);
2456 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 checkSimPuk.start();
2458 return checkSimPuk.unlockSim(puk, pin);
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
2461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463
2464 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002465 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 * a synchronous one.
2467 */
2468 private static class UnlockSim extends Thread {
2469
2470 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002471 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472
2473 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002474 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2475 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476
2477 // For replies from SimCard interface
2478 private Handler mHandler;
2479
2480 // For async handler to identify request type
2481 private static final int SUPPLY_PIN_COMPLETE = 100;
2482
Michele Berionne5e411512020-11-13 02:36:59 +00002483 UnlockSim(int phoneId, IccCard simCard) {
2484 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 mSimCard = simCard;
2486 }
2487
2488 @Override
2489 public void run() {
2490 Looper.prepare();
2491 synchronized (UnlockSim.this) {
2492 mHandler = new Handler() {
2493 @Override
2494 public void handleMessage(Message msg) {
2495 AsyncResult ar = (AsyncResult) msg.obj;
2496 switch (msg.what) {
2497 case SUPPLY_PIN_COMPLETE:
2498 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2499 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002500 mRetryCount = msg.arg1;
2501 if (ar.exception != null) {
2502 if (ar.exception instanceof CommandException &&
2503 ((CommandException)(ar.exception)).getCommandError()
2504 == CommandException.Error.PASSWORD_INCORRECT) {
2505 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002506 } //When UiccCardApp dispose,handle message and return exception
2507 else if (ar.exception instanceof CommandException &&
2508 ((CommandException) (ar.exception)).getCommandError()
2509 == CommandException.Error.ABORTED) {
2510 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002511 } else {
2512 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2513 }
2514 } else {
2515 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 mDone = true;
2518 UnlockSim.this.notifyAll();
2519 }
2520 break;
2521 }
2522 }
2523 };
2524 UnlockSim.this.notifyAll();
2525 }
2526 Looper.loop();
2527 }
2528
2529 /*
2530 * Use PIN or PUK to unlock SIM card
2531 *
2532 * If PUK is null, unlock SIM card with PIN
2533 *
2534 * If PUK is not null, unlock SIM card with PUK and set PIN code
2535 */
Wink Saville9de0f752013-10-22 19:04:03 -07002536 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537
2538 while (mHandler == null) {
2539 try {
2540 wait();
2541 } catch (InterruptedException e) {
2542 Thread.currentThread().interrupt();
2543 }
2544 }
2545 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2546
2547 if (puk == null) {
2548 mSimCard.supplyPin(pin, callback);
2549 } else {
2550 mSimCard.supplyPuk(puk, pin, callback);
2551 }
2552
2553 while (!mDone) {
2554 try {
2555 Log.d(LOG_TAG, "wait for done");
2556 wait();
2557 } catch (InterruptedException e) {
2558 // Restore the interrupted status
2559 Thread.currentThread().interrupt();
2560 }
2561 }
2562 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002563 int[] resultArray = new int[2];
2564 resultArray[0] = mResult;
2565 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002566
2567 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002568 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002569 }
2570
Wink Saville9de0f752013-10-22 19:04:03 -07002571 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
2573 }
2574
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002575 /**
2576 * This method has been removed due to privacy and stability concerns.
2577 */
2578 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002580 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2581 return;
Wink Saville36469e72014-06-11 15:17:00 -07002582 }
2583
Nathan Harold1f889d82020-06-04 17:05:26 -07002584 @Override
2585 public void updateServiceLocationWithPackageName(String callingPackage) {
2586 mApp.getSystemService(AppOpsManager.class)
2587 .checkPackage(Binder.getCallingUid(), callingPackage);
2588
Nathan Haroldf096d982020-11-18 17:18:06 -08002589 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002590 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2591 // Callers targeting S have no business invoking this method.
2592 return;
2593 }
2594
2595 LocationAccessPolicy.LocationPermissionResult locationResult =
2596 LocationAccessPolicy.checkLocationPermission(mApp,
2597 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2598 .setCallingPackage(callingPackage)
2599 .setCallingFeatureId(null)
2600 .setCallingPid(Binder.getCallingPid())
2601 .setCallingUid(Binder.getCallingUid())
2602 .setMethod("updateServiceLocation")
2603 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2604 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2605 .build());
2606 // Apps that lack location permission have no business calling this method;
2607 // however, because no permission was declared in the public API, denials must
2608 // all be "soft".
2609 switch (locationResult) {
2610 case DENIED_HARD: /* fall through */
2611 case DENIED_SOFT:
2612 return;
2613 }
2614
2615 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002618 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002620 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002627 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 @Override
2629 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002630 return isRadioOnWithFeature(callingPackage, null);
2631 }
2632
2633
2634 @Override
2635 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2636 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2637 callingFeatureId);
2638 }
2639
2640 @Deprecated
2641 @Override
2642 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2643 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002644 }
2645
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002646 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002647 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2648 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002650 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002651 return false;
2652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 return isRadioOnForSubscriber(subId);
2657 } finally {
2658 Binder.restoreCallingIdentity(identity);
2659 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002660 }
2661
2662 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 if (phone != null) {
2667 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2668 } else {
2669 return false;
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
Wink Saville36469e72014-06-11 15:17:00 -07002679
Wink Savilleb564aae2014-10-23 10:18:09 -07002680 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 final Phone phone = getPhone(subId);
2686 if (phone != null) {
2687 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002691 }
Wink Saville36469e72014-06-11 15:17:00 -07002692 }
2693
2694 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002695 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002696 }
2697
Wink Savilleb564aae2014-10-23 10:18:09 -07002698 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 final Phone phone = getPhone(subId);
2704 if (phone == null) {
2705 return false;
2706 }
2707 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2708 toggleRadioOnOffForSubscriber(subId);
2709 }
2710 return true;
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
Wink Saville36469e72014-06-11 15:17:00 -07002715
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002716 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002717 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 /*
2719 * If any of the Radios are available, it will need to be
2720 * shutdown. So return true if any Radio is available.
2721 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2725 Phone phone = PhoneFactory.getPhone(i);
2726 if (phone != null && phone.isRadioAvailable()) return true;
2727 }
2728 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2729 return false;
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002733 }
2734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 enforceModifyPermission();
2738
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2742 logv("Shutting down Phone " + i);
2743 shutdownRadioUsingPhoneId(i);
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002747 }
2748 }
2749
2750 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002751 Phone phone = PhoneFactory.getPhone(phoneId);
2752 if (phone != null && phone.isRadioAvailable()) {
2753 phone.shutdownRadio();
2754 }
2755 }
2756
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759
2760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2763 if (defaultPhone != null) {
2764 defaultPhone.setRadioPower(turnOn);
2765 return true;
2766 } else {
2767 loge("There's no default phone.");
2768 return false;
2769 }
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002772 }
Wink Saville36469e72014-06-11 15:17:00 -07002773 }
2774
Wink Savilleb564aae2014-10-23 10:18:09 -07002775 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 final Phone phone = getPhone(subId);
2781 if (phone != null) {
2782 phone.setRadioPower(turnOn);
2783 return true;
2784 } else {
2785 return false;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
Wink Saville36469e72014-06-11 15:17:00 -07002792 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 public boolean enableDataConnectivity() {
2795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 int subId = mSubscriptionController.getDefaultDataSubId();
2800 final Phone phone = getPhone(subId);
2801 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002802 phone.getDataEnabledSettings().setDataEnabled(
2803 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 return true;
2805 } else {
2806 return false;
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
Wink Saville36469e72014-06-11 15:17:00 -07002813 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 public boolean disableDataConnectivity() {
2816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817
2818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 int subId = mSubscriptionController.getDefaultDataSubId();
2821 final Phone phone = getPhone(subId);
2822 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002823 phone.getDataEnabledSettings().setDataEnabled(
2824 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 return true;
2826 } else {
2827 return false;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 }
2833
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002835 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 final Phone phone = getPhone(subId);
2839 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002840 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002841 } else {
2842 return false;
2843 }
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
2849 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002850 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002851 }
2852
pkanwarae03a6b2016-11-06 20:37:09 -08002853 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 enforceCallPermission();
2855
2856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2859 return;
2860 }
2861 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2862 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
2865 }
pkanwar32d516d2016-10-14 19:37:38 -07002866 };
2867
Wink Savilleb564aae2014-10-23 10:18:09 -07002868 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 return false;
2875 }
2876 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2877 } finally {
2878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002882 /**
2883 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2884 * tag on getCallState Binder call.
2885 */
2886 @Deprecated
2887 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002889 if (CompatChanges.isChangeEnabled(
2890 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2891 Binder.getCallingUid())) {
2892 // Do not allow this API to be called on API version 31+, it should only be
2893 // called on old apps using this Binder call directly.
2894 throw new SecurityException("This method can only be used for applications "
2895 + "targeting API version 30 or less.");
2896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 final long identity = Binder.clearCallingIdentity();
2898 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002899 Phone phone = getPhone(getDefaultSubscription());
2900 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2901 PhoneConstantConversions.convertCallState(phone.getState());
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
2904 }
2905 }
2906
2907 @Override
2908 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2909 if (CompatChanges.isChangeEnabled(
2910 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2911 Binder.getCallingUid())) {
2912 // Check READ_PHONE_STATE for API version 31+
2913 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2914 featureId, "getCallStateForSubscription")) {
2915 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2916 + "targeting API level 31+.");
2917 }
2918 }
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2923 PhoneConstantConversions.convertCallState(phone.getState());
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002930 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002931 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2932 }
2933
2934 @Override
2935 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002938 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 if (phone != null) {
2940 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2941 } else {
2942 return PhoneConstantConversions.convertDataState(
2943 PhoneConstants.DataState.DISCONNECTED);
2944 }
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 }
2949
Sanket Padawe356d7632015-06-22 14:03:32 -07002950 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002951 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002952 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2953 }
2954
2955 @Override
2956 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957 final long identity = Binder.clearCallingIdentity();
2958 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002959 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 if (phone != null) {
2961 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2962 } else {
2963 return TelephonyManager.DATA_ACTIVITY_NONE;
2964 }
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002968 }
2969
2970 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002971 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002972 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002973 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002974
2975 LocationAccessPolicy.LocationPermissionResult locationResult =
2976 LocationAccessPolicy.checkLocationPermission(mApp,
2977 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2978 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002979 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002980 .setCallingPid(Binder.getCallingPid())
2981 .setCallingUid(Binder.getCallingUid())
2982 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002983 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002984 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2985 .build());
2986 switch (locationResult) {
2987 case DENIED_HARD:
2988 throw new SecurityException("Not allowed to access cell location");
2989 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002990 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2991 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 }
2993
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002994 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002998 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002999 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
Svetoslav64fad262015-04-14 14:35:21 -07003003 }
3004
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003006 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003007 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3008 // registered cell info, so return a NULL country instead.
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003011 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3012 // Get default phone in this case.
3013 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3014 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003015 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003017 if (phone == null) return "";
3018 ServiceStateTracker sst = phone.getServiceStateTracker();
3019 if (sst == null) return "";
3020 LocaleTracker lt = sst.getLocaleTracker();
3021 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003022 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003026 }
3027
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003028 /**
3029 * This method was removed due to potential issues caused by performing partial
3030 * updates of service state, and lack of a credible use case.
3031 *
3032 * This has the ability to break the telephony implementation by disabling notification of
3033 * changes in device connectivity. DO NOT USE THIS!
3034 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003035 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003036 public void enableLocationUpdates() {
3037 mApp.enforceCallingOrSelfPermission(
3038 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -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 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 @Override
3049 public void disableLocationUpdates() {
3050 mApp.enforceCallingOrSelfPermission(
3051 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052 }
3053
3054 @Override
3055 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003056 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3057 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003058 try {
3059 mApp.getSystemService(AppOpsManager.class)
3060 .checkPackage(Binder.getCallingUid(), callingPackage);
3061 } catch (SecurityException e) {
3062 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3063 throw e;
3064 }
3065
Nathan Haroldf096d982020-11-18 17:18:06 -08003066 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003067 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3068 throw new SecurityException(
3069 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3070 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003071
Jordan Liu1617b712019-07-10 15:06:26 -07003072 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3074 return null;
3075 }
Svetoslav64fad262015-04-14 14:35:21 -07003076
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003077 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003078
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003079 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003080 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081
Nathan Haroldf180aac2018-06-01 18:43:55 -07003082 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3083 for (CellInfo ci : info) {
3084 if (ci instanceof CellInfoGsm) {
3085 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3086 } else if (ci instanceof CellInfoWcdma) {
3087 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003090 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 }
3092
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003093 private List<CellInfo> getCachedCellInfo() {
3094 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3095 for (Phone phone : PhoneFactory.getPhones()) {
3096 List<CellInfo> info = phone.getAllCellInfo();
3097 if (info != null) cellInfos.addAll(info);
3098 }
3099 return cellInfos;
3100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003101
3102 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003103 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003104 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003105 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003106
3107 LocationAccessPolicy.LocationPermissionResult locationResult =
3108 LocationAccessPolicy.checkLocationPermission(mApp,
3109 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3110 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003111 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003112 .setCallingPid(Binder.getCallingPid())
3113 .setCallingUid(Binder.getCallingUid())
3114 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003115 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003116 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3117 .build());
3118 switch (locationResult) {
3119 case DENIED_HARD:
3120 throw new SecurityException("Not allowed to access cell info");
3121 case DENIED_SOFT:
3122 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 }
3124
Nathan Haroldf096d982020-11-18 17:18:06 -08003125 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003126 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3127 return getCachedCellInfo();
3128 }
3129
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003130 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003131 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3135 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003136 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003137 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 if (info != null) cellInfos.addAll(info);
3139 }
3140 return cellInfos;
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 }
3144 }
3145
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003146 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003147 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3148 String callingFeatureId) {
3149 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3150 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003151 }
3152
3153 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003154 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3155 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003156 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003157 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003158 }
3159
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003160 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3161 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003162 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003163 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003164
3165 LocationAccessPolicy.LocationPermissionResult locationResult =
3166 LocationAccessPolicy.checkLocationPermission(mApp,
3167 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3168 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003169 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003170 .setCallingPid(Binder.getCallingPid())
3171 .setCallingUid(Binder.getCallingUid())
3172 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003173 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3174 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003175 .build());
3176 switch (locationResult) {
3177 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003178 if (TelephonyPermissions
3179 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003180 // Safetynet logging for b/154934934
3181 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3182 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003183 throw new SecurityException("Not allowed to access cell info");
3184 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003185 if (TelephonyPermissions
3186 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003187 // Safetynet logging for b/154934934
3188 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3189 }
Nathan Harold5320c422019-05-09 10:26:08 -07003190 try {
3191 cb.onCellInfo(new ArrayList<CellInfo>());
3192 } catch (RemoteException re) {
3193 // Drop without consequences
3194 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003195 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003196 }
3197
Nathan Harolda939a962019-05-09 10:13:47 -07003198
3199 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003200 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3201
3202 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3203 }
3204
3205 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003207 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003212 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 }
3217
Shishir Agrawala9f32182016-04-12 12:00:16 -07003218 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003219 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003220 Phone phone = PhoneFactory.getPhone(slotIndex);
3221 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003222 return null;
3223 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003224 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003225 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003226 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003227 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003228 return null;
3229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
3233 return phone.getImei();
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003237 }
3238
3239 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003240 public String getTypeAllocationCodeForSlot(int slotIndex) {
3241 Phone phone = PhoneFactory.getPhone(slotIndex);
3242 String tac = null;
3243 if (phone != null) {
3244 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003245 try {
3246 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3247 } catch (IndexOutOfBoundsException e) {
3248 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3249 return null;
3250 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003251 }
3252 return tac;
3253 }
3254
3255 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003256 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003257 try {
3258 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3259 } catch (SecurityException se) {
3260 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3261 throw new SecurityException("Package " + callingPackage + " does not belong to "
3262 + Binder.getCallingUid());
3263 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003264 Phone phone = PhoneFactory.getPhone(slotIndex);
3265 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003266 return null;
3267 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003268
Jeff Davidson913390f2018-02-23 17:11:49 -08003269 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003270 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003271 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003272 return null;
3273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274
3275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 return phone.getMeid();
3278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
Jack Yu2af8d712017-03-15 17:14:14 -07003281 }
3282
3283 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003284 public String getManufacturerCodeForSlot(int slotIndex) {
3285 Phone phone = PhoneFactory.getPhone(slotIndex);
3286 String manufacturerCode = null;
3287 if (phone != null) {
3288 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003289 try {
3290 manufacturerCode =
3291 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3292 } catch (IndexOutOfBoundsException e) {
3293 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3294 return null;
3295 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003296 }
3297 return manufacturerCode;
3298 }
3299
3300 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003301 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3302 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003303 Phone phone = PhoneFactory.getPhone(slotIndex);
3304 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003305 return null;
3306 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003307 int subId = phone.getSubId();
3308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003309 mApp, subId, callingPackage, callingFeatureId,
3310 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003311 return null;
3312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 return phone.getDeviceSvn();
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003320 }
3321
fionaxu43304da2017-11-27 22:51:16 -08003322 @Override
3323 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 final Phone phone = getPhone(subId);
3327 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
3330 }
fionaxu43304da2017-11-27 22:51:16 -08003331 }
3332
3333 @Override
3334 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 final Phone phone = getPhone(subId);
3338 return phone == null ? null : phone.getCarrierName();
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
fionaxu43304da2017-11-27 22:51:16 -08003342 }
3343
calvinpanffe225e2018-11-01 19:43:06 +08003344 @Override
chen xu0026ca62019-03-06 15:28:50 -08003345 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 final Phone phone = getPhone(subId);
3349 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003350 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
3354 }
3355
3356 @Override
chen xu0026ca62019-03-06 15:28:50 -08003357 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003361 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
3365 }
3366
chen xu651eec72018-11-11 19:03:44 -08003367 @Override
chen xu864e11c2018-12-06 22:10:03 -08003368 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3369 if (!isSubscriptionMccMnc) {
3370 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3371 }
chen xu651eec72018-11-11 19:03:44 -08003372 final Phone phone = PhoneFactory.getPhone(slotIndex);
3373 if (phone == null) {
3374 return TelephonyManager.UNKNOWN_CARRIER_ID;
3375 }
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
3382 }
3383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003384 //
3385 // Internal helper methods.
3386 //
3387
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003388 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003389 * Make sure the caller is the calling package itself
3390 *
3391 * @throws SecurityException if the caller is not the calling package
3392 */
3393 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3394 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003395 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3396 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003397 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003398 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003399 } catch (PackageManager.NameNotFoundException e) {
3400 // packageUid is -1
3401 }
3402 if (packageUid != callingUid) {
3403 throw new SecurityException(message + ": Package " + callingPackage
3404 + " does not belong to " + callingUid);
3405 }
3406 }
3407
3408 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003409 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3410 *
3411 * @throws SecurityException if the caller does not have the required permission
3412 */
3413 private void enforceModifyPermission() {
3414 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3415 }
3416
Shuo Qian3b6ee772019-11-13 17:43:31 -08003417 private void enforceActiveEmergencySessionPermission() {
3418 mApp.enforceCallingOrSelfPermission(
3419 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3420 }
3421
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003422 /**
3423 * Make sure the caller has the CALL_PHONE permission.
3424 *
3425 * @throws SecurityException if the caller does not have the required permission
3426 */
3427 private void enforceCallPermission() {
3428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3429 }
3430
paulhu5a773602019-08-23 19:17:33 +08003431 private void enforceSettingsPermission() {
3432 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003433 }
3434
Michele Berionne5e411512020-11-13 02:36:59 +00003435 private void enforceRebootPermission() {
3436 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3437 }
3438
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003439 private String createTelUrl(String number) {
3440 if (TextUtils.isEmpty(number)) {
3441 return null;
3442 }
3443
Jake Hambye994d462014-02-03 13:10:13 -08003444 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 }
3446
Ihab Awadf9e92732013-12-05 18:02:52 -08003447 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3449 }
3450
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003451 private static void logv(String msg) {
3452 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3453 }
3454
Ihab Awadf9e92732013-12-05 18:02:52 -08003455 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003456 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3457 }
3458
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003459 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003460 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003461 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003462 }
3463
Sanket Padawe356d7632015-06-22 14:03:32 -07003464 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003465 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 final Phone phone = PhoneFactory.getPhone(slotIndex);
3469 if (phone == null) {
3470 return PhoneConstants.PHONE_TYPE_NONE;
3471 } else {
3472 return phone.getPhoneType();
3473 }
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003477 }
3478
3479 /**
3480 * Returns the CDMA ERI icon index to display
3481 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003482 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003483 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3484 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3485 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003486 }
3487
Sanket Padawe356d7632015-06-22 14:03:32 -07003488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003489 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3490 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003492 mApp, subId, callingPackage, callingFeatureId,
3493 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003494 return -1;
3495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496
3497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 final Phone phone = getPhone(subId);
3500 if (phone != null) {
3501 return phone.getCdmaEriIconIndex();
3502 } else {
3503 return -1;
3504 }
3505 } finally {
3506 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 }
3509
3510 /**
3511 * Returns the CDMA ERI icon mode,
3512 * 0 - ON
3513 * 1 - FLASHING
3514 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003515 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003516 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3517 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3518 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003519 }
3520
Sanket Padawe356d7632015-06-22 14:03:32 -07003521 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003522 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3523 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003525 mApp, subId, callingPackage, callingFeatureId,
3526 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003527 return -1;
3528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529
3530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 final Phone phone = getPhone(subId);
3533 if (phone != null) {
3534 return phone.getCdmaEriIconMode();
3535 } else {
3536 return -1;
3537 }
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003541 }
3542
3543 /**
3544 * Returns the CDMA ERI text,
3545 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003546 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003547 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3548 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3549 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003550 }
3551
Sanket Padawe356d7632015-06-22 14:03:32 -07003552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003553 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3554 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 mApp, subId, callingPackage, callingFeatureId,
3557 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003558 return null;
3559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
3564 if (phone != null) {
3565 return phone.getCdmaEriText();
3566 } else {
3567 return null;
3568 }
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003572 }
3573
3574 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003575 * Returns the CDMA MDN.
3576 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003577 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003578 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3580 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581
3582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586 return phone.getLine1Number();
3587 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003588 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589 return null;
3590 }
3591 } finally {
3592 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003593 }
3594 }
3595
3596 /**
3597 * Returns the CDMA MIN.
3598 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003599 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003600 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3602 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603
3604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 final Phone phone = getPhone(subId);
3607 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3608 return phone.getCdmaMin();
3609 } else {
3610 return null;
3611 }
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003614 }
3615 }
3616
Hall Liud892bec2018-11-30 14:51:45 -08003617 @Override
3618 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3619 INumberVerificationCallback callback, String callingPackage) {
3620 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3621 != PERMISSION_GRANTED) {
3622 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3623 }
3624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3625
3626 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3627 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003628 throw new SecurityException("Calling package must be configured in the device config: "
3629 + "calling package: " + callingPackage
3630 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003631 }
3632
3633 if (range == null) {
3634 throw new NullPointerException("Range must be non-null");
3635 }
3636
3637 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003638 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003639
3640 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3641 }
3642
Junda Liuca05d5d2014-08-14 22:36:34 -07003643 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003644 * Returns true if CDMA provisioning needs to run.
3645 */
3646 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647 final long identity = Binder.clearCallingIdentity();
3648 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003649 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003653 }
3654
3655 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003656 * Sets the voice mail number of a given subId.
3657 */
3658 @Override
3659 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003660 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3661 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662
3663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3666 new Pair<String, String>(alphaTag, number), new Integer(subId));
3667 return success;
3668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003671 }
3672
Ta-wei Yen87c49842016-05-13 21:19:52 -07003673 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003674 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3675 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003676 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3677 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003678 if (!TextUtils.equals(callingPackage, systemDialer)) {
3679 throw new SecurityException("caller must be system dialer");
3680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681
3682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3685 if (phoneAccountHandle == null) {
3686 return null;
3687 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003688 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689 } finally {
3690 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003691 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003692 }
3693
3694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003695 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3696 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003697 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003699 mApp, subId, callingPackage, callingFeatureId,
3700 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003701 return null;
3702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003703
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003704 final long identity = Binder.clearCallingIdentity();
3705 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003710 }
3711
3712 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003713 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3714 VisualVoicemailSmsFilterSettings settings) {
3715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716
3717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003720 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003724 }
3725
3726 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003727 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729
3730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003737 }
3738
3739 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003740 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3741 String callingPackage, int subId) {
3742 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743
3744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003747 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748 } finally {
3749 Binder.restoreCallingIdentity(identity);
3750 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003751 }
3752
3753 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003754 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756
3757 final long identity = Binder.clearCallingIdentity();
3758 try {
3759 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003764 }
3765
3766 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003767 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3768 String callingAttributionTag, int subId, String number, int port, String text,
3769 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003770 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003771 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003772 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003773 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003774 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3775 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003776 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003777
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003778 /**
fionaxu0152e512016-11-14 13:36:14 -08003779 * Sets the voice activation state of a given subId.
3780 */
3781 @Override
3782 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3784 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 final Phone phone = getPhone(subId);
3789 if (phone != null) {
3790 phone.setVoiceActivationState(activationState);
3791 } else {
3792 loge("setVoiceActivationState fails with invalid subId: " + subId);
3793 }
3794 } finally {
3795 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003796 }
3797 }
3798
3799 /**
3800 * Sets the data activation state of a given subId.
3801 */
3802 @Override
3803 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3805 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806
3807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 final Phone phone = getPhone(subId);
3810 if (phone != null) {
3811 phone.setDataActivationState(activationState);
3812 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003813 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 }
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003817 }
3818 }
3819
3820 /**
3821 * Returns the voice activation state of a given subId.
3822 */
3823 @Override
3824 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826
fionaxu0152e512016-11-14 13:36:14 -08003827 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 if (phone != null) {
3831 return phone.getVoiceActivationState();
3832 } else {
3833 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3834 }
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003837 }
3838 }
3839
3840 /**
3841 * Returns the data activation state of a given subId.
3842 */
3843 @Override
3844 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846
fionaxu0152e512016-11-14 13:36:14 -08003847 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 if (phone != null) {
3851 return phone.getDataActivationState();
3852 } else {
3853 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3854 }
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003857 }
3858 }
3859
3860 /**
Wink Saville36469e72014-06-11 15:17:00 -07003861 * Returns the unread count of voicemails for a subId
3862 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003864 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3865 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003867 mApp, subId, callingPackage, callingFeatureId,
3868 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003869 return 0;
3870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 final Phone phone = getPhone(subId);
3874 if (phone != null) {
3875 return phone.getVoiceMessageCount();
3876 } else {
3877 return 0;
3878 }
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003882 }
3883
3884 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003885 * returns true, if the device is in a state where both voice and data
3886 * are supported simultaneously. This can change based on location or network condition.
3887 */
3888 @Override
3889 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890 final long identity = Binder.clearCallingIdentity();
3891 try {
3892 final Phone phone = getPhone(subId);
3893 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
3896 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003897 }
3898
3899 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003900 * Send the dialer code if called from the current default dialer or the caller has
3901 * carrier privilege.
3902 * @param inputCode The dialer code to send
3903 */
3904 @Override
3905 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003906 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003907 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003908 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3909 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003910 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003911 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003912 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914
3915 final long identity = Binder.clearCallingIdentity();
3916 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003917 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
fionaxu235cc5e2017-03-06 22:25:57 -08003921 }
3922
Pengquan Menga1bb6272018-09-06 09:59:22 -07003923 @Override
3924 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003925 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003926 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003927 mApp, subId, "getNetworkSelectionMode");
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 if (!isActiveSubscription(subId)) {
3931 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3932 }
3933 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003936 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003937 }
3938
Brad Ebinger35c841c2018-10-01 10:40:55 -07003939 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003940 public boolean isInEmergencySmsMode() {
3941 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 for (Phone phone : PhoneFactory.getPhones()) {
3945 if (phone.isInEmergencySmsMode()) {
3946 return true;
3947 }
3948 }
3949 } finally {
3950 Binder.restoreCallingIdentity(identity);
3951 }
3952 return false;
3953 }
3954
shilu366312e2019-12-17 09:28:10 -08003955 /**
3956 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3957 * @param subId The subscription to use to check the configuration.
3958 * @param c The callback that will be used to send the result.
3959 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003960 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003961 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3962 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003963 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003964 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003965
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003966 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3967 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3968 "IMS not available on device.");
3969 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 final long token = Binder.clearCallingIdentity();
3971 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003972 int slotId = getSlotIndexOrException(subId);
3973 verifyImsMmTelConfiguredOrThrow(slotId);
3974 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003975 } catch (ImsException e) {
3976 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 } finally {
3978 Binder.restoreCallingIdentity(token);
3979 }
3980 }
3981
shilu366312e2019-12-17 09:28:10 -08003982 /**
3983 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3984 * @param subId The subscription to use to check the configuration.
3985 * @param c The callback that will be used to send the result.
3986 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003988 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003989 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003990 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003991 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3992 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3993 }
Meng Wangafbc5852019-09-19 17:37:13 -07003994 final long token = Binder.clearCallingIdentity();
3995 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003996 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3997 .removeRegistrationCallbackForSubscription(c, subId);
3998 } catch (ImsException e) {
3999 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4000 + "is inactive, ignoring unregister.");
4001 // If the subscription is no longer active, just return, since the callback
4002 // will already have been removed internally.
4003 } finally {
4004 Binder.restoreCallingIdentity(token);
4005 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 }
4007
Brad Ebingera34a6c22019-10-22 17:36:18 -07004008 /**
4009 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4010 */
4011 @Override
4012 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4013 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4014 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4015 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4016 "IMS not available on device.");
4017 }
4018 final long token = Binder.clearCallingIdentity();
4019 try {
4020 Phone phone = getPhone(subId);
4021 if (phone == null) {
4022 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4023 + subId + "'");
4024 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4025 }
4026 phone.getImsRegistrationState(regState -> {
4027 try {
4028 consumer.accept((regState == null)
4029 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4030 } catch (RemoteException e) {
4031 // Ignore if the remote process is no longer available to call back.
4032 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4033 }
4034 });
4035 } finally {
4036 Binder.restoreCallingIdentity(token);
4037 }
4038 }
4039
4040 /**
4041 * Get the transport type for the IMS service registration state.
4042 */
4043 @Override
4044 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004045 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004046 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004047 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4048 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4049 "IMS not available on device.");
4050 }
4051 final long token = Binder.clearCallingIdentity();
4052 try {
4053 Phone phone = getPhone(subId);
4054 if (phone == null) {
4055 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4056 + subId + "'");
4057 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4058 }
4059 phone.getImsRegistrationTech(regTech -> {
4060 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4061 int regTechConverted = (regTech == null)
4062 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4063 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4064 regTechConverted);
4065 try {
4066 consumer.accept(regTechConverted);
4067 } catch (RemoteException e) {
4068 // Ignore if the remote process is no longer available to call back.
4069 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4070 }
4071 });
4072 } finally {
4073 Binder.restoreCallingIdentity(token);
4074 }
4075 }
4076
shilu366312e2019-12-17 09:28:10 -08004077 /**
4078 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4079 * @param subId The subscription to use to check the configuration.
4080 * @param c The callback that will be used to send the result.
4081 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004083 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4084 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004085 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004086 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004087 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4088 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4089 "IMS not available on device.");
4090 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 final long token = Binder.clearCallingIdentity();
4092 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004093 int slotId = getSlotIndexOrException(subId);
4094 verifyImsMmTelConfiguredOrThrow(slotId);
4095 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 } catch (ImsException e) {
4097 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 } finally {
4099 Binder.restoreCallingIdentity(token);
4100 }
4101 }
4102
shilu366312e2019-12-17 09:28:10 -08004103 /**
4104 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4105 * @param subId The subscription to use to check the configuration.
4106 * @param c The callback that will be used to send the result.
4107 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004109 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004110 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004111 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004112 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4113 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4114 }
Meng Wangafbc5852019-09-19 17:37:13 -07004115
4116 final long token = Binder.clearCallingIdentity();
4117 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004118 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004119 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004120 } catch (ImsException e) {
4121 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4122 + "is inactive, ignoring unregister.");
4123 // If the subscription is no longer active, just return, since the callback
4124 // will already have been removed internally.
4125 } finally {
4126 Binder.restoreCallingIdentity(token);
4127 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 }
4129
4130 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004131 public boolean isCapable(int subId, int capability, int regTech) {
4132 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 final long token = Binder.clearCallingIdentity();
4134 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004135 int slotId = getSlotIndexOrException(subId);
4136 verifyImsMmTelConfiguredOrThrow(slotId);
4137 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004138 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4140 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004141 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004142 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4143 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 } finally {
4145 Binder.restoreCallingIdentity(token);
4146 }
4147 }
4148
4149 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004150 public boolean isAvailable(int subId, int capability, int regTech) {
4151 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 final long token = Binder.clearCallingIdentity();
4153 try {
4154 Phone phone = getPhone(subId);
4155 if (phone == null) return false;
4156 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004157 } catch (com.android.ims.ImsException e) {
4158 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4159 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 } finally {
4161 Binder.restoreCallingIdentity(token);
4162 }
4163 }
4164
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004165 /**
4166 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4167 * subscription.
4168 * @param subId The subscription to use to check the configuration.
4169 * @param callback The callback that will be used to send the result.
4170 * @param capability The MmTelFeature capability that will be used to send the result.
4171 * @param transportType The transport type of the MmTelFeature capability.
4172 */
4173 @Override
4174 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4175 int transportType) {
4176 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4177 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4178 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4179 "IMS not available on device.");
4180 }
4181 final long token = Binder.clearCallingIdentity();
4182 try {
4183 int slotId = getSlotIndex(subId);
4184 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4185 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4186 + subId + "'");
4187 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4188 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004189 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004190 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4191 transportType, aBoolean -> {
4192 try {
4193 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4194 } catch (RemoteException e) {
4195 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4196 + "running. Ignore");
4197 }
4198 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004199 } catch (ImsException e) {
4200 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004201 } finally {
4202 Binder.restoreCallingIdentity(token);
4203 }
4204 }
4205
shilu366312e2019-12-17 09:28:10 -08004206 /**
4207 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4208 * @param subId The subscription to use to check the configuration.
4209 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 @Override
4211 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004212 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004213 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004214
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 final long token = Binder.clearCallingIdentity();
4216 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004217 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004218 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004219 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004220 } catch (ImsException e) {
4221 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 } finally {
4223 Binder.restoreCallingIdentity(token);
4224 }
4225 }
4226
4227 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004228 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004230 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 final long identity = Binder.clearCallingIdentity();
4232 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004233 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004234 // This setting doesn't require an active ImsService connection, so do not verify. The
4235 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004236 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004237 } catch (ImsException e) {
4238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
4242 }
4243
shilu366312e2019-12-17 09:28:10 -08004244 /**
4245 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4246 * @param subId The subscription to use to check the configuration.
4247 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004248 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004249 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004250 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004251 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 final long identity = Binder.clearCallingIdentity();
4253 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004254 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004255 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004256 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004257 } catch (ImsException e) {
4258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
4262 }
4263
4264 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004265 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004267 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 final long identity = Binder.clearCallingIdentity();
4269 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004270 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004271 // This setting doesn't require an active ImsService connection, so do not verify. The
4272 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004273 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004274 } catch (ImsException e) {
4275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
4279 }
4280
shilu366312e2019-12-17 09:28:10 -08004281 /**
4282 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4283 * @param subId The subscription to use to check the configuration.
4284 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 @Override
4286 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004287 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004288 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 final long identity = Binder.clearCallingIdentity();
4290 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004291 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004292 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004293 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004294 } catch (ImsException e) {
4295 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
4299 }
4300
4301 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004302 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004304 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 final long identity = Binder.clearCallingIdentity();
4306 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004307 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004308 // This setting doesn't require an active ImsService connection, so do not verify. The
4309 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004310 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004311 } catch (ImsException e) {
4312 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
4316 }
4317
shilu366312e2019-12-17 09:28:10 -08004318 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004319 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4320 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4321 * @param subId The subscription to use to check the configuration.
4322 */
4323 @Override
4324 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004325 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004326 mApp, subId, "isCrossSimCallingEnabledByUser");
4327 final long identity = Binder.clearCallingIdentity();
4328 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004329 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004330 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004331 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004332 } catch (ImsException e) {
4333 throw new ServiceSpecificException(e.getCode());
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
4337 }
4338
4339 /**
4340 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4341 * Requires MODIFY_PHONE_STATE permission.
4342 * @param subId The subscription to use to check the configuration.
4343 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4344 * false otherwise
4345 */
4346 @Override
4347 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4349 "setCrossSimCallingEnabled");
4350 final long identity = Binder.clearCallingIdentity();
4351 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004352 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004353 // This setting doesn't require an active ImsService connection, so do not verify. The
4354 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004355 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004356 } catch (ImsException e) {
4357 throw new ServiceSpecificException(e.getCode());
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
4363 /**
shilu366312e2019-12-17 09:28:10 -08004364 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4365 * @param subId The subscription to use to check the configuration.
4366 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004368
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004370 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004371 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 final long identity = Binder.clearCallingIdentity();
4373 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004375 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004377 } catch (ImsException e) {
4378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
4382 }
4383
4384 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004385 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004387 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004388 final long identity = Binder.clearCallingIdentity();
4389 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004390 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004391 // This setting doesn't require an active ImsService connection, so do not verify. The
4392 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004394 } catch (ImsException e) {
4395 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
4399 }
4400
4401 @Override
4402 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4404 "setVoWiFiNonPersistent");
4405 final long identity = Binder.clearCallingIdentity();
4406 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004407 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004408 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004409 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004410 } catch (ImsException e) {
4411 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
4415 }
4416
shilu366312e2019-12-17 09:28:10 -08004417 /**
4418 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4419 * @param subId The subscription to use to check the configuration.
4420 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004421 @Override
4422 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004423 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004424 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004425 final long identity = Binder.clearCallingIdentity();
4426 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004427 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004428 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004429 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004430 } catch (ImsException e) {
4431 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
4435 }
4436
4437 @Override
4438 public void setVoWiFiModeSetting(int subId, int mode) {
4439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4440 "setVoWiFiModeSetting");
4441 final long identity = Binder.clearCallingIdentity();
4442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004444 // This setting doesn't require an active ImsService connection, so do not verify. The
4445 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004446 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004447 } catch (ImsException e) {
4448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
4452 }
4453
4454 @Override
4455 public int getVoWiFiRoamingModeSetting(int subId) {
4456 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4457 final long identity = Binder.clearCallingIdentity();
4458 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004460 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004462 } catch (ImsException e) {
4463 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
4467 }
4468
4469 @Override
4470 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4472 "setVoWiFiRoamingModeSetting");
4473 final long identity = Binder.clearCallingIdentity();
4474 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004475 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004476 // This setting doesn't require an active ImsService connection, so do not verify. The
4477 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004479 } catch (ImsException e) {
4480 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
4484 }
4485
4486 @Override
4487 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4489 "setRttCapabilityEnabled");
4490 final long identity = Binder.clearCallingIdentity();
4491 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004492 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004493 // This setting doesn't require an active ImsService connection, so do not verify. The
4494 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004496 } catch (ImsException e) {
4497 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
4501 }
4502
shilu366312e2019-12-17 09:28:10 -08004503 /**
4504 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4505 * @param subId The subscription to use to check the configuration.
4506 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 @Override
4508 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004509 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004510 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004511 final long identity = Binder.clearCallingIdentity();
4512 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004513 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004514 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004516 } catch (ImsException e) {
4517 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 }
4522
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004523 @Override
4524 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4525 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004526
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004527 final long identity = Binder.clearCallingIdentity();
4528 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004529 if (!isImsAvailableOnDevice()) {
4530 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4531 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004532 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004533 int slotId = getSlotIndexOrException(subId);
4534 verifyImsMmTelConfiguredOrThrow(slotId);
4535 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004536 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004537 } catch (ImsException e) {
4538 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004539 } finally {
4540 Binder.restoreCallingIdentity(identity);
4541 }
4542 }
4543
4544 @Override
4545 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4546 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004547
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004548 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004549 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4550 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4551 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004552 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004553 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004554 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004555 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004556 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4557 + "is inactive, ignoring unregister.");
4558 // If the subscription is no longer active, just return, since the callback will already
4559 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
4563 }
4564
joonhunshin2c3e4232021-11-28 07:32:01 +00004565 @Override
4566 public void registerFeatureProvisioningChangedCallback(int subId,
4567 IFeatureProvisioningCallback callback) {
4568 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4569 mApp, subId, "registerFeatureProvisioningChangedCallback");
4570
4571 final long identity = Binder.clearCallingIdentity();
4572 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4573 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4574 }
4575
4576 ImsProvisioningController.getInstance()
4577 .addFeatureProvisioningChangedCallback(subId, callback);
4578
4579 Binder.restoreCallingIdentity(identity);
4580 }
4581
4582 @Override
4583 public void unregisterFeatureProvisioningChangedCallback(int subId,
4584 IFeatureProvisioningCallback callback) {
4585 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4586 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4587
4588 final long identity = Binder.clearCallingIdentity();
4589 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4590 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4591 }
4592
4593 ImsProvisioningController.getInstance()
4594 .removeFeatureProvisioningChangedCallback(subId, callback);
4595
4596 Binder.restoreCallingIdentity(identity);
4597 }
allenwtsu99c623b2020-01-03 18:24:23 +08004598
4599 private void checkModifyPhoneStatePermission(int subId, String message) {
4600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4601 message);
4602 }
4603
4604 private boolean isImsProvisioningRequired(int subId, int capability,
4605 boolean isMmtelCapability) {
4606 Phone phone = getPhone(subId);
4607 if (phone == null) {
4608 loge("phone instance null for subid " + subId);
4609 return false;
4610 }
4611 if (isMmtelCapability) {
4612 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4613 return false;
4614 }
4615 } else {
4616 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4617 return false;
4618 }
4619 }
4620 return true;
4621 }
4622
4623 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004624 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004625 boolean isProvisioned) {
4626 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4627
4628 final long identity = Binder.clearCallingIdentity();
4629 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004630 ImsProvisioningController.getInstance()
4631 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4632 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004633 } finally {
4634 Binder.restoreCallingIdentity(identity);
4635 }
allenwtsu99c623b2020-01-03 18:24:23 +08004636 }
4637
4638
4639 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004640 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4641 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4642 mApp, subId, "getRcsProvisioningStatusForCapability");
4643
allenwtsu99c623b2020-01-03 18:24:23 +08004644 final long identity = Binder.clearCallingIdentity();
4645 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004646 return ImsProvisioningController.getInstance()
4647 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
4651 }
4652
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004653 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4655 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004656 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshin2c3e4232021-11-28 07:32:01 +00004657
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004658 final long identity = Binder.clearCallingIdentity();
4659 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004660 ImsProvisioningController.getInstance()
4661 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
4665 }
4666
4667 @Override
4668 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshin2c3e4232021-11-28 07:32:01 +00004669 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4670 mApp, subId, "getProvisioningStatusForCapability");
4671
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004672 final long identity = Binder.clearCallingIdentity();
4673 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004674 return ImsProvisioningController.getInstance()
4675 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004676
4677 } finally {
4678 Binder.restoreCallingIdentity(identity);
4679 }
4680 }
4681
4682 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004683 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4684 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4685 mApp, subId, "isProvisioningRequiredForCapability");
4686
4687 final long identity = Binder.clearCallingIdentity();
4688 try {
4689 return ImsProvisioningController.getInstance()
4690 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4691 } finally {
4692 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004693 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004694 }
4695
4696 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004697 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4698 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4699 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004700
joonhunshin2c3e4232021-11-28 07:32:01 +00004701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 return ImsProvisioningController.getInstance()
4704 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 }
4709
4710 private static String getMmTelProvisioningKey(int subId, int tech) {
4711 // resulting key is provision_ims_mmtel_{subId}_{tech}
4712 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4713 }
4714
4715 /**
4716 * Query CarrierConfig to see if the specified capability requires provisioning for the
4717 * carrier associated with the subscription id.
4718 */
4719 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4720 int capability) {
4721 CarrierConfigManager configManager = new CarrierConfigManager(context);
4722 PersistableBundle c = configManager.getConfigForSubId(subId);
4723 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004724 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004725 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4726 false);
4727 boolean requireVoiceVtProvisioning = c.getBoolean(
4728 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4729
4730 // First check to make sure that the capability requires provisioning.
4731 switch (capability) {
4732 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4733 // intentional fallthrough
4734 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4735 if (requireVoiceVtProvisioning) {
4736 // Voice and Video requires provisioning
4737 return true;
4738 }
4739 break;
4740 }
4741 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4742 if (requireUtProvisioning) {
4743 // UT requires provisioning
4744 return true;
4745 }
4746 break;
4747 }
4748 }
4749 return false;
4750 }
4751
allenwtsu99c623b2020-01-03 18:24:23 +08004752 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4753 int capability) {
4754 CarrierConfigManager configManager = new CarrierConfigManager(context);
4755 PersistableBundle c = configManager.getConfigForSubId(subId);
4756
4757 boolean requireRcsProvisioning = c.getBoolean(
4758 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4759
4760 // First check to make sure that the capability requires provisioning.
4761 switch (capability) {
4762 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4763 // intentional fallthrough
4764 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4765 if (requireRcsProvisioning) {
4766 // OPTION or PRESENCE requires provisioning
4767 return true;
4768 }
4769 break;
4770 }
4771 }
4772 return false;
4773 }
4774
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004775 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004776 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004777 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4778 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4779 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004780 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4781 mApp, subId, "getImsProvisioningInt");
4782
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004783 final long identity = Binder.clearCallingIdentity();
4784 try {
4785 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004786 int slotId = getSlotIndex(subId);
4787 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4788 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4789 + subId + "' for key:" + key);
4790 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4791 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004792
4793 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4794 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4795 return retVal;
4796 }
4797
calvinpanb5a34062021-02-08 19:59:36 +08004798 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004799 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004800 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4801 + subId + "' for key:" + key);
4802 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
4806 }
4807
4808 @Override
4809 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004810 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4811 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4812 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004813 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4814 mApp, subId, "getImsProvisioningString");
4815
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004816 final long identity = Binder.clearCallingIdentity();
4817 try {
4818 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004819 int slotId = getSlotIndex(subId);
4820 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4821 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4822 + subId + "' for key:" + key);
4823 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4824 }
calvinpanb5a34062021-02-08 19:59:36 +08004825 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004826 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004827 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4828 + subId + "' for key:" + key);
4829 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004830 } finally {
4831 Binder.restoreCallingIdentity(identity);
4832 }
4833 }
4834
4835 @Override
4836 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004837 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4838 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4839 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4841 "setImsProvisioningInt");
joonhunshin2c3e4232021-11-28 07:32:01 +00004842
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004843 final long identity = Binder.clearCallingIdentity();
4844 try {
4845 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004846 int slotId = getSlotIndex(subId);
4847 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4848 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4849 + subId + "' for key:" + key);
4850 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4851 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004852
4853 int retVal = ImsProvisioningController.getInstance()
4854 .setProvisioningValue(subId, key, value);
4855 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4856 return retVal;
4857 }
4858
calvinpanb5a34062021-02-08 19:59:36 +08004859 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4860 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004861 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004862 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004863 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
4867 }
4868
4869 @Override
4870 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004871 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4872 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4873 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4875 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004879 int slotId = getSlotIndex(subId);
4880 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4881 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4882 + subId + "' for key:" + key);
4883 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4884 }
calvinpanb5a34062021-02-08 19:59:36 +08004885 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4886 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004887 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004888 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004889 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004890 } finally {
4891 Binder.restoreCallingIdentity(identity);
4892 }
4893 }
4894
Brad Ebinger919631e2021-06-02 17:46:35 -07004895 /**
4896 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4897 * for the given slot ID or no ImsResolver instance has been created.
4898 * @param slotId The slot ID that the IMS service is created for.
4899 * @throws ImsException If there is no ImsService configured for this slot.
4900 */
4901 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4902 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4903 ImsFeature.FEATURE_MMTEL)) {
4904 throw new ImsException("This subscription does not support MMTEL over IMS",
4905 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4906 }
4907 }
4908
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004909 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004910 int slotId = SubscriptionManager.getSlotIndex(subId);
4911 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004912 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4913 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004914 }
4915 return slotId;
4916 }
4917
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004918 private int getSlotIndex(int subId) {
4919 int slotId = SubscriptionManager.getSlotIndex(subId);
4920 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4921 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4922 }
4923 return slotId;
4924 }
4925
Wink Saville36469e72014-06-11 15:17:00 -07004926 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004927 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004928 */
4929 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004930 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4931 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004932 try {
4933 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4934 } catch (SecurityException se) {
4935 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4936 throw new SecurityException("Package " + callingPackage + " does not belong to "
4937 + Binder.getCallingUid());
4938 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004939 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004940 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004941 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004942 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004943 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004944 mApp, subId, callingPackage, callingFeatureId,
4945 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004946 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4947 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 final long identity = Binder.clearCallingIdentity();
4950 try {
4951 final Phone phone = getPhone(subId);
4952 if (phone != null) {
4953 return phone.getServiceState().getDataNetworkType();
4954 } else {
4955 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4956 }
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004960 }
4961
4962 /**
4963 * Returns the data network type
4964 */
4965 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004966 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004967 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4968 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004969 }
4970
4971 /**
4972 * Returns the data network type for a subId
4973 */
4974 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004975 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4976 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07004977 String functionName = "getDataNetworkTypeForSubscriber";
4978 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
4979 mApp, functionName)) {
4980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4981 mApp, subId, callingPackage, callingFeatureId, functionName)) {
4982 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4983 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004984 }
4985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 final long identity = Binder.clearCallingIdentity();
4987 try {
4988 final Phone phone = getPhone(subId);
4989 if (phone != null) {
4990 return phone.getServiceState().getDataNetworkType();
4991 } else {
4992 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4993 }
4994 } finally {
4995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004997 }
4998
4999 /**
Wink Saville36469e72014-06-11 15:17:00 -07005000 * Returns the Voice network type for a subId
5001 */
5002 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005003 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5004 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005005 String functionName = "getVoiceNetworkTypeForSubscriber";
5006 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5007 mApp, functionName)) {
5008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5009 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5010 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5011 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005012 }
5013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 final Phone phone = getPhone(subId);
5017 if (phone != null) {
5018 return phone.getServiceState().getVoiceNetworkType();
5019 } else {
5020 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5021 }
5022 } finally {
5023 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005025 }
5026
5027 /**
5028 * @return true if a ICC card is present
5029 */
5030 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005031 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005032 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5033 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005034 }
5035
5036 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005037 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005038 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005039 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005040 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 final long identity = Binder.clearCallingIdentity();
5042 try {
5043 final Phone phone = PhoneFactory.getPhone(slotIndex);
5044 if (phone != null) {
5045 return phone.getIccCard().hasIccCard();
5046 } else {
5047 return false;
5048 }
5049 } finally {
5050 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005052 }
5053
5054 /**
5055 * Return if the current radio is LTE on CDMA. This
5056 * is a tri-state return value as for a period of time
5057 * the mode may be unknown.
5058 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005059 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005060 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005061 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005062 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005064 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5065 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5066 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005067 }
5068
Sanket Padawe356d7632015-06-22 14:03:32 -07005069 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005070 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5071 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005072 try {
5073 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5074 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005075 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5076 }
5077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 final Phone phone = getPhone(subId);
5081 if (phone == null) {
5082 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5083 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005084 return TelephonyProperties.lte_on_cdma_device()
5085 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 }
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005089 }
Wink Saville36469e72014-06-11 15:17:00 -07005090 }
5091
Wink Saville36469e72014-06-11 15:17:00 -07005092 /**
5093 * {@hide}
5094 * Returns Default subId, 0 in the case of single standby.
5095 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005096 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005097 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005098 }
5099
Shishir Agrawala9f32182016-04-12 12:00:16 -07005100 private int getSlotForDefaultSubscription() {
5101 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5102 }
5103
Wink Savilleb564aae2014-10-23 10:18:09 -07005104 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005105 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005106 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005107
Pengquan Menge92a50d2018-09-21 15:54:48 -07005108 private boolean isActiveSubscription(int subId) {
5109 return mSubscriptionController.isActiveSubId(subId);
5110 }
5111
Ihab Awadf2177b72013-11-25 13:33:23 -08005112 /**
5113 * @see android.telephony.TelephonyManager.WifiCallingChoices
5114 */
5115 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 final long identity = Binder.clearCallingIdentity();
5117 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005118 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5120 getWhenToMakeWifiCallsDefaultPreference());
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
5123 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005124 }
5125
5126 /**
5127 * @see android.telephony.TelephonyManager.WifiCallingChoices
5128 */
5129 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130 final long identity = Binder.clearCallingIdentity();
5131 try {
5132 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005133 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5135 } finally {
5136 Binder.restoreCallingIdentity(identity);
5137 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005138 }
5139
Sailesh Nepald1e68152013-12-12 19:08:02 -08005140 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005141 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005142 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005143 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005144
Jordan Liu4c733742019-02-28 12:03:40 -08005145 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5146 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5147 if (phoneId == -1) {
5148 throw new IllegalArgumentException("Given slot index: " + slotIndex
5149 + " does not correspond to an active phone");
5150 }
5151 return PhoneFactory.getPhone(phoneId);
5152 }
5153
Shishir Agrawal566b7612013-10-28 14:41:00 -07005154 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005155 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5156 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5158 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005160 if (DBG) {
5161 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5162 }
5163 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5164 p2);
5165 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005166
Jordan Liu4c733742019-02-28 12:03:40 -08005167
5168 @Override
5169 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5170 int slotIndex, String callingPackage, String aid, int p2) {
5171 enforceModifyPermission();
5172 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5173 if (DBG) {
5174 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5175 }
5176 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5177 callingPackage, aid, p2);
5178 }
5179
5180 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5181 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 final long identity = Binder.clearCallingIdentity();
5183 try {
5184 if (TextUtils.equals(ISDR_AID, aid)) {
5185 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005186 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5187 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 if (bestComponent == null
5189 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5190 loge("The calling package is not allowed to access ISD-R.");
5191 throw new SecurityException(
5192 "The calling package is not allowed to access ISD-R.");
5193 }
Derek Tan740e1672017-06-27 14:56:27 -07005194 }
Derek Tan740e1672017-06-27 14:56:27 -07005195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005197 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5198 null /* workSource */);
5199 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200 return response;
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005204 }
5205
5206 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005207 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5209 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005210 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5211 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5212 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005213
Jordan Liu4c733742019-02-28 12:03:40 -08005214 @Override
5215 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5216 enforceModifyPermission();
5217 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5218 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5219 channel);
5220 }
5221
5222 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 if (channel < 0) {
5226 return false;
5227 }
Jordan Liu4c733742019-02-28 12:03:40 -08005228 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5229 null /* workSource */);
5230 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 return success;
5232 } finally {
5233 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005234 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005235 }
5236
5237 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005238 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005239 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5241 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005242 if (DBG) {
5243 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5244 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5245 + p3 + " data=" + data);
5246 }
5247 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5248 command, p1, p2, p3, data);
5249 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005250
Jordan Liu4c733742019-02-28 12:03:40 -08005251 @Override
5252 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5253 int command, int p1, int p2, int p3, String data) {
5254 enforceModifyPermission();
5255 if (DBG) {
5256 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5257 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5258 + p3 + " data=" + data);
5259 }
5260 return iccTransmitApduLogicalChannelWithPermission(
5261 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5262 data);
5263 }
5264
5265 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5266 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267 final long identity = Binder.clearCallingIdentity();
5268 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005269 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 return "";
5271 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005274 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5275 null /* workSource */);
5276 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 // Append the returned status code to the end of the response payload.
5279 String s = Integer.toHexString(
5280 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5281 if (response.payload != null) {
5282 s = IccUtils.bytesToHexString(response.payload) + s;
5283 }
5284 return s;
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005287 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005288 }
Jake Hambye994d462014-02-03 13:10:13 -08005289
Evan Charltonc66da362014-05-16 14:06:40 -07005290 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005291 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5292 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5294 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005296 if (DBG) {
5297 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5298 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5299 }
5300 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5301 cla, command, p1, p2, p3, data);
5302 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005303
Jordan Liu4c733742019-02-28 12:03:40 -08005304 @Override
5305 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5306 int command, int p1, int p2, int p3, String data) {
5307 enforceModifyPermission();
5308 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5309 if (DBG) {
5310 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5311 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5312 + " data=" + data);
5313 }
5314
5315 return iccTransmitApduBasicChannelWithPermission(
5316 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5317 p2, p3, data);
5318 }
5319
5320 // open APDU basic channel assuming the caller has sufficient permissions
5321 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5322 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 final long identity = Binder.clearCallingIdentity();
5324 try {
5325 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5326 && TextUtils.equals(ISDR_AID, data)) {
5327 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005328 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5329 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 if (bestComponent == null
5331 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5332 loge("The calling package is not allowed to select ISD-R.");
5333 throw new SecurityException(
5334 "The calling package is not allowed to select ISD-R.");
5335 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005336 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005339 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5340 null /* workSource */);
5341 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 // Append the returned status code to the end of the response payload.
5344 String s = Integer.toHexString(
5345 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5346 if (response.payload != null) {
5347 s = IccUtils.bytesToHexString(response.payload) + s;
5348 }
5349 return s;
5350 } finally {
5351 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005352 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005353 }
5354
5355 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005356 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005357 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5359 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 final long identity = Binder.clearCallingIdentity();
5362 try {
5363 if (DBG) {
5364 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5365 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5366 }
5367
5368 IccIoResult response =
5369 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5370 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5371 subId);
5372
5373 if (DBG) {
5374 log("Exchange SIM_IO [R]" + response);
5375 }
5376
5377 byte[] result = null;
5378 int length = 2;
5379 if (response.payload != null) {
5380 length = 2 + response.payload.length;
5381 result = new byte[length];
5382 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5383 } else {
5384 result = new byte[length];
5385 }
5386
5387 result[length - 1] = (byte) response.sw2;
5388 result[length - 2] = (byte) response.sw1;
5389 return result;
5390 } finally {
5391 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005392 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005393 }
5394
Nathan Haroldb3014052017-01-25 15:57:32 -08005395 /**
5396 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5397 * on a particular subscription
5398 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005399 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5400 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005402 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005403 return null;
5404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405
5406 final long identity = Binder.clearCallingIdentity();
5407 try {
5408 if (appType != TelephonyManager.APPTYPE_USIM
5409 && appType != TelephonyManager.APPTYPE_SIM) {
5410 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5411 return null;
5412 }
5413 Object response = sendRequest(
5414 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5415 if (response instanceof String[]) {
5416 return (String[]) response;
5417 }
yincheng zhao2737e882019-09-06 17:06:54 -07005418 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005420 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 } finally {
5422 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005423 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005424 }
5425
yincheng zhao2737e882019-09-06 17:06:54 -07005426 /**
5427 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5428 * subscription.
5429 *
5430 * @param subId the id of the subscription.
5431 * @param appType the uicc app type, must be USIM or SIM.
5432 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5433 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005434 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005435 * @return number of fplmns that is successfully written to the SIM.
5436 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005437 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5438 String callingFeatureId) {
5439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5440 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005441 if (DBG) logv("no permissions for setForbiddenplmns");
5442 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5443 }
5444 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5445 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5446 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5447 }
5448 if (fplmns == null) {
5449 throw new IllegalArgumentException("Fplmn List provided is null");
5450 }
5451 for (String fplmn : fplmns) {
5452 if (!CellIdentity.isValidPlmn(fplmn)) {
5453 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5454 }
5455 }
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
5458 Object response = sendRequest(
5459 CMD_SET_FORBIDDEN_PLMNS,
5460 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5461 subId);
5462 return (int) response;
5463 } finally {
5464 Binder.restoreCallingIdentity(identity);
5465 }
5466 }
5467
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005468 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005469 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5471 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 final long identity = Binder.clearCallingIdentity();
5474 try {
5475 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5476 if (response.payload == null) {
5477 return "";
5478 }
Evan Charltonc66da362014-05-16 14:06:40 -07005479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 // Append the returned status code to the end of the response payload.
5481 String s = Integer.toHexString(
5482 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5483 s = IccUtils.bytesToHexString(response.payload) + s;
5484 return s;
5485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
Evan Charltonc66da362014-05-16 14:06:40 -07005488 }
5489
Jake Hambye994d462014-02-03 13:10:13 -08005490 /**
5491 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5492 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5493 *
5494 * @param itemID the ID of the item to read
5495 * @return the NV item as a String, or null on error.
5496 */
5497 @Override
5498 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005499 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5501 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502
5503 final long identity = Binder.clearCallingIdentity();
5504 try {
5505 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005506 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5508 return value;
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
Jake Hambye994d462014-02-03 13:10:13 -08005512 }
5513
5514 /**
5515 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5516 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5517 *
5518 * @param itemID the ID of the item to read
5519 * @param itemValue the value to write, as a String
5520 * @return true on success; false on any failure
5521 */
5522 @Override
5523 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005524 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5526 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527
5528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5531 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005532 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5534 return success;
5535 } finally {
5536 Binder.restoreCallingIdentity(identity);
5537 }
Jake Hambye994d462014-02-03 13:10:13 -08005538 }
5539
5540 /**
5541 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5542 * Used for device configuration by some CDMA operators.
5543 *
5544 * @param preferredRoamingList byte array containing the new PRL
5545 * @return true on success; false on any failure
5546 */
5547 @Override
5548 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5550 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551
5552 final long identity = Binder.clearCallingIdentity();
5553 try {
5554 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5555 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5556 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5557 return success;
5558 } finally {
5559 Binder.restoreCallingIdentity(identity);
5560 }
Jake Hambye994d462014-02-03 13:10:13 -08005561 }
5562
5563 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005564 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005565 * Used for device configuration by some CDMA operators.
5566 *
chen xu6dac5ab2018-10-26 17:39:23 -07005567 * @param slotIndex - device slot.
5568 *
Jake Hambye994d462014-02-03 13:10:13 -08005569 * @return true on success; false on any failure
5570 */
5571 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005572 public boolean resetModemConfig(int slotIndex) {
5573 Phone phone = PhoneFactory.getPhone(slotIndex);
5574 if (phone != null) {
5575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5576 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577
chen xu6dac5ab2018-10-26 17:39:23 -07005578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5581 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5582 return success;
5583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 }
chen xu6dac5ab2018-10-26 17:39:23 -07005587 return false;
5588 }
5589
5590 /**
5591 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5592 *
5593 * @param slotIndex - device slot.
5594 *
5595 * @return true on success; false on any failure
5596 */
5597 @Override
5598 public boolean rebootModem(int slotIndex) {
5599 Phone phone = PhoneFactory.getPhone(slotIndex);
5600 if (phone != null) {
5601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, phone.getSubId(), "rebootModem");
5603
5604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5607 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5608 return success;
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
5611 }
5612 }
5613 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005614 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005615
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005616 public String[] getPcscfAddress(String apnType, String callingPackage,
5617 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005618 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5620 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005621 return new String[0];
5622 }
5623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 final long identity = Binder.clearCallingIdentity();
5625 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005626 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629 }
Wink Saville36469e72014-06-11 15:17:00 -07005630 }
5631
Brad Ebinger51f743a2017-01-23 13:50:20 -08005632 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005633 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5634 * {@link #disableIms(int)}.
5635 * @param slotIndex device slot.
5636 */
5637 public void resetIms(int slotIndex) {
5638 enforceModifyPermission();
5639
5640 final long identity = Binder.clearCallingIdentity();
5641 try {
5642 if (mImsResolver == null) {
5643 // may happen if the does not support IMS.
5644 return;
5645 }
5646 mImsResolver.disableIms(slotIndex);
5647 mImsResolver.enableIms(slotIndex);
5648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
5651 }
5652
5653 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005654 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5655 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005656 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005657 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659
5660 final long identity = Binder.clearCallingIdentity();
5661 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005662 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005663 // may happen if the device does not support IMS.
5664 return;
5665 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005666 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005670 }
5671
5672 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005673 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5674 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005675 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005676 public void disableIms(int slotId) {
5677 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678
5679 final long identity = Binder.clearCallingIdentity();
5680 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005681 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005682 // may happen if the device does not support IMS.
5683 return;
5684 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005685 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 } finally {
5687 Binder.restoreCallingIdentity(identity);
5688 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005689 }
5690
5691 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005692 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5693 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005694 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005695 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005696 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005697 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698
5699 final long identity = Binder.clearCallingIdentity();
5700 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005701 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005702 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5703 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005704 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005705 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 } finally {
5707 Binder.restoreCallingIdentity(identity);
5708 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005709 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005710 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005711 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5712 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005713 @Override
5714 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005715 enforceModifyPermission();
5716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005720 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005721 } finally {
5722 Binder.restoreCallingIdentity(identity);
5723 }
5724 }
5725
5726 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005727 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005728 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005729 */
5730 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005735 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005736 // may happen if the device does not support IMS.
5737 return null;
5738 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005739 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005743 }
5744
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005745 /**
5746 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005747 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005748 */
5749 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5750 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751
5752 final long identity = Binder.clearCallingIdentity();
5753 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005754 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005755 // may happen if the device does not support IMS.
5756 return null;
5757 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005758 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759 } finally {
5760 Binder.restoreCallingIdentity(identity);
5761 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005762 }
5763
Brad Ebinger884c07b2018-02-15 16:17:40 -08005764 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005765 * Sets the ImsService Package Name that Telephony will bind to.
5766 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005767 * @param slotIndex the slot ID that the ImsService should bind for.
5768 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005769 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 * @param featureTypes An integer array of feature types associated with a packageName.
5771 * @param packageName The name of the package that the current configuration will be replaced
5772 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005773 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005774 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005775 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5776 int[] featureTypes, String packageName) {
5777 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5780 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005781 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783 final long identity = Binder.clearCallingIdentity();
5784 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005785 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005786 // may happen if the device does not support IMS.
5787 return false;
5788 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 Map<Integer, String> featureConfig = new HashMap<>();
5790 for (int featureType : featureTypes) {
5791 featureConfig.put(featureType, packageName);
5792 }
5793 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5794 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005798 }
5799
5800 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005801 * Clears any carrier ImsService overrides for the slot index specified that were previously
5802 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5803 *
5804 * This should only be used for testing.
5805 *
5806 * @param slotIndex the slot ID that the ImsService should bind for.
5807 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5808 */
5809 @Override
5810 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5811 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5812 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5813 "clearCarrierImsServiceOverride");
5814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5815 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5816 "clearCarrierImsServiceOverride");
5817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 if (mImsResolver == null) {
5821 // may happen if the device does not support IMS.
5822 return false;
5823 }
5824 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5825 } finally {
5826 Binder.restoreCallingIdentity(identity);
5827 }
5828 }
5829
5830 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005831 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005832 *
5833 * @param slotId The slot that the ImsService is associated with.
5834 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5835 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005836 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005837 * @return the package name of the ImsService configuration.
5838 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5840 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005841 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005843 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005844 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5845 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 final long identity = Binder.clearCallingIdentity();
5848 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005849 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005850 // may happen if the device does not support IMS.
5851 return "";
5852 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005853 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005854 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5855 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005859 }
5860
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005861 /**
5862 * Get the MmTelFeature state associated with the requested subscription id.
5863 * @param subId The subscription that the MmTelFeature is associated with.
5864 * @param callback A callback with an integer containing the
5865 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5866 */
5867 @Override
5868 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5869 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5870 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5871 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5872 "IMS not available on device.");
5873 }
5874 final long token = Binder.clearCallingIdentity();
5875 try {
5876 int slotId = getSlotIndex(subId);
5877 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5878 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5879 + subId + "'");
5880 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5881 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005882 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005883 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5884 try {
5885 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5886 } catch (RemoteException e) {
5887 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5888 + "Ignore");
5889 }
5890 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005891 } catch (ImsException e) {
5892 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005893 } finally {
5894 Binder.restoreCallingIdentity(token);
5895 }
5896 }
5897
Daniel Brightbb5840b2021-01-12 15:48:18 -08005898 /**
5899 * Sets the ims registration state on all valid {@link Phone}s.
5900 */
5901 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005902 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903
5904 final long identity = Binder.clearCallingIdentity();
5905 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005906 // NOTE: Before S, this method only set the default phone.
5907 for (final Phone phone : PhoneFactory.getPhones()) {
5908 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5909 phone.setImsRegistrationState(registered);
5910 }
5911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 } finally {
5913 Binder.restoreCallingIdentity(identity);
5914 }
Wink Saville36469e72014-06-11 15:17:00 -07005915 }
5916
5917 /**
Stuart Scott54788802015-03-30 13:18:01 -07005918 * Set the network selection mode to automatic.
5919 *
5920 */
5921 @Override
5922 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5924 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925
5926 final long identity = Binder.clearCallingIdentity();
5927 try {
shilufc958392020-01-20 11:36:01 -08005928 if (!isActiveSubscription(subId)) {
5929 return;
5930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005932 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5933 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 } finally {
5935 Binder.restoreCallingIdentity(identity);
5936 }
Stuart Scott54788802015-03-30 13:18:01 -07005937 }
5938
Jack Yud10cdd42020-09-28 20:28:01 -07005939 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005940 * Ask the radio to connect to the input network and change selection mode to manual.
5941 *
5942 * @param subId the id of the subscription.
5943 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5944 * the operator to attach to.
5945 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5946 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5947 * normal network selection next time.
5948 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005949 */
5950 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005951 public boolean setNetworkSelectionModeManual(
5952 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5954 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005955
5956 if (!isActiveSubscription(subId)) {
5957 return false;
5958 }
5959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 final long identity = Binder.clearCallingIdentity();
5961 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005962 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005964 if (DBG) {
5965 log("setNetworkSelectionModeManual: subId: " + subId
5966 + " operator: " + operatorInfo);
5967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5969 } finally {
5970 Binder.restoreCallingIdentity(identity);
5971 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005972 }
shilu84f6e8b2019-12-19 13:58:01 -08005973 /**
5974 * Get the manual network selection
5975 *
5976 * @param subId the id of the subscription.
5977 *
5978 * @return the previously saved user selected PLMN
5979 */
5980 @Override
5981 public String getManualNetworkSelectionPlmn(int subId) {
5982 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005983 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005984 mApp, subId, "getManualNetworkSelectionPlmn");
5985
5986 final long identity = Binder.clearCallingIdentity();
5987 try {
5988 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005989 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005990 }
5991
5992 final Phone phone = getPhone(subId);
5993 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005994 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005995 }
5996 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5997 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5998 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
6002 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006003
6004 /**
6005 * Scans for available networks.
6006 */
6007 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006008 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6009 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6011 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006012 LocationAccessPolicy.LocationPermissionResult locationResult =
6013 LocationAccessPolicy.checkLocationPermission(mApp,
6014 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6015 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006016 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006017 .setCallingPid(Binder.getCallingPid())
6018 .setCallingUid(Binder.getCallingUid())
6019 .setMethod("getCellNetworkScanResults")
6020 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006021 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6022 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006023 .build());
6024 switch (locationResult) {
6025 case DENIED_HARD:
6026 throw new SecurityException("Not allowed to access scan results -- location");
6027 case DENIED_SOFT:
6028 return null;
6029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030
Pengquan Menga1bb6272018-09-06 09:59:22 -07006031 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032 try {
6033 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006034 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006039 }
6040
6041 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006042 * Get the call forwarding info, given the call forwarding reason.
6043 */
6044 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006045 public void getCallForwarding(int subId, int callForwardingReason,
6046 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006047 enforceReadPrivilegedPermission("getCallForwarding");
6048 long identity = Binder.clearCallingIdentity();
6049 try {
6050 if (DBG) {
6051 log("getCallForwarding: subId " + subId
6052 + " callForwardingReason" + callForwardingReason);
6053 }
Hall Liu27d24262020-09-18 19:04:59 -07006054
6055 Phone phone = getPhone(subId);
6056 if (phone == null) {
6057 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006058 callback.onError(
6059 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006060 } catch (RemoteException e) {
6061 // ignore
6062 }
6063 return;
6064 }
6065
6066 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6067 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6068 @Override
6069 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6070 try {
6071 callback.onCallForwardingInfoAvailable(info);
6072 } catch (RemoteException e) {
6073 // ignore
6074 }
6075 }
6076
6077 @Override
6078 public void onError(int error) {
6079 try {
6080 callback.onError(error);
6081 } catch (RemoteException e) {
6082 // ignore
6083 }
6084 }
6085 });
6086 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
6090 }
6091
6092 /**
6093 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6094 * reason, the number to forward, and the timeout before the forwarding is attempted.
6095 */
6096 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006097 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6098 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006099 enforceModifyPermission();
6100 long identity = Binder.clearCallingIdentity();
6101 try {
6102 if (DBG) {
6103 log("setCallForwarding: subId " + subId
6104 + " callForwardingInfo" + callForwardingInfo);
6105 }
Hall Liu27d24262020-09-18 19:04:59 -07006106
6107 Phone phone = getPhone(subId);
6108 if (phone == null) {
6109 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006110 callback.accept(
6111 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006112 } catch (RemoteException e) {
6113 // ignore
6114 }
6115 return;
6116 }
6117
6118 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6119 FunctionalUtils.ignoreRemoteException(callback::accept));
6120
6121 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006122 } finally {
6123 Binder.restoreCallingIdentity(identity);
6124 }
6125 }
6126
6127 /**
Hall Liu27d24262020-09-18 19:04:59 -07006128 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006129 */
6130 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006131 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006132 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006133 long identity = Binder.clearCallingIdentity();
6134 try {
Hall Liu27d24262020-09-18 19:04:59 -07006135 Phone phone = getPhone(subId);
6136 if (phone == null) {
6137 try {
6138 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6139 } catch (RemoteException e) {
6140 // ignore
6141 }
6142 return;
6143 }
SongFerngWang0e767992021-03-31 22:08:45 +08006144 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6145 PersistableBundle c = configManager.getConfigForSubId(subId);
6146 boolean requireUssd = c.getBoolean(
6147 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006148
Shuo Qian4a594052020-01-23 11:59:30 -08006149 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006150 if (requireUssd) {
6151 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6152 getSubscriptionCarrierId(subId));
6153 String newUssdCommand = "";
6154 try {
6155 newUssdCommand = carrierXmlParser.getFeature(
6156 CarrierXmlParser.FEATURE_CALL_WAITING)
6157 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6158 } catch (NullPointerException e) {
6159 loge("Failed to generate USSD number" + e);
6160 }
6161 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6162 mMainThreadHandler, callback, carrierXmlParser,
6163 CarrierXmlParser.SsEntry.SSAction.QUERY);
6164 final String ussdCommand = newUssdCommand;
6165 Executors.newSingleThreadExecutor().execute(() -> {
6166 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6167 });
6168 } else {
6169 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6170 callback::accept);
6171 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6172 }
Shuo Qian4a594052020-01-23 11:59:30 -08006173 } finally {
6174 Binder.restoreCallingIdentity(identity);
6175 }
6176 }
6177
6178 /**
Hall Liu27d24262020-09-18 19:04:59 -07006179 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006180 */
6181 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006182 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006183 enforceModifyPermission();
6184 long identity = Binder.clearCallingIdentity();
6185 try {
Hall Liu27d24262020-09-18 19:04:59 -07006186 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6187
6188 Phone phone = getPhone(subId);
6189 if (phone == null) {
6190 try {
6191 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6192 } catch (RemoteException e) {
6193 // ignore
6194 }
6195 return;
6196 }
6197
SongFerngWang0e767992021-03-31 22:08:45 +08006198 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6199 PersistableBundle c = configManager.getConfigForSubId(subId);
6200 boolean requireUssd = c.getBoolean(
6201 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006202
SongFerngWang0e767992021-03-31 22:08:45 +08006203 if (DBG) log("getCallWaitingStatus: subId " + subId);
6204 if (requireUssd) {
6205 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6206 getSubscriptionCarrierId(subId));
6207 CarrierXmlParser.SsEntry.SSAction ssAction =
6208 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6209 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6210 String newUssdCommand = "";
6211 try {
6212 newUssdCommand = carrierXmlParser.getFeature(
6213 CarrierXmlParser.FEATURE_CALL_WAITING)
6214 .makeCommand(ssAction, null);
6215 } catch (NullPointerException e) {
6216 loge("Failed to generate USSD number" + e);
6217 }
6218 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6219 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6220 final String ussdCommand = newUssdCommand;
6221 Executors.newSingleThreadExecutor().execute(() -> {
6222 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6223 });
6224 } else {
6225 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6226 FunctionalUtils.ignoreRemoteException(callback::accept));
6227
6228 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6229 }
Shuo Qian4a594052020-01-23 11:59:30 -08006230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
6233 }
6234
6235 /**
yinxub1bed742017-04-17 11:45:04 -07006236 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006237 *
yinxub1bed742017-04-17 11:45:04 -07006238 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006239 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6240 * location related information which will be sent if the caller already possess
6241 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006242 * @param request contains the radio access networks with bands/channels to scan
6243 * @param messenger callback messenger for scan results or errors
6244 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006245 * @return the id of the requested scan which can be used to stop the scan.
6246 */
6247 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006248 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6249 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006250 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6252 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006253 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006254 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6255 if (!renounceFineLocationAccess) {
6256 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6257 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6258 .setCallingPackage(callingPackage)
6259 .setCallingFeatureId(callingFeatureId)
6260 .setCallingPid(Binder.getCallingPid())
6261 .setCallingUid(Binder.getCallingUid())
6262 .setMethod("requestNetworkScan")
6263 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6264 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6265 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6266 .build());
6267 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006268 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006269 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6270 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006271 if (e != null) {
6272 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6273 throw e;
6274 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006275 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006276 return TelephonyScanManager.INVALID_SCAN_ID;
6277 }
6278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006279 }
Hall Liu912dfd32019-04-25 14:02:26 -07006280 int callingUid = Binder.getCallingUid();
6281 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006282 final long identity = Binder.clearCallingIdentity();
6283 try {
6284 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006285 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006286 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006287 } finally {
6288 Binder.restoreCallingIdentity(identity);
6289 }
yinxu504e1392017-04-12 16:03:22 -07006290 }
6291
Hall Liub2ac8ef2019-02-28 15:56:23 -08006292 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006293 NetworkScanRequest request, int subId, String callingPackage) {
6294 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006295 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6296 boolean hasNetworkScanPermission =
6297 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6298 == PERMISSION_GRANTED;
6299
6300 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6301 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6302 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006303 }
6304
6305 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6306 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006307 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6308 return new SecurityException("Specific channels must not be"
6309 + " scanned without location access.");
6310 }
6311 }
6312 }
6313
Hall Liub2ac8ef2019-02-28 15:56:23 -08006314 return null;
6315 }
6316
yinxu504e1392017-04-12 16:03:22 -07006317 /**
6318 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006319 *
6320 * @param subId id of the subscription
6321 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006322 */
6323 @Override
6324 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6326 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327
Hall Liu912dfd32019-04-25 14:02:26 -07006328 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 final long identity = Binder.clearCallingIdentity();
6330 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006331 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
yinxu504e1392017-04-12 16:03:22 -07006335 }
6336
6337 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006338 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006339 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006340 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006341 */
6342 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006343 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006344 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006345 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006346 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347
6348 final long identity = Binder.clearCallingIdentity();
6349 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006350 if (DBG) log("getAllowedNetworkTypesBitmask");
6351 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6352 int networkTypesBitmask = (result != null ? result[0] : -1);
6353 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6354 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 } finally {
6356 Binder.restoreCallingIdentity(identity);
6357 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006358 }
6359
6360 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006361 * Get the allowed network types for certain reason.
6362 *
6363 * @param subId the id of the subscription.
6364 * @param reason the reason the allowed network type change is taking place
6365 * @return the allowed network types.
6366 */
6367 @Override
6368 public long getAllowedNetworkTypesForReason(int subId,
6369 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006370 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006371 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006372 final long identity = Binder.clearCallingIdentity();
6373 try {
6374 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6375 } finally {
6376 Binder.restoreCallingIdentity(identity);
6377 }
6378 }
6379
6380 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006381 * Enable/Disable E-UTRA-NR Dual Connectivity
6382 * @param subId subscription id of the sim card
6383 * @param nrDualConnectivityState expected NR dual connectivity state
6384 * This can be passed following states
6385 * <ol>
6386 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6387 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6388 * <li>Disable NR dual connectivity and force secondary cell to be released
6389 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6390 * </ol>
6391 * @return operation result.
6392 */
6393 @Override
6394 public int setNrDualConnectivityState(int subId,
6395 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6397 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006398 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006399 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6400 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6401 }
6402
Sooraj Sasindran37444802020-08-11 10:40:43 -07006403 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6404 final long identity = Binder.clearCallingIdentity();
6405 try {
6406 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6407 nrDualConnectivityState, subId,
6408 workSource);
6409 if (DBG) log("enableNRDualConnectivity result: " + result);
6410 return result;
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
6414 }
6415
6416 /**
6417 * Is E-UTRA-NR Dual Connectivity enabled
6418 * @return true if dual connectivity is enabled else false
6419 */
6420 @Override
6421 public boolean isNrDualConnectivityEnabled(int subId) {
6422 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006423 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006424 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006425 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006426 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6427 return false;
6428 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006429 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
6432 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6433 null, subId, workSource);
6434 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6435 return isEnabled;
6436 } finally {
6437 Binder.restoreCallingIdentity(identity);
6438 }
6439 }
6440
6441 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006442 * Set the allowed network types of the device and
6443 * provide the reason triggering the allowed network change.
6444 *
6445 * @param subId the id of the subscription.
6446 * @param reason the reason the allowed network type change is taking place
6447 * @param allowedNetworkTypes the allowed network types.
6448 * @return true on success; false on any failure.
6449 */
6450 @Override
6451 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006452 @TelephonyManager.AllowedNetworkTypesReason int reason,
6453 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6455 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006456 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006457 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6458 return false;
6459 }
6460 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6461 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006462 return false;
6463 }
6464
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006465 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6466 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6467
6468
6469 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6470 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6471 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006472 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006473
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006474 final long identity = Binder.clearCallingIdentity();
6475 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006476 Boolean success = (Boolean) sendRequest(
6477 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6478 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6479
6480 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6481 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006482 } finally {
6483 Binder.restoreCallingIdentity(identity);
6484 }
6485 }
6486
6487 /**
Miaoa84611c2019-03-15 09:21:10 +08006488 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006489 *
Miaoa84611c2019-03-15 09:21:10 +08006490 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006491 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006492 * @hide
6493 */
6494 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006495 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006498 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499 try {
Miaoa84611c2019-03-15 09:21:10 +08006500 if (phone != null) {
6501 return phone.hasMatchedTetherApnSetting();
6502 } else {
6503 return false;
6504 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505 } finally {
6506 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006507 }
Junda Liu475951f2014-11-07 16:45:03 -08006508 }
6509
6510 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006511 * Get the user enabled state of Mobile Data.
6512 *
6513 * TODO: remove and use isUserDataEnabled.
6514 * This can't be removed now because some vendor codes
6515 * calls through ITelephony directly while they should
6516 * use TelephonyManager.
6517 *
6518 * @return true on enabled
6519 */
6520 @Override
6521 public boolean getDataEnabled(int subId) {
6522 return isUserDataEnabled(subId);
6523 }
6524
6525 /**
6526 * Get whether mobile data is enabled per user setting.
6527 *
6528 * There are other factors deciding whether mobile data is actually enabled, but they are
6529 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006530 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006531 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6532 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006533 *
6534 * @return {@code true} if data is enabled else {@code false}
6535 */
6536 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006537 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006538 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006539 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006540 try {
6541 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6542 functionName);
6543 } catch (Exception e) {
6544 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6545 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006546 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006548 mApp, subId, functionName);
6549
Robert Greenwalt646120a2014-05-23 11:54:03 -07006550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
6554 int phoneId = mSubscriptionController.getPhoneId(subId);
6555 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6556 Phone phone = PhoneFactory.getPhone(phoneId);
6557 if (phone != null) {
6558 boolean retVal = phone.isUserDataEnabled();
6559 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6560 return retVal;
6561 } else {
6562 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6563 return false;
6564 }
6565 } finally {
6566 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006567 }
6568 }
6569
6570 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006571 * Checks if the device is capable of mobile data by considering whether whether the
6572 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6573 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006574 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006575 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006576 */
6577 @Override
6578 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006579 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006580 try {
6581 try {
6582 mApp.enforceCallingOrSelfPermission(
6583 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006584 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006585 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006586 try {
6587 mApp.enforceCallingOrSelfPermission(
6588 android.Manifest.permission.READ_PHONE_STATE,
6589 functionName);
6590 } catch (Exception e2) {
6591 mApp.enforceCallingOrSelfPermission(
6592 permission.READ_BASIC_PHONE_STATE, functionName);
6593 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006594 }
6595 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006596 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
6601 int phoneId = mSubscriptionController.getPhoneId(subId);
6602 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6603 Phone phone = PhoneFactory.getPhone(phoneId);
6604 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006605 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6607 return retVal;
6608 } else {
6609 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6610 return false;
6611 }
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006614 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006615 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006616
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006617 /**
6618 * Check if data is enabled for a specific reason
6619 * @param subId Subscription index
6620 * @param reason the reason the data enable change is taking place
6621 * @return {@code true} if the overall data is enabled; {@code false} if not.
6622 */
6623 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006624 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006625 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006626 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006627 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006628 try {
6629 mApp.enforceCallingOrSelfPermission(
6630 android.Manifest.permission.ACCESS_NETWORK_STATE,
6631 functionName);
6632 } catch (Exception e) {
6633 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6634 functionName);
6635 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006636 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006637 try {
6638 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006639 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006640 } catch (Exception e2) {
6641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006642 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006643 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006644 }
6645
6646
6647 final long identity = Binder.clearCallingIdentity();
6648 try {
6649 int phoneId = mSubscriptionController.getPhoneId(subId);
6650 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006651 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006652 + " reason=" + reason);
6653 }
6654 Phone phone = PhoneFactory.getPhone(phoneId);
6655 if (phone != null) {
6656 boolean retVal;
6657 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6658 retVal = phone.isUserDataEnabled();
6659 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006660 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006661 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006662 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006663 return retVal;
6664 } else {
6665 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006666 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006667 + subId + " retVal=false");
6668 }
6669 return false;
6670 }
6671 } finally {
6672 Binder.restoreCallingIdentity(identity);
6673 }
6674 }
6675
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006676 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006677 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006678 if (uid == Process.PHONE_UID) {
6679 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6680 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006681 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6682 }
6683
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006684 //load access rules from carrier configs, and check those as well: b/139133814
6685 SubscriptionController subController = SubscriptionController.getInstance();
6686 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6687 || subController == null) return privilegeFromSim;
6688
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006689 PackageManager pkgMgr = phone.getContext().getPackageManager();
6690 String[] packages = pkgMgr.getPackagesForUid(uid);
6691
6692 final long identity = Binder.clearCallingIdentity();
6693 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006694 int subId = phone.getSubId();
6695 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6696 // A test override is in place for the privileges for this subId, so don't try to
6697 // read the subscription privileges.
6698 return privilegeFromSim;
6699 }
6700 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006701 SubscriptionManager subManager = (SubscriptionManager)
6702 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6703 for (String pkg : packages) {
6704 if (subManager.canManageSubscription(subInfo, pkg)) {
6705 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6706 }
6707 }
6708 return privilegeFromSim;
6709 } finally {
6710 Binder.restoreCallingIdentity(identity);
6711 }
6712 }
6713
6714 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6715 String pkgName) {
6716 //load access rules from carrier configs, and check those as well: b/139133814
6717 SubscriptionController subController = SubscriptionController.getInstance();
6718 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6719 || subController == null) return privilegeFromSim;
6720
6721 final long identity = Binder.clearCallingIdentity();
6722 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006723 int subId = phone.getSubId();
6724 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6725 // A test override is in place for the privileges for this subId, so don't try to
6726 // read the subscription privileges.
6727 return privilegeFromSim;
6728 }
6729 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006730 SubscriptionManager subManager = (SubscriptionManager)
6731 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6732 return subManager.canManageSubscription(subInfo, pkgName)
6733 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6734 } finally {
6735 Binder.restoreCallingIdentity(identity);
6736 }
6737 }
6738
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006739 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006740 public int getCarrierPrivilegeStatus(int subId) {
6741 final Phone phone = getPhone(subId);
6742 if (phone == null) {
6743 loge("getCarrierPrivilegeStatus: Invalid subId");
6744 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6745 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006746 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6747 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006748 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006749 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6750 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006751
6752 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006753 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006754 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006755 }
Junda Liu29340342014-07-10 15:23:27 -07006756
6757 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006758 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006759 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006760 final Phone phone = getPhone(subId);
6761 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006762 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006763 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6764 }
6765 UiccProfile profile =
6766 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6767 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006768 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006769 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6770 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006771 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006772 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006773 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006774 }
6775
6776 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006777 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006778 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006779 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006780 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006781 }
6782
6783 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006784 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6785 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006786 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006787 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6788 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006789 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006790 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006791 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006792 }
6793
6794 @Override
6795 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006796 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006797 if (TextUtils.isEmpty(pkgName))
6798 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006799 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6800 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006801 UiccPort port = UiccController.getInstance().getUiccPort(i);
6802 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006803 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006804 continue;
6805 }
6806
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006807 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006808 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006809 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006810 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6811 break;
6812 }
6813 }
6814
6815 return result;
Junda Liu29340342014-07-10 15:23:27 -07006816 }
Derek Tan89e89d42014-07-08 17:00:10 -07006817
6818 @Override
Junda Liue64de782015-04-16 17:19:16 -07006819 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006820 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006821 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6822 loge("phoneId " + phoneId + " is not valid.");
6823 return null;
6824 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006825 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6826 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006827 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006828 return null ;
6829 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006830 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006831 }
6832
Amith Yamasani6e118872016-02-19 12:53:51 -08006833 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006834 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006835 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006836 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006837 List<String> privilegedPackages = new ArrayList<>();
6838 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006839 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006840 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006841 if (port != null) {
6842 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006843 if (packages == null) {
6844 // Only check packages in user 0 for now
6845 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006846 PackageManager.MATCH_DISABLED_COMPONENTS
6847 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006848 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006849 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006850 }
6851 for (int p = packages.size() - 1; p >= 0; p--) {
6852 PackageInfo pkgInfo = packages.get(p);
6853 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006854 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006855 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006856 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006857 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006858 privilegedPackages.add(pkgInfo.packageName);
6859 }
6860 }
6861 }
6862 }
6863 return privilegedPackages;
6864 }
6865
chen xuf7e9fe82019-05-09 19:31:02 -07006866 @Override
6867 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006868 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6869
6870 final long identity = Binder.clearCallingIdentity();
6871
chen xuf7e9fe82019-05-09 19:31:02 -07006872 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006873 try {
6874 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6875 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6876 }
6877 } finally {
6878 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006879 }
6880 return privilegedPackages;
6881 }
6882
Wink Savilleb564aae2014-10-23 10:18:09 -07006883 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006884 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006885 UiccPort port = phone == null ? null : phone.getUiccPort();
6886 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006887 return null;
6888 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006889 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006890 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006891 return null;
6892 }
6893 return iccId;
6894 }
6895
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006896 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006897 public void setCallComposerStatus(int subId, int status) {
6898 enforceModifyPermission();
6899
6900 final long identity = Binder.clearCallingIdentity();
6901 try {
6902 Phone phone = getPhone(subId);
6903 if (phone != null) {
6904 Phone defaultPhone = phone.getImsPhone();
6905 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6906 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6907 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006908 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6909 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006910 }
6911 }
Shuo Qian284ae752020-12-22 19:10:14 -08006912 } catch (ImsException e) {
6913 throw new ServiceSpecificException(e.getCode());
6914 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006915 Binder.restoreCallingIdentity(identity);
6916 }
6917 }
6918
6919 @Override
6920 public int getCallComposerStatus(int subId) {
6921 enforceReadPrivilegedPermission("getCallComposerStatus");
6922
6923 final long identity = Binder.clearCallingIdentity();
6924 try {
6925 Phone phone = getPhone(subId);
6926 if (phone != null) {
6927 Phone defaultPhone = phone.getImsPhone();
6928 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6929 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6930 return imsPhone.getCallComposerStatus();
6931 }
6932 }
6933 } finally {
6934 Binder.restoreCallingIdentity(identity);
6935 }
6936 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6937 }
6938
6939 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006940 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6941 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006942 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006943 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945 final long identity = Binder.clearCallingIdentity();
6946 try {
6947 final String iccId = getIccId(subId);
6948 final Phone phone = getPhone(subId);
6949 if (phone == null) {
6950 return false;
6951 }
6952 final String subscriberId = phone.getSubscriberId();
6953
6954 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006955 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006956 + subscriberId + " to " + number);
6957 }
6958
6959 if (TextUtils.isEmpty(iccId)) {
6960 return false;
6961 }
6962
6963 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6964
6965 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6966 if (alphaTag == null) {
6967 editor.remove(alphaTagPrefKey);
6968 } else {
6969 editor.putString(alphaTagPrefKey, alphaTag);
6970 }
6971
6972 // Record both the line number and IMSI for this ICCID, since we need to
6973 // track all merged IMSIs based on line number
6974 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6975 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6976 if (number == null) {
6977 editor.remove(numberPrefKey);
6978 editor.remove(subscriberPrefKey);
6979 } else {
6980 editor.putString(numberPrefKey, number);
6981 editor.putString(subscriberPrefKey, subscriberId);
6982 }
6983
6984 editor.commit();
6985 return true;
6986 } finally {
6987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006988 }
Derek Tan7226c842014-07-02 17:42:23 -07006989 }
6990
6991 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006992 public String getLine1NumberForDisplay(int subId, String callingPackage,
6993 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006994 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006996 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006997 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006998 return null;
6999 }
Derek Tan97ebb422014-09-05 16:55:38 -07007000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 final long identity = Binder.clearCallingIdentity();
7002 try {
7003 String iccId = getIccId(subId);
7004 if (iccId != null) {
7005 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7006 if (DBG_MERGE) {
7007 log("getLine1NumberForDisplay returning "
7008 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7009 }
7010 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7013 return null;
7014 } finally {
7015 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007016 }
Derek Tan7226c842014-07-02 17:42:23 -07007017 }
7018
7019 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007020 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7021 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007023 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007024 return null;
7025 }
Derek Tan97ebb422014-09-05 16:55:38 -07007026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 String iccId = getIccId(subId);
7030 if (iccId != null) {
7031 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7032 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7033 }
7034 return null;
7035 } finally {
7036 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007037 }
Derek Tan7226c842014-07-02 17:42:23 -07007038 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007039
7040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007041 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7042 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007043 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7044 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007046 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007047 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007048 return null;
7049 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007050
Jordan Liub49b04b2019-05-06 14:45:15 -07007051 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7052 // the process, where TelephonyManager was instantiated.
7053 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007054 final long identity = Binder.clearCallingIdentity();
7055 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007056 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 final TelephonyManager tele = TelephonyManager.from(context);
7058 final SubscriptionManager sub = SubscriptionManager.from(context);
7059
7060 // Figure out what subscribers are currently active
7061 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062
Jordan Liub49b04b2019-05-06 14:45:15 -07007063 // Only consider subs which match the current subId
7064 // This logic can be simplified. See b/131189269 for progress.
7065 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007066 activeSubscriberIds.add(tele.getSubscriberId(subId));
7067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068
7069 // First pass, find a number override for an active subscriber
7070 String mergeNumber = null;
7071 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7072 for (String key : prefs.keySet()) {
7073 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7074 final String subscriberId = (String) prefs.get(key);
7075 if (activeSubscriberIds.contains(subscriberId)) {
7076 final String iccId = key.substring(
7077 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7078 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7079 mergeNumber = (String) prefs.get(numberKey);
7080 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007081 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 + " for active subscriber " + subscriberId);
7083 }
7084 if (!TextUtils.isEmpty(mergeNumber)) {
7085 break;
7086 }
7087 }
7088 }
7089 }
7090
7091 // Shortcut when no active merged subscribers
7092 if (TextUtils.isEmpty(mergeNumber)) {
7093 return null;
7094 }
7095
7096 // Second pass, find all subscribers under that line override
7097 final ArraySet<String> result = new ArraySet<>();
7098 for (String key : prefs.keySet()) {
7099 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7100 final String number = (String) prefs.get(key);
7101 if (mergeNumber.equals(number)) {
7102 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7103 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7104 final String subscriberId = (String) prefs.get(subscriberKey);
7105 if (!TextUtils.isEmpty(subscriberId)) {
7106 result.add(subscriberId);
7107 }
7108 }
7109 }
7110 }
7111
7112 final String[] resultArray = result.toArray(new String[result.size()]);
7113 Arrays.sort(resultArray);
7114 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007115 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7117 }
7118 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007119 } finally {
7120 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007121 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007122 }
7123
7124 @Override
zoey chen38003472019-12-13 17:16:31 +08007125 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7126 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007127
7128 final long identity = Binder.clearCallingIdentity();
7129 try {
7130 final TelephonyManager telephonyManager = mApp.getSystemService(
7131 TelephonyManager.class);
7132 String subscriberId = telephonyManager.getSubscriberId(subId);
7133 if (subscriberId == null) {
7134 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007135 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007136 + subId);
7137 }
7138 return null;
7139 }
7140
7141 final SubscriptionInfo info = SubscriptionController.getInstance()
7142 .getSubscriptionInfo(subId);
7143 final ParcelUuid groupUuid = info.getGroupUuid();
7144 // If it doesn't belong to any group, return just subscriberId of itself.
7145 if (groupUuid == null) {
7146 return new String[]{subscriberId};
7147 }
7148
7149 // Get all subscriberIds from the group.
7150 final List<String> mergedSubscriberIds = new ArrayList<>();
7151 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007152 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007153 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007154 for (SubscriptionInfo subInfo : groupInfos) {
7155 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7156 if (subscriberId != null) {
7157 mergedSubscriberIds.add(subscriberId);
7158 }
7159 }
7160
7161 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164
7165 }
7166 }
7167
7168 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007169 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007170 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007171 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172
7173 final long identity = Binder.clearCallingIdentity();
7174 try {
7175 final Phone phone = getPhone(subId);
7176 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007180 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007181
7182 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007183 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007184 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7185 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007186 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7187 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188
7189 final long identity = Binder.clearCallingIdentity();
7190 try {
7191 final Phone phone = getPhone(subId);
7192 if (phone == null) {
7193 return false;
7194 }
7195 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7196 cdmaNonRoamingList);
7197 } finally {
7198 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007199 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007200 }
7201
7202 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007203 @Deprecated
7204 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7205 enforceModifyPermission();
7206
7207 int returnValue = 0;
7208 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007209 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007210 if(result.exception == null) {
7211 if (result.result != null) {
7212 byte[] responseData = (byte[])(result.result);
7213 if(responseData.length > oemResp.length) {
7214 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7215 responseData.length + "bytes. Buffer Size is " +
7216 oemResp.length + "bytes.");
7217 }
7218 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7219 returnValue = responseData.length;
7220 }
7221 } else {
7222 CommandException ex = (CommandException) result.exception;
7223 returnValue = ex.getCommandError().ordinal();
7224 if(returnValue > 0) returnValue *= -1;
7225 }
7226 } catch (RuntimeException e) {
7227 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7228 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7229 if(returnValue > 0) returnValue *= -1;
7230 }
7231
7232 return returnValue;
7233 }
7234
7235 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007236 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007237 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007238 try {
7239 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007240 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007241 mApp, phone.getSubId(), "getRadioAccessFamily");
7242 } catch (SecurityException e) {
7243 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7244 throw e;
7245 }
chen xub97461a2018-10-26 14:17:57 -07007246 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007247 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007248 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 final long identity = Binder.clearCallingIdentity();
7251 try {
chen xub97461a2018-10-26 14:17:57 -07007252 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007253 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007254 mApp, phone.getSubId(), "getRadioAccessFamily");
7255 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258 }
chen xub97461a2018-10-26 14:17:57 -07007259 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007260 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007261
7262 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007263 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007264 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007265 try {
7266 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7267 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007268 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007269 }
7270 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007271 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007272 }
7273 RoleManager rm = mApp.getSystemService(RoleManager.class);
7274 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7275 if (!dialerRoleHolders.contains(callingPackage)) {
7276 throw new SecurityException("App must be the dialer role holder to"
7277 + " upload a call composer pic");
7278 }
7279
7280 Executors.newSingleThreadExecutor().execute(() -> {
7281 ByteArrayOutputStream output = new ByteArrayOutputStream(
7282 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7283 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7284 boolean readUntilEnd = false;
7285 int totalBytesRead = 0;
7286 byte[] buffer = new byte[16 * 1024];
7287 while (true) {
7288 int numRead;
7289 try {
7290 numRead = input.read(buffer);
7291 } catch (IOException e) {
7292 try {
7293 fd.checkError();
7294 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7295 null);
7296 } catch (IOException e1) {
7297 // This means that the other side closed explicitly with an error. If this
7298 // happens, log and ignore.
7299 loge("Remote end of call composer picture pipe closed: " + e1);
7300 }
7301 break;
7302 }
7303 if (numRead == -1) {
7304 readUntilEnd = true;
7305 break;
7306 }
7307 totalBytesRead += numRead;
7308 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7309 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7310 try {
7311 input.close();
7312 } catch (IOException e) {
7313 // ignore
7314 }
7315 break;
7316 }
7317 output.write(buffer, 0, numRead);
7318 }
7319 // Generally, the remote end will close the file descriptors. The only case where we
7320 // close is above, where the picture size is too big.
7321
7322 try {
7323 fd.checkError();
7324 } catch (IOException e) {
7325 loge("Remote end for call composer closed with an error: " + e);
7326 return;
7327 }
7328
Hall Liuaa4211e2021-01-20 15:43:39 -08007329 if (!readUntilEnd) {
7330 loge("Did not finish reading entire image; aborting");
7331 return;
7332 }
Hall Liu82694d52020-12-11 18:22:04 -08007333
Hall Liuaa4211e2021-01-20 15:43:39 -08007334 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7335 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7336 new CallComposerPictureTransfer.Factory() {},
7337 imageData,
7338 (result) -> {
7339 if (result.first != null) {
7340 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7341 Bundle outputResult = new Bundle();
7342 outputResult.putParcelable(
7343 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7344 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7345 outputResult);
7346 } else {
7347 callback.send(result.second, null);
7348 }
7349 }
7350 );
Hall Liu82694d52020-12-11 18:22:04 -08007351 });
7352 }
7353
7354 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007355 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007356 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007357 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358
7359 final long identity = Binder.clearCallingIdentity();
7360 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007361 ImsManager.getInstance(defaultPhone.getContext(),
7362 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007366 }
7367
7368 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007369 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007370 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7372 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007373 return false;
7374 }
Svet Ganovb320e182015-04-16 12:30:10 -07007375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 final long identity = Binder.clearCallingIdentity();
7377 try {
7378 // Check the user preference and the system-level IMS setting. Even if the user has
7379 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7380 // In the long run, we may instead need to check if there exists a connection service
7381 // which can support video calling.
7382 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007383 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 return imsManager.isVtEnabledByPlatform()
7385 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7386 && imsManager.isVtEnabledByUser();
7387 } finally {
7388 Binder.restoreCallingIdentity(identity);
7389 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007390 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007391
Andrew Leea1239f22015-03-02 17:44:07 -08007392 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007393 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7394 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007396 mApp, subId, callingPackage, callingFeatureId,
7397 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 return false;
7399 }
7400
7401 final long identity = Binder.clearCallingIdentity();
7402 try {
7403 CarrierConfigManager configManager =
7404 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007405 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7407 } finally {
7408 Binder.restoreCallingIdentity(identity);
7409 }
Andrew Leea1239f22015-03-02 17:44:07 -08007410 }
7411
7412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007413 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007415 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 return false;
7417 }
7418
7419 final long identity = Binder.clearCallingIdentity();
7420 try {
7421 CarrierConfigManager configManager =
7422 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007423 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7425 } finally {
7426 Binder.restoreCallingIdentity(identity);
7427 }
Andrew Leea1239f22015-03-02 17:44:07 -08007428 }
7429
Andrew Lee9431b832015-03-09 18:46:45 -07007430 @Override
7431 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007432 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007433 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007434 }
7435
7436 @Override
7437 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 final long identity = Binder.clearCallingIdentity();
7439 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007440 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 } finally {
7442 Binder.restoreCallingIdentity(identity);
7443 }
Andrew Lee9431b832015-03-09 18:46:45 -07007444 }
7445
Hall Liuf6668912018-10-31 17:05:23 -07007446 /**
7447 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7448 * support for the feature and device firmware support.
7449 *
7450 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7451 */
7452 @Override
7453 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007455 final Phone phone = getPhone(subscriptionId);
7456 if (phone == null) {
7457 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7458 return false;
7459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007461 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7463 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 return isCarrierSupported && isDeviceSupported;
7466 } finally {
7467 Binder.restoreCallingIdentity(identity);
7468 }
Hall Liu98187582018-01-22 19:15:32 -08007469 }
7470
Hall Liuf6668912018-10-31 17:05:23 -07007471 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007472 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7473 * RTT setting, will return true if the device and carrier both support RTT.
7474 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007475 */
7476 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 final long identity = Binder.clearCallingIdentity();
7478 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007479 boolean isRttSupported = isRttSupported(subscriptionId);
7480 boolean isUserRttSettingOn = Settings.Secure.getInt(
7481 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7482 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7483 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7484 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 } finally {
7486 Binder.restoreCallingIdentity(identity);
7487 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007488 }
7489
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007490 @Deprecated
7491 @Override
7492 public String getDeviceId(String callingPackage) {
7493 return getDeviceIdWithFeature(callingPackage, null);
7494 }
7495
Sanket Padawe7310cc72015-01-14 09:53:20 -08007496 /**
7497 * Returns the unique device ID of phone, for example, the IMEI for
7498 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7499 *
7500 * <p>Requires Permission:
7501 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7502 */
7503 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007504 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007505 try {
7506 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7507 } catch (SecurityException se) {
7508 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7509 throw new SecurityException("Package " + callingPackage + " does not belong to "
7510 + Binder.getCallingUid());
7511 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007512 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007513 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007514 return null;
7515 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007516 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007517 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007518 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007519 return null;
7520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
7524 return phone.getDeviceId();
7525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007528 }
7529
Ping Sunc67b7c22016-03-02 19:16:45 +08007530 /**
7531 * {@hide}
7532 * Returns the IMS Registration Status on a particular subid
7533 *
7534 * @param subId
7535 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007536 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007537 Phone phone = getPhone(subId);
7538 if (phone != null) {
7539 return phone.isImsRegistered();
7540 } else {
7541 return false;
7542 }
7543 }
7544
Santos Cordon7a1885b2015-02-03 11:15:19 -08007545 @Override
7546 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 final long identity = Binder.clearCallingIdentity();
7548 try {
7549 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7550 } finally {
7551 Binder.restoreCallingIdentity(identity);
7552 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007553 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007554
Tyler Gunnf70ed162019-04-03 15:28:53 -07007555 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007556 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007557 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007559 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007560 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7561 }
7562 final long identity = Binder.clearCallingIdentity();
7563 try {
7564 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7565 } finally {
7566 Binder.restoreCallingIdentity(identity);
7567 }
7568 }
7569
7570 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007571 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007572 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007573 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007574 mApp,
7575 subscriptionId,
7576 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 Phone phone = getPhone(subscriptionId);
7580 if (phone == null) {
7581 return null;
7582 }
7583 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
7586 }
7587 }
7588
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007589 /**
7590 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007591 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007592 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 final long identity = Binder.clearCallingIdentity();
7594 try {
7595 Phone phone = getPhone(subId);
7596 if (phone != null) {
7597 return phone.isWifiCallingEnabled();
7598 } else {
7599 return false;
7600 }
7601 } finally {
7602 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007603 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007604 }
7605
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007606 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007607 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007608 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007609 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 Phone phone = getPhone(subId);
7613 if (phone != null) {
7614 return phone.isVideoEnabled();
7615 } else {
7616 return false;
7617 }
7618 } finally {
7619 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007620 }
7621 }
7622
7623 /**
7624 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7625 * defined in {@link ImsRegistrationImplBase}.
7626 */
7627 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007628 final long identity = Binder.clearCallingIdentity();
7629 try {
7630 Phone phone = getPhone(subId);
7631 if (phone != null) {
7632 return phone.getImsRegistrationTech();
7633 } else {
7634 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7635 }
7636 } finally {
7637 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007638 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007639 }
7640
Stuart Scott8eef64f2015-04-08 15:13:54 -07007641 @Override
7642 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007643 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007644 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7645 return;
7646 }
Kai Shif70f46f2021-03-03 13:59:46 -08007647 Phone defaultPhone = getDefaultPhone();
7648 if (defaultPhone != null) {
7649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7650 mApp, getDefaultPhone().getSubId(), "factoryReset");
7651 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007652 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007653
Svet Ganovcc087f82015-05-12 20:35:54 -07007654 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007655 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7656 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007657 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007658 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007659 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007660 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007661 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007662 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007663 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007664 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007665 // There has been issues when Sms raw table somehow stores orphan
7666 // fragments. They lead to garbled message when new fragments come
7667 // in and combined with those stale ones. In case this happens again,
7668 // user can reset all network settings which will clean up this table.
7669 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007670 // Clean up IMS settings as well here.
7671 int slotId = getSlotIndex(subId);
7672 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7673 ImsManager.getInstance(mApp, slotId).factoryReset();
7674 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007675
Kai Shif70f46f2021-03-03 13:59:46 -08007676 if (defaultPhone == null) {
7677 return;
7678 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007679 // Erase modem config if erase modem on network setting is enabled.
7680 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7681 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7682 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007683 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007684 }
Kai Shif70f46f2021-03-03 13:59:46 -08007685
7686 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007687 } finally {
7688 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007689 }
7690 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007691
SongFerngWangfd89b102021-05-27 22:44:54 +08007692 @VisibleForTesting
7693 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7694 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7695 return;
7696 }
7697 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7698 RILConstants.PREFERRED_NETWORK_MODE);
7699 SubscriptionManager.setSubscriptionProperty(subId,
7700 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7701 "user=" + defaultNetworkType);
7702 phone.loadAllowedNetworksFromSubscriptionDatabase();
7703 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7704 defaultNetworkType, null);
7705 }
7706
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007707 private void cleanUpSmsRawTable(Context context) {
7708 ContentResolver resolver = context.getContentResolver();
7709 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7710 resolver.delete(uri, null, null);
7711 }
7712
Narayan Kamath1c496c22015-04-16 14:40:19 +01007713 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007714 public String getSimLocaleForSubscriber(int subId) {
7715 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7716 final Phone phone = getPhone(subId);
7717 if (phone == null) {
7718 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007719 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721 final long identity = Binder.clearCallingIdentity();
7722 try {
chen xu5d3637b2019-01-21 23:31:38 -08007723 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007724 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007725 if (info == null) {
7726 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7727 return null;
7728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 // Try and fetch the locale from the carrier properties or from the SIM language
7730 // preferences (EF-PL and EF-LI)...
7731 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007733 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7734 if (localeFromDefaultSim != null) {
7735 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7736 if (DBG) log("Using locale from subId: " + subId + " locale: "
7737 + localeFromDefaultSim);
7738 return localeFromDefaultSim.toLanguageTag();
7739 } else {
7740 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007741 }
7742 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744 // The SIM language preferences only store a language (e.g. fr = French), not an
7745 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7746 // the SIM and carrier preferences does not include a country we add the country
7747 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007748 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007749 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007750 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 return mccLocale.toLanguageTag();
7752 }
7753
7754 if (DBG) log("No locale found - returning null");
7755 return null;
7756 } finally {
7757 Binder.restoreCallingIdentity(identity);
7758 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007759 }
7760
7761 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007762 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007763 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007764 }
7765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 /**
7767 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7768 */
7769 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007770 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007771 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007772 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007773
Chenjie Yu1ba97252018-01-11 18:16:20 -08007774 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007775 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007776
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007777 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007778 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7779 * representing the state of the modem.
7780 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007781 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7782 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007783 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007784 */
7785 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007786 public void requestModemActivityInfo(ResultReceiver result) {
7787 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007788 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789
7790 final long identity = Binder.clearCallingIdentity();
7791 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007792 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 } finally {
7794 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007795 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007796 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007797
Siddharth Rayb8114062018-06-17 15:02:38 -07007798 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7799 // less than total activity duration.
7800 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7801 if (info == null) {
7802 return false;
7803 }
7804 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007805 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7806 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7807
Siddharth Rayb8114062018-06-17 15:02:38 -07007808 return (info.isValid()
7809 && (info.getSleepTimeMillis() <= activityDurationMs)
7810 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007811 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007812 && (totalTxTimeMs <= activityDurationMs));
7813 }
7814
Jack Yu85bd38a2015-11-09 11:34:32 -08007815 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007816 * Returns the service state information on specified subscription.
7817 */
7818 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007819 public ServiceState getServiceStateForSubscriber(int subId,
7820 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7821 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007823 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007824 return null;
7825 }
7826
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007827 boolean hasFinePermission = false;
7828 boolean hasCoarsePermission = false;
7829 if (!renounceFineLocationAccess) {
7830 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7831 LocationAccessPolicy.checkLocationPermission(mApp,
7832 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7833 .setCallingPackage(callingPackage)
7834 .setCallingFeatureId(callingFeatureId)
7835 .setCallingPid(Binder.getCallingPid())
7836 .setCallingUid(Binder.getCallingUid())
7837 .setMethod("getServiceStateForSubscriber")
7838 .setLogAsInfo(true)
7839 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7840 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7841 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7842 .build());
7843 hasFinePermission =
7844 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7845 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007846
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007847 if (!renounceCoarseLocationAccess) {
7848 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7849 LocationAccessPolicy.checkLocationPermission(mApp,
7850 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7851 .setCallingPackage(callingPackage)
7852 .setCallingFeatureId(callingFeatureId)
7853 .setCallingPid(Binder.getCallingPid())
7854 .setCallingUid(Binder.getCallingUid())
7855 .setMethod("getServiceStateForSubscriber")
7856 .setLogAsInfo(true)
7857 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7858 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7859 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7860 .build());
7861 hasCoarsePermission =
7862 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7863 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007864
Jack Yu479f40e2020-10-27 21:29:25 -07007865 final Phone phone = getPhone(subId);
7866 if (phone == null) {
7867 return null;
7868 }
7869
Jordan Liu0f2bc442020-11-18 16:47:37 -08007870 final long identity = Binder.clearCallingIdentity();
7871
Jack Yu479f40e2020-10-27 21:29:25 -07007872 boolean isCallingPackageDataService = phone.getDataServicePackages()
7873 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007875 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7876 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7877 Rlog.d(LOG_TAG,
7878 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7879 return null;
7880 }
7881
Hall Liuf19c44f2018-11-27 14:38:17 -08007882 ServiceState ss = phone.getServiceState();
7883
7884 // Scrub out the location info in ServiceState depending on what level of access
7885 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007886 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007887 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7888 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889 } finally {
7890 Binder.restoreCallingIdentity(identity);
7891 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007892 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007893
7894 /**
7895 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7896 *
7897 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7898 * voicemail ringtone.
7899 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7900 * PhoneAccount.
7901 */
7902 @Override
7903 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7907 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007908 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
7914 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007915 }
7916
7917 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007918 * Sets the per-account voicemail ringtone.
7919 *
7920 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7921 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7922 *
7923 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7924 * voicemail ringtone.
7925 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7926 * PhoneAccount.
7927 */
7928 @Override
7929 public void setVoicemailRingtoneUri(String callingPackage,
7930 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007931 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007932 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007933 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7934 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7936 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7937 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939
7940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7943 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007944 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007945 }
7946 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7947 } finally {
7948 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007949 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007950 }
7951
7952 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007953 * Returns whether vibration is set for voicemail notification in Phone settings.
7954 *
7955 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7956 * voicemail vibration setting.
7957 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7958 */
7959 @Override
7960 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 final long identity = Binder.clearCallingIdentity();
7962 try {
7963 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7964 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007965 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007966 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
7971 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007972 }
7973
Youhan Wange64578a2016-05-02 15:32:42 -07007974 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007975 * Sets the per-account voicemail vibration.
7976 *
7977 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7978 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7979 *
7980 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7981 * voicemail vibration setting.
7982 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7983 * specific PhoneAccount.
7984 */
7985 @Override
7986 public void setVoicemailVibrationEnabled(String callingPackage,
7987 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007989 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007990 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7991 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7993 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7994 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007995 }
7996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 final long identity = Binder.clearCallingIdentity();
7998 try {
7999 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8000 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008001 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002 }
8003 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008006 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008007 }
8008
8009 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008010 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8011 *
8012 * @throws SecurityException if the caller does not have the required permission
8013 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008014 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008015 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008016 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008017 }
8018
8019 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008020 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8021 * permission.
8022 *
8023 * @throws SecurityException if the caller does not have the required permission
8024 */
8025 private void enforceSendSmsPermission() {
8026 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8027 }
8028
8029 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008030 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008031 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008032 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008033 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008034 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 final long identity = Binder.clearCallingIdentity();
8036 try {
8037 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008038 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039 if (componentName == null) {
8040 throw new SecurityException(
8041 "Caller not current active visual voicemail package[null]");
8042 }
8043 String vvmPackage = componentName.getPackageName();
8044 if (!callingPackage.equals(vvmPackage)) {
8045 throw new SecurityException("Caller not current active visual voicemail package["
8046 + vvmPackage + "]");
8047 }
8048 } finally {
8049 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008050 }
8051 }
8052
8053 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008054 * Return the application ID for the app type.
8055 *
8056 * @param subId the subscription ID that this request applies to.
8057 * @param appType the uicc app type.
8058 * @return Application ID for specificied app type, or null if no uicc.
8059 */
8060 @Override
8061 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008062 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008063 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008064
8065 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008066 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067 if (phone == null) {
8068 return null;
8069 }
8070 String aid = null;
8071 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008072 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008073 .getApplicationByType(appType).getAid();
8074 } catch (Exception e) {
8075 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8076 }
8077 return aid;
8078 } finally {
8079 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008080 }
Youhan Wange64578a2016-05-02 15:32:42 -07008081 }
8082
Youhan Wang4001d252016-05-11 10:29:41 -07008083 /**
8084 * Return the Electronic Serial Number.
8085 *
8086 * @param subId the subscription ID that this request applies to.
8087 * @return ESN or null if error.
8088 */
8089 @Override
8090 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008091 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008092 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093
8094 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008095 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008096 if (phone == null) {
8097 return null;
8098 }
8099 String esn = null;
8100 try {
8101 esn = phone.getEsn();
8102 } catch (Exception e) {
8103 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8104 }
8105 return esn;
8106 } finally {
8107 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008108 }
Youhan Wang4001d252016-05-11 10:29:41 -07008109 }
8110
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008111 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008112 * Return the Preferred Roaming List Version.
8113 *
8114 * @param subId the subscription ID that this request applies to.
8115 * @return PRLVersion or null if error.
8116 */
8117 @Override
8118 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008119 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008120 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121
8122 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008123 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 if (phone == null) {
8125 return null;
8126 }
8127 String cdmaPrlVersion = null;
8128 try {
8129 cdmaPrlVersion = phone.getCdmaPrlVersion();
8130 } catch (Exception e) {
8131 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8132 }
8133 return cdmaPrlVersion;
8134 } finally {
8135 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008136 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008137 }
8138
8139 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008140 * Get snapshot of Telephony histograms
8141 * @return List of Telephony histograms
8142 * @hide
8143 */
8144 @Override
8145 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8147 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148
8149 final long identity = Binder.clearCallingIdentity();
8150 try {
8151 return RIL.getTelephonyRILTimingHistograms();
8152 } finally {
8153 Binder.restoreCallingIdentity(identity);
8154 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008155 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008156
8157 /**
8158 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008159 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8160 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008161 * Require system privileges. In the future we may add this to carrier APIs.
8162 *
Michele Berionne482f8202018-11-27 18:57:59 -08008163 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008164 */
8165 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008166 @TelephonyManager.SetCarrierRestrictionResult
8167 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008168 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008169 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008170
Michele Berionne482f8202018-11-27 18:57:59 -08008171 if (carrierRestrictionRules == null) {
8172 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008173 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 final long identity = Binder.clearCallingIdentity();
8176 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008177 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008178 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179 } finally {
8180 Binder.restoreCallingIdentity(identity);
8181 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008182 }
8183
8184 /**
8185 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008186 * Get the allowed carrier list and the excluded carrier list, including the priority between
8187 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008188 * Require system privileges. In the future we may add this to carrier APIs.
8189 *
Michele Berionne482f8202018-11-27 18:57:59 -08008190 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008191 */
8192 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008193 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008194 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008195 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196
8197 final long identity = Binder.clearCallingIdentity();
8198 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008199 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8200 if (response instanceof CarrierRestrictionRules) {
8201 return (CarrierRestrictionRules) response;
8202 }
8203 // Response is an Exception of some kind,
8204 // which is signalled to the user as a NULL retval
8205 return null;
8206 } catch (Exception e) {
8207 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8208 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 } finally {
8210 Binder.restoreCallingIdentity(identity);
8211 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008212 }
8213
fionaxu59545b42016-05-25 15:53:37 -07008214 /**
fionaxu59545b42016-05-25 15:53:37 -07008215 * Action set from carrier signalling broadcast receivers to enable/disable radio
8216 * @param subId the subscription ID that this action applies to.
8217 * @param enabled control enable or disable radio.
8218 * {@hide}
8219 */
8220 @Override
8221 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8222 enforceModifyPermission();
8223 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224
8225 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008226 if (phone == null) {
8227 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8228 return;
8229 }
8230 try {
8231 phone.carrierActionSetRadioEnabled(enabled);
8232 } catch (Exception e) {
8233 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234 } finally {
8235 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008236 }
8237 }
8238
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008239 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008240 * Enable or disable Voice over NR (VoNR)
8241 * @param subId the subscription ID that this action applies to.
8242 * @param enabled enable or disable VoNR.
8243 * @return operation result.
8244 */
8245 @Override
8246 public int setVoNrEnabled(int subId, boolean enabled) {
8247 enforceModifyPermission();
8248 final Phone phone = getPhone(subId);
8249
8250 final long identity = Binder.clearCallingIdentity();
8251 if (phone == null) {
8252 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8253 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8254 }
8255
8256 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8257 try {
8258 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8259 workSource);
8260 if (DBG) log("setVoNrEnabled result: " + result);
8261 return result;
8262 } finally {
8263 Binder.restoreCallingIdentity(identity);
8264 }
8265 }
8266
8267 /**
8268 * Is voice over NR enabled
8269 * @return true if VoNR is enabled else false
8270 */
8271 @Override
8272 public boolean isVoNrEnabled(int subId) {
8273 enforceReadPrivilegedPermission("isVoNrEnabled");
8274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8278 null, subId, workSource);
8279 if (DBG) log("isVoNrEnabled: " + isEnabled);
8280 return isEnabled;
8281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
8284 }
8285
8286 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008287 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8288 * network status based on which carrier apps could apply actions accordingly,
8289 * enable/disable default url handler for example.
8290 *
8291 * @param subId the subscription ID that this action applies to.
8292 * @param report control start/stop reporting the default network status.
8293 * {@hide}
8294 */
8295 @Override
8296 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8297 enforceModifyPermission();
8298 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299
8300 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008301 if (phone == null) {
8302 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8303 return;
8304 }
8305 try {
8306 phone.carrierActionReportDefaultNetworkStatus(report);
8307 } catch (Exception e) {
8308 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 } finally {
8310 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008311 }
8312 }
8313
8314 /**
fionaxud9622282017-07-17 17:51:30 -07008315 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8316 * @param subId the subscription ID that this action applies to.
8317 * {@hide}
8318 */
8319 @Override
8320 public void carrierActionResetAll(int subId) {
8321 enforceModifyPermission();
8322 final Phone phone = getPhone(subId);
8323 if (phone == null) {
8324 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8325 return;
8326 }
8327 try {
8328 phone.carrierActionResetAll();
8329 } catch (Exception e) {
8330 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8331 }
8332 }
8333
8334 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008335 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8336 * bug report is being generated.
8337 */
8338 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008339 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008340 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8341 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008342 writer.println("Permission Denial: can't dump Phone from pid="
8343 + Binder.getCallingPid()
8344 + ", uid=" + Binder.getCallingUid()
8345 + "without permission "
8346 + android.Manifest.permission.DUMP);
8347 return;
8348 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008349 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008350 }
Jack Yueb89b242016-06-22 13:27:47 -07008351
Brad Ebingerdac2f002018-04-03 15:17:52 -07008352 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008353 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8354 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8355 @NonNull String[] args) {
8356 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8357 this, in.getFileDescriptor(), out.getFileDescriptor(),
8358 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008359 }
8360
Jack Yueb89b242016-06-22 13:27:47 -07008361 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008362 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008363 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008364 * @param reason the reason the data enable change is taking place
8365 * @param enabled True if enabling the data, otherwise disabling.
8366 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008367 */
8368 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008369 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008370 boolean enabled) {
8371 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8372 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8373 try {
8374 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008375 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008376 } catch (SecurityException se) {
8377 enforceModifyPermission();
8378 }
8379 } else {
8380 enforceModifyPermission();
8381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382
8383 final long identity = Binder.clearCallingIdentity();
8384 try {
8385 Phone phone = getPhone(subId);
8386 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008387 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8388 phone.carrierActionSetMeteredApnsEnabled(enabled);
8389 } else {
8390 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8391 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392 }
8393 } finally {
8394 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008395 }
8396 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008397
8398 /**
8399 * Get Client request stats
8400 * @return List of Client Request Stats
8401 * @hide
8402 */
8403 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008404 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8405 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008406 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008407 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008408 return null;
8409 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008410 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412 final long identity = Binder.clearCallingIdentity();
8413 try {
8414 if (phone != null) {
8415 return phone.getClientRequestStats();
8416 }
8417
8418 return null;
8419 } finally {
8420 Binder.restoreCallingIdentity(identity);
8421 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008422 }
8423
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008424 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008425 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008426 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008427 }
Jack Yueb4124c2017-02-16 15:32:43 -08008428
8429 /**
Grace Chen70990072017-03-24 17:21:30 -07008430 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008431 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008432 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008433 * @param state State of SIM (power down, power up, pass through)
8434 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8435 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8436 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008437 *
8438 **/
8439 @Override
Grace Chen70990072017-03-24 17:21:30 -07008440 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008441 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008442 Phone phone = PhoneFactory.getPhone(slotIndex);
8443
vagdeviaf9a5b92018-08-15 16:01:53 -07008444 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008449 phone.setSimPowerState(state, null, workSource);
8450 }
8451 } finally {
8452 Binder.restoreCallingIdentity(identity);
8453 }
8454 }
8455
8456 /**
8457 * Set SIM card power state.
8458 *
8459 * @param slotIndex SIM slot id.
8460 * @param state State of SIM (power down, power up, pass through)
8461 * @param callback callback to trigger after success or failure
8462 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8463 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8464 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8465 *
8466 **/
8467 @Override
8468 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8469 IIntegerConsumer callback) {
8470 enforceModifyPermission();
8471 Phone phone = PhoneFactory.getPhone(slotIndex);
8472
8473 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8474
8475 final long identity = Binder.clearCallingIdentity();
8476 try {
8477 if (phone != null) {
8478 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8479 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480 }
8481 } finally {
8482 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008483 }
8484 }
Shuo Qiandd210312017-04-12 22:11:33 +00008485
Tyler Gunn65d45c22017-06-05 11:22:26 -07008486 private boolean isUssdApiAllowed(int subId) {
8487 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008488 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008489 if (configManager == null) {
8490 return false;
8491 }
8492 PersistableBundle pb = configManager.getConfigForSubId(subId);
8493 if (pb == null) {
8494 return false;
8495 }
8496 return pb.getBoolean(
8497 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8498 }
8499
Shuo Qiandd210312017-04-12 22:11:33 +00008500 /**
8501 * Check if phone is in emergency callback mode
8502 * @return true if phone is in emergency callback mode
8503 * @param subId sub id
8504 */
goneil9c5f4872017-12-05 14:07:56 -08008505 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008506 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008507 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008508 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008509
8510 final long identity = Binder.clearCallingIdentity();
8511 try {
8512 if (phone != null) {
8513 return phone.isInEcm();
8514 } else {
8515 return false;
8516 }
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008519 }
8520 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008521
8522 /**
8523 * Get the current signal strength information for the given subscription.
8524 * Because this information is not updated when the device is in a low power state
8525 * it should not be relied-upon to be current.
8526 * @param subId Subscription index
8527 * @return the most recent cached signal strength info from the modem
8528 */
8529 @Override
8530 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008531 final long identity = Binder.clearCallingIdentity();
8532 try {
8533 Phone p = getPhone(subId);
8534 if (p == null) {
8535 return null;
8536 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008538 return p.getSignalStrength();
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
8541 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008542 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008543
Pengquan Meng77b7f132018-08-22 14:49:57 -07008544 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008545 * Get the current modem radio state for the given slot.
8546 * @param slotIndex slot index.
8547 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008548 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008549 * @return the current radio power state from the modem
8550 */
8551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008552 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008553 Phone phone = PhoneFactory.getPhone(slotIndex);
8554 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8556 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008557 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8558 }
8559
8560 final long identity = Binder.clearCallingIdentity();
8561 try {
8562 return phone.getRadioPowerState();
8563 } finally {
8564 Binder.restoreCallingIdentity(identity);
8565 }
8566 }
8567 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8568 }
8569
8570 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008571 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8572 *
8573 * <p>Requires one of the following permissions:
8574 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008575 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008576 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8577 * privileges.
8578 *
8579 * @param subId subscription id
8580 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8581 * {@code false}.
8582 */
8583 @Override
8584 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008585 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008586 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008587 try {
8588 mApp.enforceCallingOrSelfPermission(
8589 android.Manifest.permission.ACCESS_NETWORK_STATE,
8590 functionName);
8591 } catch (Exception e) {
8592 mApp.enforceCallingOrSelfPermission(
8593 permission.READ_BASIC_PHONE_STATE, functionName);
8594 }
Shuo Qian093013d2020-08-13 15:42:55 -07008595 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008596 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008597 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008598 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008599
Pengquan Menga1bb6272018-09-06 09:59:22 -07008600 boolean isEnabled = false;
8601 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008602 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008603 Phone phone = getPhone(subId);
8604 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008605 } finally {
8606 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008608 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008609 }
8610
8611
8612 /**
8613 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8614 *
8615 * <p> Requires permission:
8616 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8617 * privileges.
8618 *
8619 * @param subId subscription id
8620 * @param isEnabled {@code true} means enable, {@code false} means disable.
8621 */
8622 @Override
8623 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8625 mApp, subId, "setDataRoamingEnabled");
8626
Pengquan Menga1bb6272018-09-06 09:59:22 -07008627 final long identity = Binder.clearCallingIdentity();
8628 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008629 Phone phone = getPhone(subId);
8630 if (phone != null) {
8631 phone.setDataRoamingEnabled(isEnabled);
8632 }
8633 } finally {
8634 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008635 }
8636 }
8637
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008638 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008639 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008640 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008641 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008642 mApp, subId, "isManualNetworkSelectionAllowed");
8643
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008644 boolean isAllowed = true;
8645 final long identity = Binder.clearCallingIdentity();
8646 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008647 Phone phone = getPhone(subId);
8648 if (phone != null) {
8649 isAllowed = phone.isCspPlmnEnabled();
8650 }
8651 } finally {
8652 Binder.restoreCallingIdentity(identity);
8653 }
8654 return isAllowed;
8655 }
8656
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008657 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8658 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8659 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8660 // Update each UiccPort object based on privilege access
8661 UiccPort[] uiccPorts = card.getUiccPortList();
8662 for (UiccPort port : uiccPorts) {
8663 UiccProfile profile = port.getUiccProfile();
8664 if (profile == null ||
8665 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8666 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8667 return false;
8668 }
8669 }
8670 return true;
8671 }
8672
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008673 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008674 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008675 // Verify that tha callingPackage belongs to the calling UID
8676 mApp.getSystemService(AppOpsManager.class)
8677 .checkPackage(Binder.getCallingUid(), callingPackage);
8678
Jordan Liu1e142fc2019-04-22 15:10:43 -07008679 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008680 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008681 try {
8682 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008683 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008684 } catch (SecurityException e) {
8685 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8686 // has carrier privileges on an active UICC
8687 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8688 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008689 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008690 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008691 }
sandeepjs0a502c42021-09-27 15:34:44 +00008692 // checking compatibility, if calling app's target SDK is T and beyond.
8693 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8694 Binder.getCallingUid())) {
8695 isIccIdAccessRestricted = true;
8696 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008697 final long identity = Binder.clearCallingIdentity();
8698 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008699 UiccController uiccController = UiccController.getInstance();
8700 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008701 if (hasReadPermission) {
8702 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008703 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008704
8705 // Remove private info if the caller doesn't have access
8706 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8707 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008708 //setting the value after compatibility check
8709 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008710 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8711 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008712 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008713 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8714 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8715 if (card == null || card.getUiccPortList().length == 0) {
8716 // assume no access if the card or ports are unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008717 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008718 continue;
8719 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008720
8721 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008722 filteredInfos.add(cardInfo);
8723 } else {
sandeepjs0a502c42021-09-27 15:34:44 +00008724 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008725 }
8726 }
8727 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008728 } finally {
8729 Binder.restoreCallingIdentity(identity);
8730 }
8731 }
8732
sandeepjs0a502c42021-09-27 15:34:44 +00008733 /**
8734 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8735 * generally private and require carrier privileges to view.
8736 *
8737 * @hide
8738 */
8739 @NonNull
8740 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8741 List<UiccPortInfo> portinfo = new ArrayList<>();
8742 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8743 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8744 }
8745 return new UiccCardInfo(
8746 cardInfo.isEuicc(),
8747 cardInfo.getCardId(),
8748 null,
8749 cardInfo.getPhysicalSlotIndex(),
8750 cardInfo.isRemovable(),
8751 cardInfo.isMultipleEnabledProfilesSupported(),
8752 portinfo
8753 );
8754 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008755
sandeepjs0a502c42021-09-27 15:34:44 +00008756 /**
8757 * @hide
8758 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8759 * These values are generally private and require carrier privileges to view.
8760 */
8761 @NonNull
8762 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8763 return new UiccPortInfo(
8764 UiccPortInfo.ICCID_REDACTED,
8765 portInfo.getPortIndex(),
8766 portInfo.getLogicalSlotIndex(),
8767 portInfo.isActive()
8768 );
8769 }
8770 @Override
8771 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
8772 // Verify that tha callingPackage belongs to the calling UID
8773 mApp.getSystemService(AppOpsManager.class)
8774 .checkPackage(Binder.getCallingUid(), callingPackage);
8775
8776 boolean hasReadPermission = false;
8777 boolean isLogicalSlotAccessRestricted = false;
8778 String iccId;
8779
8780 try {
8781 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8782 hasReadPermission = true;
8783 } catch (SecurityException e) {
8784 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8785 // has carrier privileges on an active UICC
8786 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8787 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8788 hasReadPermission = true;
8789 }
8790 }
8791
8792 // checking compatibility, if calling app's target SDK is T and beyond.
8793 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8794 Binder.getCallingUid())) {
8795 isLogicalSlotAccessRestricted = true;
8796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008797 final long identity = Binder.clearCallingIdentity();
8798 try {
8799 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8800 if (slots == null) {
8801 Rlog.i(LOG_TAG, "slots is null.");
8802 return null;
8803 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008804 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8805 for (int i = 0; i < slots.length; i++) {
8806 UiccSlot slot = slots[i];
8807 if (slot == null) {
8808 continue;
8809 }
8810
Jordan Liu7be7e652019-05-06 18:55:02 +00008811 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008812 UiccCard card = slot.getUiccCard();
sandeepjs0a502c42021-09-27 15:34:44 +00008813 //if has read permission
8814 if (hasReadPermission) {
8815 iccId = slot.getIccId();
8816 } else {
8817 // if no read permission checking carrier
8818 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
8819 iccId = slot.getIccId();
8820 } else {
8821 //if no carrier permission redact ICCID
8822 iccId = IccUtils.TEST_ICCID;
8823 }
8824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008825 if (card != null) {
8826 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008827 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008828 cardId = slot.getEid();
8829 if (TextUtils.isEmpty(cardId)) {
sandeepjs0a502c42021-09-27 15:34:44 +00008830 cardId = iccId;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008831 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008832 }
8833
Jordan Liu857451f2019-05-09 16:35:35 -07008834 if (cardId != null) {
8835 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8836 // if cardId is an EID, it's all digits so this is fine
8837 cardId = IccUtils.stripTrailingFs(cardId);
8838 }
8839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008840 int cardState = 0;
8841 switch (slot.getCardState()) {
8842 case CARDSTATE_ABSENT:
8843 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8844 break;
8845 case CARDSTATE_PRESENT:
8846 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8847 break;
8848 case CARDSTATE_ERROR:
8849 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8850 break;
8851 case CARDSTATE_RESTRICTED:
8852 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8853 break;
8854 default:
8855 break;
8856
8857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008858 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008859 slot.isEuicc(),
8860 cardId,
8861 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008862 slot.isExtendedApduSupported(),
sandeepjs0a502c42021-09-27 15:34:44 +00008863 slot.isRemovable(), Collections.singletonList(
8864 new UiccPortInfo(
8865 iccId,
8866 0 /* TODO: to use portList from UiccSlots */,
8867 slot.getPhoneId(),
8868 slot.isActive())));
8869 //setting the value after compatibility check
8870 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008871 }
8872 return infos;
8873 } finally {
8874 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008875 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008876 }
8877
8878 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008879 @Deprecated
8880 //TODO : once integrating with HAL Changes we can clean up this Internal API.
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008881 public boolean switchSlots(int[] physicalSlots) {
8882 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008883
8884 final long identity = Binder.clearCallingIdentity();
8885 try {
8886 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8887 } finally {
8888 Binder.restoreCallingIdentity(identity);
8889 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008890 }
Jack Yu4c988042018-02-27 15:30:01 -08008891
8892 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008893 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8894 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8895 enforceModifyPermission();
8896
8897 final long identity = Binder.clearCallingIdentity();
8898 try {
8899 //TODO: once integrating the HAL changes we can proceed with to work on the parsing side
8900 int[] physicalSlots = new int[slotMapping.size()];
8901 for (int i = 0; i < physicalSlots.length; i++) {
8902 physicalSlots[i] = slotMapping.get(i).getPhysicalSlotIndex();
8903 }
8904 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8905 } finally {
8906 Binder.restoreCallingIdentity(identity);
8907 }
8908 }
8909
8910 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008911 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008912 final long identity = Binder.clearCallingIdentity();
8913 try {
8914 return UiccController.getInstance().getCardIdForDefaultEuicc();
8915 } finally {
8916 Binder.restoreCallingIdentity(identity);
8917 }
8918 }
8919
Pengquan Meng85728fb2018-03-12 16:31:21 -07008920 /**
goneil47ffb6e2018-04-06 15:40:58 -07008921 * A test API to reload the UICC profile.
8922 *
8923 * <p>Requires that the calling app has permission
8924 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8925 * @hide
8926 */
8927 @Override
8928 public void refreshUiccProfile(int subId) {
8929 enforceModifyPermission();
8930
8931 final long identity = Binder.clearCallingIdentity();
8932 try {
8933 Phone phone = getPhone(subId);
8934 if (phone == null) {
8935 return;
8936 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008937 UiccPort uiccPort = phone.getUiccPort();
8938 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008939 return;
8940 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008941 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008942 if (uiccProfile == null) {
8943 return;
8944 }
8945 uiccProfile.refresh();
8946 } finally {
8947 Binder.restoreCallingIdentity(identity);
8948 }
8949 }
8950
8951 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008952 * Returns false if the mobile data is disabled by default, otherwise return true.
8953 */
8954 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008955 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008956 }
8957
8958 /**
8959 * Returns true if the data roaming is enabled by default, i.e the system property
8960 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8961 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8962 */
8963 private boolean getDefaultDataRoamingEnabled(int subId) {
8964 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008965 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008966 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008967 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8968 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8969 return isDataRoamingEnabled;
8970 }
8971
8972 /**
8973 * Returns the default network type for the given {@code subId}, if the default network type is
8974 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8975 */
8976 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008977 List<Integer> list = TelephonyProperties.default_network();
8978 int phoneId = mSubscriptionController.getPhoneId(subId);
8979 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8980 return list.get(phoneId);
8981 }
8982 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008983 }
fionaxua13278b2018-03-21 00:08:13 -07008984
8985 @Override
8986 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008987 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008988 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008989
8990 final long identity = Binder.clearCallingIdentity();
8991 try {
8992 final Phone phone = getPhone(subId);
8993 if (phone == null) {
8994 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8995 return;
8996 }
chen xueaba88a2019-03-15 13:15:10 -07008997 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8998 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008999 if (carrierPrivilegeRules == null) {
9000 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9001 } else {
9002 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009004 } finally {
9005 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009006 }
fionaxua13278b2018-03-21 00:08:13 -07009007 }
9008
9009 @Override
9010 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009011 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009012
9013 final long identity = Binder.clearCallingIdentity();
9014 try {
9015 final Phone phone = getPhone(subId);
9016 if (phone == null) {
9017 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9018 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9019 }
9020 return phone.getCarrierIdListVersion();
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009023 }
fionaxua13278b2018-03-21 00:08:13 -07009024 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009025
9026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009027 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9028 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009030 mApp, subId, callingPackage, callingFeatureId,
9031 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009032 return -1;
9033 }
9034
9035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9038 } finally {
9039 Binder.restoreCallingIdentity(identity);
9040 }
9041 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009042
9043 @Override
9044 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009045 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009046 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009047 mApp, subId, "getCdmaRoamingMode");
9048
9049 final long identity = Binder.clearCallingIdentity();
9050 try {
9051 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9052 } finally {
9053 Binder.restoreCallingIdentity(identity);
9054 }
9055 }
9056
9057 @Override
9058 public boolean setCdmaRoamingMode(int subId, int mode) {
9059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9060 mApp, subId, "setCdmaRoamingMode");
9061
9062 final long identity = Binder.clearCallingIdentity();
9063 try {
9064 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9065 } finally {
9066 Binder.restoreCallingIdentity(identity);
9067 }
9068 }
9069
9070 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009071 public int getCdmaSubscriptionMode(int subId) {
9072 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009073 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009074 mApp, subId, "getCdmaSubscriptionMode");
9075
9076 final long identity = Binder.clearCallingIdentity();
9077 try {
9078 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9079 } finally {
9080 Binder.restoreCallingIdentity(identity);
9081 }
9082 }
9083
9084 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009085 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9087 mApp, subId, "setCdmaSubscriptionMode");
9088
9089 final long identity = Binder.clearCallingIdentity();
9090 try {
9091 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
9095 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009096
sqianc5eccab2018-10-19 18:46:41 -07009097 @Override
sqian8c685422019-02-22 15:55:18 -08009098 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009099 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009101 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9102 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009103 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9104 }
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
sqian854d44b2018-12-12 16:48:18 -08009107 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9108 for (Phone phone: PhoneFactory.getPhones()) {
9109 if (phone.getEmergencyNumberTracker() != null
9110 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9111 emergencyNumberListInternal.put(
9112 phone.getSubId(),
9113 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9114 }
sqian11b7a0e2018-12-05 18:48:28 -08009115 }
sqian854d44b2018-12-12 16:48:18 -08009116 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009117 } finally {
9118 Binder.restoreCallingIdentity(identity);
9119 }
sqianc5eccab2018-10-19 18:46:41 -07009120 }
9121
9122 @Override
sqian8c685422019-02-22 15:55:18 -08009123 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009124 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009125 if (!exactMatch) {
9126 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009127 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009128 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009129 }
9130 final long identity = Binder.clearCallingIdentity();
9131 try {
sqian854d44b2018-12-12 16:48:18 -08009132 for (Phone phone: PhoneFactory.getPhones()) {
9133 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009134 && phone.getEmergencyNumberTracker()
9135 .isEmergencyNumber(number, exactMatch)) {
9136 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009137 }
sqian11b7a0e2018-12-05 18:48:28 -08009138 }
9139 return false;
9140 } finally {
9141 Binder.restoreCallingIdentity(identity);
9142 }
9143 }
9144
sqianf4ca7ed2019-01-15 18:32:07 -08009145 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009146 * Start emergency callback mode for GsmCdmaPhone for testing.
9147 */
9148 @Override
9149 public void startEmergencyCallbackMode() {
9150 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9151 "startEmergencyCallbackMode");
9152 enforceModifyPermission();
9153 final long identity = Binder.clearCallingIdentity();
9154 try {
9155 for (Phone phone : PhoneFactory.getPhones()) {
9156 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9157 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9158 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9159 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9160 gsmCdmaPhone.obtainMessage(
9161 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9162 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9163 }
9164 }
9165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
9168 }
9169
9170 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009171 * Update emergency number list for test mode.
9172 */
9173 @Override
9174 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9175 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9176 "updateEmergencyNumberListTestMode");
9177
9178 final long identity = Binder.clearCallingIdentity();
9179 try {
9180 for (Phone phone: PhoneFactory.getPhones()) {
9181 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9182 if (tracker != null) {
9183 tracker.executeEmergencyNumberTestModeCommand(action, num);
9184 }
9185 }
9186 } finally {
9187 Binder.restoreCallingIdentity(identity);
9188 }
9189 }
9190
9191 /**
9192 * Get the full emergency number list for test mode.
9193 */
9194 @Override
9195 public List<String> getEmergencyNumberListTestMode() {
9196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9197 "getEmergencyNumberListTestMode");
9198
9199 final long identity = Binder.clearCallingIdentity();
9200 try {
9201 Set<String> emergencyNumbers = new HashSet<>();
9202 for (Phone phone: PhoneFactory.getPhones()) {
9203 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9204 if (tracker != null) {
9205 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9206 emergencyNumbers.add(num.getNumber());
9207 }
9208 }
9209 }
9210 return new ArrayList<>(emergencyNumbers);
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 }
9215
chen xud6b45bd2018-10-30 22:27:10 -07009216 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009217 public int getEmergencyNumberDbVersion(int subId) {
9218 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9219
9220 final long identity = Binder.clearCallingIdentity();
9221 try {
9222 final Phone phone = getPhone(subId);
9223 if (phone == null) {
9224 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9225 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9226 }
9227 return phone.getEmergencyNumberDbVersion();
9228 } finally {
9229 Binder.restoreCallingIdentity(identity);
9230 }
9231 }
9232
9233 @Override
9234 public void notifyOtaEmergencyNumberDbInstalled() {
9235 enforceModifyPermission();
9236
9237 final long identity = Binder.clearCallingIdentity();
9238 try {
9239 for (Phone phone: PhoneFactory.getPhones()) {
9240 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9241 if (tracker != null) {
9242 tracker.updateOtaEmergencyNumberDatabase();
9243 }
9244 }
9245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
9248 }
9249
9250 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009251 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009252 enforceActiveEmergencySessionPermission();
9253
9254 final long identity = Binder.clearCallingIdentity();
9255 try {
9256 for (Phone phone: PhoneFactory.getPhones()) {
9257 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9258 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009259 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9260 }
9261 }
9262 } finally {
9263 Binder.restoreCallingIdentity(identity);
9264 }
9265 }
9266
9267 @Override
9268 public void resetOtaEmergencyNumberDbFilePath() {
9269 enforceActiveEmergencySessionPermission();
9270
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 for (Phone phone: PhoneFactory.getPhones()) {
9274 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9275 if (tracker != null) {
9276 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009277 }
9278 }
9279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
9283
9284 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009285 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9286 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9287 Phone phone = getPhone(subId);
9288 if (phone == null) {
9289 return null;
9290 }
9291 final long identity = Binder.clearCallingIdentity();
9292 try {
9293 UiccProfile profile = UiccController.getInstance()
9294 .getUiccProfileForPhone(phone.getPhoneId());
9295 if (profile != null) {
9296 return profile.getCertsFromCarrierPrivilegeAccessRules();
9297 }
9298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 return null;
9302 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009303
9304 /**
9305 * Enable or disable a modem stack.
9306 */
9307 @Override
9308 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9309 enforceModifyPermission();
9310
9311 final long identity = Binder.clearCallingIdentity();
9312 try {
9313 Phone phone = PhoneFactory.getPhone(slotIndex);
9314 if (phone == null) {
9315 return false;
9316 } else {
9317 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9318 }
9319 } finally {
9320 Binder.restoreCallingIdentity(identity);
9321 }
9322 }
Michelecea4cf22018-12-21 15:00:11 -08009323
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009324 /**
9325 * Whether a modem stack is enabled or not.
9326 */
9327 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009328 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9329 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009330 Phone phone = PhoneFactory.getPhone(slotIndex);
9331 if (phone == null) return false;
9332
9333 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009334 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9335 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009336 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9337 }
9338
9339 final long identity = Binder.clearCallingIdentity();
9340 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009341 try {
9342 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9343 } catch (NoSuchElementException ex) {
9344 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9345 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009346 } finally {
9347 Binder.restoreCallingIdentity(identity);
9348 }
9349 }
9350
Michelecea4cf22018-12-21 15:00:11 -08009351 @Override
Michele0ea7d782019-03-19 14:58:42 -07009352 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009353 enforceModifyPermission();
9354
9355 final long identity = Binder.clearCallingIdentity();
9356 try {
9357 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009358 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009359 .commit();
9360 } finally {
9361 Binder.restoreCallingIdentity(identity);
9362 }
9363 }
9364
9365 @Override
Michele0ea7d782019-03-19 14:58:42 -07009366 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009367 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009369 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9370 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009371 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009372 }
Michelecea4cf22018-12-21 15:00:11 -08009373
9374 final long identity = Binder.clearCallingIdentity();
9375 try {
Michele0ea7d782019-03-19 14:58:42 -07009376 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009377 } finally {
9378 Binder.restoreCallingIdentity(identity);
9379 }
9380 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009381
Michele0ea7d782019-03-19 14:58:42 -07009382 @TelephonyManager.IsMultiSimSupportedResult
9383 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009384 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9385 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9386 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009387 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9388 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009389 }
9390 // Check if the hardware supports multisim functionality. If usage of multisim is not
9391 // supported by the modem, indicate that it is restricted.
9392 PhoneCapability staticCapability =
9393 mPhoneConfigurationManager.getStaticPhoneCapability();
9394 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009395 loge("isMultiSimSupportedInternal: no static configuration available");
9396 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009397 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009398 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009399 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9400 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009401 }
9402 // Check if support of multiple SIMs is restricted by carrier
9403 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009404 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009405 }
9406
Michele0ea7d782019-03-19 14:58:42 -07009407 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009408 }
9409
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009410 /**
9411 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009412 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9413 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9414 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009415 * @param numOfSims number of active sims we want to switch to
9416 */
9417 @Override
9418 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009419 if (numOfSims == 1) {
9420 enforceModifyPermission();
9421 } else {
9422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9423 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9424 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009425 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009426
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009427 try {
Michele30b57b22019-03-01 12:01:14 -08009428 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009429 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009430 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9431 return;
9432 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009433 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9434 } finally {
9435 Binder.restoreCallingIdentity(identity);
9436 }
9437 }
9438
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009439 @Override
9440 public boolean isApplicationOnUicc(int subId, int appType) {
9441 enforceReadPrivilegedPermission("isApplicationOnUicc");
9442 Phone phone = getPhone(subId);
9443 if (phone == null) {
9444 return false;
9445 }
9446 final long identity = Binder.clearCallingIdentity();
9447 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009448 UiccPort uiccPort = phone.getUiccPort();
9449 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009450 return false;
9451 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009452 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009453 if (uiccProfile == null) {
9454 return false;
9455 }
9456 if (TelephonyManager.APPTYPE_SIM <= appType
9457 && appType <= TelephonyManager.APPTYPE_ISIM) {
9458 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9459 }
9460 return false;
9461 } finally {
9462 Binder.restoreCallingIdentity(identity);
9463 }
9464 }
9465
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009466 /**
chen xub4baa772019-04-03 10:23:41 -07009467 * Get whether making changes to modem configurations will trigger reboot.
9468 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009469 */
9470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009471 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9472 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009474 mApp, subId, callingPackage, callingFeatureId,
9475 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009476 return false;
9477 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009478 final long identity = Binder.clearCallingIdentity();
9479 try {
9480 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9481 } finally {
9482 Binder.restoreCallingIdentity(identity);
9483 }
9484 }
9485
Nathan Harold29f5f052019-02-15 13:41:57 -08009486 private void updateModemStateMetrics() {
9487 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9488 // TODO: check the state for each modem if the api is ready.
9489 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9490 }
9491
Pengquan Meng3889a572019-01-23 11:16:29 -08009492 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00009493 public int[] getSlotsMapping(@NonNull String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009494 enforceReadPrivilegedPermission("getSlotsMapping");
9495
9496 final long identity = Binder.clearCallingIdentity();
9497 try {
9498 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9499 // All logical slots should have a mapping to a physical slot.
9500 int[] logicalSlotsMapping = new int[phoneCount];
sandeepjs0a502c42021-09-27 15:34:44 +00009501 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009502 for (int i = 0; i < slotInfos.length; i++) {
9503 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9504 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9505 }
9506 }
9507 return logicalSlotsMapping;
9508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009512
9513 /**
9514 * Get the IRadio HAL Version
9515 */
9516 @Override
9517 public int getRadioHalVersion() {
9518 Phone phone = getDefaultPhone();
9519 if (phone == null) return -1;
9520 HalVersion hv = phone.getHalVersion();
9521 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9522 return hv.major * 100 + hv.minor;
9523 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009524
9525 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009526 * Get the current calling package name.
9527 * @return the current calling package name
9528 */
9529 @Override
9530 public String getCurrentPackageName() {
9531 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9532 }
9533
9534 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009535 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9536 * corresponding network requests on a subId.
9537 *
9538 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009539 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009540 * 2) APN is un-metered for this subscription, or
9541 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009542 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009543 *
9544 * @return whether data is allowed for a apn type.
9545 *
9546 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009547 */
9548 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009549 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009550 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9551 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009552
9553 // Now that all security checks passes, perform the operation as ourselves.
9554 final long identity = Binder.clearCallingIdentity();
9555 try {
9556 Phone phone = getPhone(subId);
9557 if (phone == null) return false;
9558
Jack Yu41407ee2019-05-13 16:54:09 -07009559 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009560 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 }
9565
9566 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009567 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009568 enforceReadPrivilegedPermission("isApnMetered");
9569
9570 // Now that all security checks passes, perform the operation as ourselves.
9571 final long identity = Binder.clearCallingIdentity();
9572 try {
9573 Phone phone = getPhone(subId);
9574 if (phone == null) return true; // By default return true.
9575
Jack Yu41407ee2019-05-13 16:54:09 -07009576 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009577 } finally {
9578 Binder.restoreCallingIdentity(identity);
9579 }
9580 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009581
9582 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009583 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9584 int subscriptionId, IBooleanConsumer resultCallback) {
9585 enforceModifyPermission();
9586 long token = Binder.clearCallingIdentity();
9587 try {
9588 Phone phone = getPhone(subscriptionId);
9589 if (phone == null) {
9590 try {
9591 if (resultCallback != null) {
9592 resultCallback.accept(false);
9593 }
9594 } catch (RemoteException e) {
9595 // ignore
9596 }
9597 return;
9598 }
9599 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9600 Pair.create(specifiers, (x) -> {
9601 try {
9602 if (resultCallback != null) {
9603 resultCallback.accept(x);
9604 }
9605 } catch (RemoteException e) {
9606 // ignore
9607 }
9608 });
9609 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9610 } finally {
9611 Binder.restoreCallingIdentity(token);
9612 }
9613 }
9614
9615 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009616 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9617 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009618 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009619 mApp, subId, "getSystemSelectionChannels");
9620 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9621 final long identity = Binder.clearCallingIdentity();
9622 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009623 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9624 if (result instanceof IllegalStateException) {
9625 throw (IllegalStateException) result;
9626 }
9627 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009628 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9629 return specifiers;
9630 } finally {
9631 Binder.restoreCallingIdentity(identity);
9632 }
9633 }
9634
9635 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009636 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009637 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009638 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9639 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9640 if (iccRecords == null) {
9641 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9642 return false;
9643 }
9644 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9645 }
9646
9647 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009648 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9649 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009650 if (callingPackage == null) {
9651 callingPackage = getCurrentPackageName();
9652 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009653 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9654 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009655 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9656 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009657 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9658 }
9659 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9660 Intent intent = new Intent();
9661 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9662 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9663 // Bring up choose default SMS subscription dialog right now
9664 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9665 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9666 mApp.startActivity(intent);
9667 }
chen xud5ca2d52019-05-28 15:20:57 -07009668
9669 @Override
9670 public String getMmsUAProfUrl(int subId) {
9671 //TODO investigate if this API should require proper permission check in R b/133791609
9672 final long identity = Binder.clearCallingIdentity();
9673 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009674 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9675 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9676 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9677 return carrierUAProfUrl;
9678 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009679 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9680 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009681 } finally {
9682 Binder.restoreCallingIdentity(identity);
9683 }
9684 }
9685
9686 @Override
9687 public String getMmsUserAgent(int subId) {
9688 //TODO investigate if this API should require proper permission check in R b/133791609
9689 final long identity = Binder.clearCallingIdentity();
9690 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009691 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9692 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9693 if (!TextUtils.isEmpty(carrierUserAgent)) {
9694 return carrierUserAgent;
9695 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009696 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9697 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009698 } finally {
9699 Binder.restoreCallingIdentity(identity);
9700 }
9701 }
Jack Yub07d4972019-05-28 16:12:25 -07009702
9703 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009704 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9705 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009706
Jack Yub07d4972019-05-28 16:12:25 -07009707 final long identity = Binder.clearCallingIdentity();
9708 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009709 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009710 if (phone == null) return false;
9711
Hall Liua62f5da2020-09-25 10:42:19 -07009712 switch (policy) {
9713 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9714 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9715 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9716 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9717 default:
9718 throw new IllegalArgumentException(policy + " is not a valid policy");
9719 }
Jack Yub07d4972019-05-28 16:12:25 -07009720 } finally {
9721 Binder.restoreCallingIdentity(identity);
9722 }
9723 }
9724
9725 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009726 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009727 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009728 enforceModifyPermission();
9729
changbettyd5c246e2019-12-24 15:40:37 +08009730 final long identity = Binder.clearCallingIdentity();
9731 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009732 Phone phone = getPhone(subscriptionId);
9733 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009734
Hall Liua62f5da2020-09-25 10:42:19 -07009735 switch (policy) {
9736 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9737 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9738 break;
9739 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9740 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9741 break;
9742 default:
9743 throw new IllegalArgumentException(policy + " is not a valid policy");
9744 }
changbettyd5c246e2019-12-24 15:40:37 +08009745 } finally {
9746 Binder.restoreCallingIdentity(identity);
9747 }
9748 }
9749
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009750 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009751 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009752 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9753 * otherwise.
9754 */
9755 @Override
9756 public void setCepEnabled(boolean isCepEnabled) {
9757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9758
9759 final long identity = Binder.clearCallingIdentity();
9760 try {
9761 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9762 for (Phone phone : PhoneFactory.getPhones()) {
9763 Phone defaultPhone = phone.getImsPhone();
9764 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9765 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9766 ImsPhoneCallTracker imsPhoneCallTracker =
9767 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9768 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9769 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9770 + imsPhone.getMsisdn());
9771 }
9772 }
9773 } finally {
9774 Binder.restoreCallingIdentity(identity);
9775 }
9776 }
allenwtsu46dcc572020-01-08 18:24:03 +08009777
9778 /**
9779 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9780 *
9781 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9782 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9783 * before being read.
9784 */
9785 @Override
9786 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9787 isCompressed) {
9788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9789 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9791 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9792 }
9793 if (!isImsAvailableOnDevice()) {
9794 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9795 "IMS not available on device.");
9796 }
9797
9798 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009799 try {
Hui Wang761a6682020-10-31 05:12:53 +00009800 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9801 } finally {
9802 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009803 }
9804 }
zoey chene02881a2019-12-30 16:11:23 +08009805
9806 @Override
9807 public boolean isIccLockEnabled(int subId) {
9808 enforceReadPrivilegedPermission("isIccLockEnabled");
9809
9810 // Now that all security checks passes, perform the operation as ourselves.
9811 final long identity = Binder.clearCallingIdentity();
9812 try {
9813 Phone phone = getPhone(subId);
9814 if (phone != null && phone.getIccCard() != null) {
9815 return phone.getIccCard().getIccLockEnabled();
9816 } else {
9817 return false;
9818 }
9819 } finally {
9820 Binder.restoreCallingIdentity(identity);
9821 }
9822 }
9823
9824 /**
9825 * Set the ICC pin lock enabled or disabled.
9826 *
9827 * @return an integer representing the status of IccLock enabled or disabled in the following
9828 * three cases:
9829 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9830 * successfully.
9831 * - Positive number and zero for remaining password attempts.
9832 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9833 *
9834 */
9835 @Override
9836 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9837 enforceModifyPermission();
9838
9839 Phone phone = getPhone(subId);
9840 if (phone == null) {
9841 return 0;
9842 }
9843 // Now that all security checks passes, perform the operation as ourselves.
9844 final long identity = Binder.clearCallingIdentity();
9845 try {
9846 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9847 new Pair<Boolean, String>(enabled, password), phone, null);
9848 return attemptsRemaining;
9849
9850 } catch (Exception e) {
9851 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9852 } finally {
9853 Binder.restoreCallingIdentity(identity);
9854 }
9855 return 0;
9856 }
9857
9858 /**
9859 * Change the ICC password used in ICC pin lock.
9860 *
9861 * @return an integer representing the status of IccLock changed in the following three cases:
9862 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9863 * - Positive number and zero for remaining password attempts.
9864 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9865 *
9866 */
9867 @Override
9868 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9869 enforceModifyPermission();
9870
9871 Phone phone = getPhone(subId);
9872 if (phone == null) {
9873 return 0;
9874 }
9875 // Now that all security checks passes, perform the operation as ourselves.
9876 final long identity = Binder.clearCallingIdentity();
9877 try {
9878 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9879 new Pair<String, String>(oldPassword, newPassword), phone, null);
9880 return attemptsRemaining;
9881
9882 } catch (Exception e) {
9883 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9884 } finally {
9885 Binder.restoreCallingIdentity(identity);
9886 }
9887 return 0;
9888 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009889
9890 /**
9891 * Request for receiving user activity notification
9892 */
9893 @Override
9894 public void requestUserActivityNotification() {
9895 if (!mNotifyUserActivity.get()
9896 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9897 mNotifyUserActivity.set(true);
9898 }
9899 }
9900
9901 /**
9902 * Called when userActivity is signalled in the power manager.
9903 * This is safe to call from any thread, with any window manager locks held or not.
9904 */
9905 @Override
9906 public void userActivity() {
9907 // ***************************************
9908 // * Inherited from PhoneWindowManager *
9909 // ***************************************
9910 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9911 // WITH ITS LOCKS HELD.
9912 //
9913 // This code must be VERY careful about the locks
9914 // it acquires.
9915 // In fact, the current code acquires way too many,
9916 // and probably has lurking deadlocks.
9917
9918 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9919 throw new SecurityException("Only the OS may call notifyUserActivity()");
9920 }
9921
9922 if (mNotifyUserActivity.getAndSet(false)) {
9923 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9924 USER_ACTIVITY_NOTIFICATION_DELAY);
9925 }
9926 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009927
9928 @Override
9929 public boolean canConnectTo5GInDsdsMode() {
9930 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9931 }
Jack Yud10cdd42020-09-28 20:28:01 -07009932
9933 @Override
9934 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9935 String callingFeatureId) {
9936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9937 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9938 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9939 }
9940
9941 Phone phone = getPhone(subId);
9942 if (phone == null) {
9943 throw new RuntimeException("phone is not available");
9944 }
9945 // Now that all security checks passes, perform the operation as ourselves.
9946 final long identity = Binder.clearCallingIdentity();
9947 try {
9948 return phone.getEquivalentHomePlmns();
9949 } finally {
9950 Binder.restoreCallingIdentity(identity);
9951 }
9952 }
Daniel Bright59e67312020-11-13 11:49:37 -08009953
9954 @Override
9955 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009956 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9957 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009958 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009959 if (radioInterfaceCapabilities == null) {
9960 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009961 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009962 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009963 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009964
Hui Wang641e81c2020-10-12 12:14:23 -07009965 @Override
9966 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9967 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009968 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9969 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9970 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9971 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9972 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009973 if (DBG) {
9974 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9975 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9976 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9977 }
9978
9979 if (!SubscriptionManager.isValidSubscriptionId(subId)
9980 || appType < TelephonyManager.APPTYPE_UNKNOWN
9981 || appType > TelephonyManager.APPTYPE_ISIM
9982 || nafUrl == null || securityProtocol == null || callback == null) {
9983 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9984 if (callback != null) {
9985 try {
9986 callback.onAuthenticationFailure(
9987 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9988 } catch (RemoteException exception) {
9989 log("Fail to notify onAuthenticationFailure due to " + exception);
9990 }
9991 return;
9992 }
9993 }
9994
9995 final long token = Binder.clearCallingIdentity();
9996 try {
9997 getGbaManager(subId).bootstrapAuthenticationRequest(
9998 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9999 forceBootStrapping, callback));
10000 } finally {
10001 Binder.restoreCallingIdentity(token);
10002 }
10003 }
10004
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010005 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010006 * Attempts to set the radio power state for all phones for thermal reason.
10007 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010008 * requested radio power state will actually be set. See {@link
10009 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10010 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010011 * @param enable {@code true} if trying to turn radio on.
10012 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10013 * false}.
10014 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010015 private boolean setRadioPowerForThermal(boolean enable) {
10016 boolean isPhoneAvailable = false;
10017 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10018 Phone phone = PhoneFactory.getPhone(i);
10019 if (phone != null) {
10020 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10021 isPhoneAvailable = true;
10022 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010023 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010024
10025 // return true if successfully informed the phone object about the thermal radio power
10026 // request.
10027 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010028 }
10029
10030 private int handleDataThrottlingRequest(int subId,
10031 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010032 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10033 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10034 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10035 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10036 throw new IllegalArgumentException("modem does not support data throttling");
10037 }
10038
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010039 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10040 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010041 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010042 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10043 }
10044
10045 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10046
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010047 if (isDataThrottlingSupported) {
10048 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010049 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010050 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10051 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10052 } else if (thermalMitigationResult
10053 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010054 log("Modem likely does not support data throttling on secondary carrier. Data " +
10055 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10056 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010057 }
10058 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010059 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010060
10061 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010062 }
10063
Jack Nudelman644b91a2021-03-12 14:09:48 -080010064 private static List<String> getThermalMitigationAllowlist(Context context) {
10065 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10066 for (String pckg : context.getResources()
10067 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10068 sThermalMitigationAllowlistedPackages.add(pckg);
10069 }
10070 }
10071
10072 return sThermalMitigationAllowlistedPackages;
10073 }
10074
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010075 private boolean isAnyPhoneInEmergencyState() {
10076 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10077 if (tm.isInEmergencyCall()) {
10078 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10079 return true;
10080 }
10081 for (Phone phone : PhoneFactory.getPhones()) {
10082 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10083 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10084 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10085 + phone.isInEcm());
10086 return true;
10087 }
10088 }
10089
10090 return false;
10091 }
10092
Jack Nudelman644b91a2021-03-12 14:09:48 -080010093 /**
10094 * Used by shell commands to add an authorized package name for thermal mitigation.
10095 * @param packageName name of package to be allowlisted
10096 * @param context
10097 */
10098 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10099 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10100 sThermalMitigationAllowlistedPackages.add(packageName);
10101 }
10102
10103 /**
10104 * Used by shell commands to remove an authorized package name for thermal mitigation.
10105 * @param packageName name of package to remove from allowlist
10106 * @param context
10107 */
10108 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10109 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10110 sThermalMitigationAllowlistedPackages.remove(packageName);
10111 }
10112
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010113 /**
10114 * Thermal mitigation request to control functionalities at modem.
10115 *
10116 * @param subId the id of the subscription.
10117 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010118 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010119 *
10120 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10121 */
10122 @Override
10123 @ThermalMitigationResult
10124 public int sendThermalMitigationRequest(
10125 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010126 ThermalMitigationRequest thermalMitigationRequest,
10127 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010128 enforceModifyPermission();
10129
Jack Nudelman644b91a2021-03-12 14:09:48 -080010130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10131 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10132 .contains(callingPackage)) {
10133 throw new SecurityException("Calling package must be configured in the device config. "
10134 + "calling package: " + callingPackage);
10135 }
10136
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10138 final long identity = Binder.clearCallingIdentity();
10139
10140 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10141 try {
10142 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10143 switch (thermalMitigationAction) {
10144 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10145 thermalMitigationResult =
10146 handleDataThrottlingRequest(subId,
10147 thermalMitigationRequest.getDataThrottlingRequest());
10148 break;
10149 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10150 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10151 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10152 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10153 }
10154
10155 // Ensure that radio is on. If not able to power on due to phone being
10156 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010157 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010158 thermalMitigationResult =
10159 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10160 break;
10161 }
10162
10163 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10164 false);
10165 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10166 break;
10167 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10168 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10169 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10170 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10171 }
10172
10173 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10174 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010175 Phone phone = getPhone(subId);
10176 if (phone == null) {
10177 thermalMitigationResult =
10178 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10179 break;
10180 }
10181
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010182 TelephonyConnectionService service =
10183 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010184 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010185 Log.e(LOG_TAG, "An emergency call is pending");
10186 thermalMitigationResult =
10187 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10188 break;
10189 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010190 thermalMitigationResult =
10191 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10192 break;
10193 }
10194 } else {
10195 thermalMitigationResult =
10196 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10197 break;
10198 }
10199
10200 // Turn radio off. If not able to power off due to phone being unavailable,
10201 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010202 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010203 thermalMitigationResult =
10204 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10205 break;
10206 }
10207 thermalMitigationResult =
10208 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10209 break;
10210 default:
10211 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10212 + "not exist. Requested action: " + thermalMitigationAction);
10213 }
10214 } catch (IllegalArgumentException e) {
10215 throw e;
10216 } catch (Exception e) {
10217 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10218 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10219 } finally {
10220 Binder.restoreCallingIdentity(identity);
10221 }
10222
10223 if (DBG) {
10224 log("thermalMitigationRequest returning with thermalMitigationResult: "
10225 + thermalMitigationResult);
10226 }
10227
10228 return thermalMitigationResult;
10229 }
Hui Wang641e81c2020-10-12 12:14:23 -070010230
10231 /**
10232 * Set the GbaService Package Name that Telephony will bind to.
10233 *
10234 * @param subId The sim that the GbaService is associated with.
10235 * @param packageName The name of the package to be replaced with.
10236 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10237 */
10238 @Override
10239 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10240 enforceModifyPermission();
10241
10242 final long identity = Binder.clearCallingIdentity();
10243 try {
10244 return getGbaManager(subId).overrideServicePackage(packageName);
10245 } finally {
10246 Binder.restoreCallingIdentity(identity);
10247 }
10248 }
10249
10250 /**
10251 * Return the package name of the currently bound GbaService.
10252 *
10253 * @param subId The sim that the GbaService is associated with.
10254 * @return the package name of the GbaService configuration, null if GBA is not supported.
10255 */
10256 @Override
10257 public String getBoundGbaService(int subId) {
10258 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10259
10260 final long identity = Binder.clearCallingIdentity();
10261 try {
10262 return getGbaManager(subId).getServicePackage();
10263 } finally {
10264 Binder.restoreCallingIdentity(identity);
10265 }
10266 }
10267
10268 /**
10269 * Set the release time for telephony to unbind GbaService.
10270 *
10271 * @param subId The sim that the GbaService is associated with.
10272 * @param interval The release time to unbind GbaService by millisecond.
10273 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10274 */
10275 @Override
10276 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10277 enforceModifyPermission();
10278
10279 final long identity = Binder.clearCallingIdentity();
10280 try {
10281 return getGbaManager(subId).overrideReleaseTime(interval);
10282 } finally {
10283 Binder.restoreCallingIdentity(identity);
10284 }
10285 }
10286
10287 /**
10288 * Return the release time for telephony to unbind GbaService.
10289 *
10290 * @param subId The sim that the GbaService is associated with.
10291 * @return The release time to unbind GbaService by millisecond.
10292 */
10293 @Override
10294 public int getGbaReleaseTime(int subId) {
10295 enforceReadPrivilegedPermission("getGbaReleaseTime");
10296
10297 final long identity = Binder.clearCallingIdentity();
10298 try {
10299 return getGbaManager(subId).getReleaseTime();
10300 } finally {
10301 Binder.restoreCallingIdentity(identity);
10302 }
10303 }
10304
10305 private GbaManager getGbaManager(int subId) {
10306 GbaManager instance = GbaManager.getInstance(subId);
10307 if (instance == null) {
10308 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10309 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10310 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10311 }
10312 return instance;
10313 }
Hui Wang761a6682020-10-31 05:12:53 +000010314
10315 /**
10316 * indicate whether the device and the carrier can support
10317 * RCS VoLTE single registration.
10318 */
10319 @Override
10320 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010321 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10322 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10323 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10324 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010325
10326 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10327 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10328 }
10329
10330 final long identity = Binder.clearCallingIdentity();
10331 try {
10332 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10333 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010334 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10335 if (isCapable != null) {
10336 return isCapable;
10337 }
Hui Wang761a6682020-10-31 05:12:53 +000010338 }
Hui Wang67af90e2021-06-04 16:57:15 -070010339 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10340 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010341 } finally {
10342 Binder.restoreCallingIdentity(identity);
10343 }
10344 }
10345
10346 /**
10347 * Register RCS provisioning callback.
10348 */
10349 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010350 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010351 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010352 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010353 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010354 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10355 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010356
10357 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10358 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10359 }
10360 if (!isImsAvailableOnDevice()) {
10361 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10362 "IMS not available on device.");
10363 }
10364
10365 final long identity = Binder.clearCallingIdentity();
10366 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010367 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010368 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010369 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10370 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010371 }
Hui Wang761a6682020-10-31 05:12:53 +000010372 } finally {
10373 Binder.restoreCallingIdentity(identity);
10374 }
10375 }
10376
10377 /**
10378 * Unregister RCS provisioning callback.
10379 */
10380 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010381 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010382 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010383 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010384 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010385 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10386 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010387
10388 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10389 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10390 }
10391 if (!isImsAvailableOnDevice()) {
10392 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10393 "IMS not available on device.");
10394 }
10395
10396 final long identity = Binder.clearCallingIdentity();
10397 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010398 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010399 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010400 } finally {
10401 Binder.restoreCallingIdentity(identity);
10402 }
10403 }
10404
10405 /**
10406 * trigger RCS reconfiguration.
10407 */
10408 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010409 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10410 "triggerRcsReconfiguration",
10411 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010412
10413 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10414 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10415 }
10416 if (!isImsAvailableOnDevice()) {
10417 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10418 "IMS not available on device.");
10419 }
10420
10421 final long identity = Binder.clearCallingIdentity();
10422 try {
10423 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10424 } finally {
10425 Binder.restoreCallingIdentity(identity);
10426 }
10427 }
10428
10429 /**
10430 * Provide the client configuration parameters of the RCS application.
10431 */
10432 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010433 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10434 "setRcsClientConfiguration",
10435 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010436
10437 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10438 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10439 }
10440 if (!isImsAvailableOnDevice()) {
10441 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10442 "IMS not available on device.");
10443 }
10444
10445 final long identity = Binder.clearCallingIdentity();
10446
10447 try {
10448 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10449 if (configBinder == null) {
10450 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010451 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10452 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010453 } else {
10454 configBinder.setRcsClientConfiguration(rcc);
10455 }
10456 } catch (RemoteException e) {
10457 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010458 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10459 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010460 } finally {
10461 Binder.restoreCallingIdentity(identity);
10462 }
10463 }
10464
10465 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010466 * Enables or disables the test mode for RCS VoLTE single registration.
10467 */
10468 @Override
10469 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10470 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10471 "setRcsSingleRegistrationTestModeEnabled");
10472
10473 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10474 }
10475
10476 /**
10477 * Gets the test mode for RCS VoLTE single registration.
10478 */
10479 @Override
10480 public boolean getRcsSingleRegistrationTestModeEnabled() {
10481 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10482 "getRcsSingleRegistrationTestModeEnabled");
10483
10484 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10485 }
10486
10487 /**
Hui Wang761a6682020-10-31 05:12:53 +000010488 * Overrides the config of RCS VoLTE single registration enabled for the device.
10489 */
10490 @Override
10491 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10492 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10493 "setDeviceSingleRegistrationEnabledOverride");
10494 enforceModifyPermission();
10495
10496 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10497 : Boolean.parseBoolean(enabledStr);
10498 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010499 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010500 }
10501
10502 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010503 * Sends a device to device communication message. Only usable via shell.
10504 * @param message message to send.
10505 * @param value message value.
10506 */
10507 @Override
10508 public void sendDeviceToDeviceMessage(int message, int value) {
10509 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010510 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010511 enforceModifyPermission();
10512
10513 final long identity = Binder.clearCallingIdentity();
10514 try {
10515 TelephonyConnectionService service =
10516 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10517 if (service == null) {
10518 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10519 return;
10520 }
10521 service.sendTestDeviceToDeviceMessage(message, value);
10522 } finally {
10523 Binder.restoreCallingIdentity(identity);
10524 }
10525 }
10526
Tyler Gunnbabbda02021-02-10 11:05:02 -080010527 /**
10528 * Sets the specified device to device transport active.
10529 * @param transport The transport to set active.
10530 */
10531 @Override
10532 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10533 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10534 "setActiveDeviceToDeviceTransport");
10535 enforceModifyPermission();
10536
10537 final long identity = Binder.clearCallingIdentity();
10538 try {
10539 TelephonyConnectionService service =
10540 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10541 if (service == null) {
10542 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10543 return;
10544 }
10545 service.setActiveDeviceToDeviceTransport(transport);
10546 } finally {
10547 Binder.restoreCallingIdentity(identity);
10548 }
10549 }
Tyler Gunn92479152021-01-20 16:30:10 -080010550
Tyler Gunnd4575212021-05-03 14:46:49 -070010551 @Override
10552 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10554 "setDeviceToDeviceForceEnabled");
10555
10556 final long identity = Binder.clearCallingIdentity();
10557 try {
10558 Arrays.stream(PhoneFactory.getPhones()).forEach(
10559 p -> {
10560 Phone thePhone = p.getImsPhone();
10561 if (thePhone != null && thePhone instanceof ImsPhone) {
10562 ImsPhone imsPhone = (ImsPhone) thePhone;
10563 CallTracker tracker = imsPhone.getCallTracker();
10564 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10565 ImsPhoneCallTracker imsPhoneCallTracker =
10566 (ImsPhoneCallTracker) tracker;
10567 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10568 }
10569 }
10570 }
10571 );
10572 } finally {
10573 Binder.restoreCallingIdentity(identity);
10574 }
10575 }
10576
Tyler Gunn92479152021-01-20 16:30:10 -080010577 /**
Hui Wang761a6682020-10-31 05:12:53 +000010578 * Gets the config of RCS VoLTE single registration enabled for the device.
10579 */
10580 @Override
10581 public boolean getDeviceSingleRegistrationEnabled() {
10582 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10583 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10584 }
10585
10586 /**
10587 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10588 */
10589 @Override
10590 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10591 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10592 "setCarrierSingleRegistrationEnabledOverride");
10593 enforceModifyPermission();
10594
10595 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10596 : Boolean.parseBoolean(enabledStr);
10597 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10598 subId, enabled);
10599 }
10600
10601 /**
10602 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10603 */
10604 @Override
10605 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10606 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10607 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10608 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010609
10610 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010611 * Overrides the ims feature validation result
10612 */
10613 @Override
10614 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10615 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10616 "setImsFeatureValidationOverride");
10617
10618 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10619 : Boolean.parseBoolean(enabledStr);
10620 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10621 subId, enabled);
10622 }
10623
10624 /**
10625 * Gets the ims feature validation override value
10626 */
10627 @Override
10628 public boolean getImsFeatureValidationOverride(int subId) {
10629 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10630 "getImsFeatureValidationOverride");
10631 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10632 }
10633
10634 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010635 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10636 * their mobile plan.
10637 */
10638 @Override
10639 public String getMobileProvisioningUrl() {
10640 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10641 final long identity = Binder.clearCallingIdentity();
10642 try {
10643 return getDefaultPhone().getMobileProvisioningUrl();
10644 } finally {
10645 Binder.restoreCallingIdentity(identity);
10646 }
10647 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010648
James.cf Linbcdf8b32021-01-14 16:44:13 +080010649 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010650 * Get the EAB contact from the EAB database.
10651 */
10652 @Override
10653 public String getContactFromEab(String contact) {
10654 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10655 enforceModifyPermission();
10656 final long identity = Binder.clearCallingIdentity();
10657 try {
10658 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10659 } finally {
10660 Binder.restoreCallingIdentity(identity);
10661 }
10662 }
10663
10664 /**
Calvin Pana1434322021-07-01 19:27:01 +080010665 * Get the EAB capability from the EAB database.
10666 */
10667 @Override
10668 public String getCapabilityFromEab(String contact) {
10669 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10670 enforceModifyPermission();
10671 final long identity = Binder.clearCallingIdentity();
10672 try {
10673 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10674 } finally {
10675 Binder.restoreCallingIdentity(identity);
10676 }
10677 }
10678
10679 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010680 * Remove the EAB contacts from the EAB database.
10681 */
10682 @Override
10683 public int removeContactFromEab(int subId, String contacts) {
10684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10685 enforceModifyPermission();
10686 final long identity = Binder.clearCallingIdentity();
10687 try {
10688 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10689 } finally {
10690 Binder.restoreCallingIdentity(identity);
10691 }
10692 }
10693
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010694 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010695 public boolean getDeviceUceEnabled() {
10696 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10697 final long identity = Binder.clearCallingIdentity();
10698 try {
10699 return mApp.getDeviceUceEnabled();
10700 } finally {
10701 Binder.restoreCallingIdentity(identity);
10702 }
10703 }
10704
10705 @Override
10706 public void setDeviceUceEnabled(boolean isEnabled) {
10707 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10708 final long identity = Binder.clearCallingIdentity();
10709 try {
10710 mApp.setDeviceUceEnabled(isEnabled);
10711 } finally {
10712 Binder.restoreCallingIdentity(identity);
10713 }
10714 }
10715
Brad Ebinger14d467f2021-02-12 06:18:28 +000010716 /**
10717 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10718 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10719 */
10720 // Used for SHELL command only right now.
10721 @Override
10722 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10723 List<String> featureTags) {
10724 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10725 "addUceRegistrationOverrideShell");
10726 final long identity = Binder.clearCallingIdentity();
10727 try {
10728 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10729 new ArraySet<>(featureTags));
10730 } catch (ImsException e) {
10731 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10732 } finally {
10733 Binder.restoreCallingIdentity(identity);
10734 }
10735 }
10736
10737 /**
10738 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10739 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10740 */
10741 // Used for SHELL command only right now.
10742 @Override
10743 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10744 List<String> featureTags) {
10745 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10746 "removeUceRegistrationOverrideShell");
10747 final long identity = Binder.clearCallingIdentity();
10748 try {
10749 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10750 new ArraySet<>(featureTags));
10751 } catch (ImsException e) {
10752 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10753 } finally {
10754 Binder.restoreCallingIdentity(identity);
10755 }
10756 }
10757
10758 /**
10759 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10760 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10761 */
10762 // Used for SHELL command only right now.
10763 @Override
10764 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10766 "clearUceRegistrationOverrideShell");
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10770 } catch (ImsException e) {
10771 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10772 } finally {
10773 Binder.restoreCallingIdentity(identity);
10774 }
10775 }
10776
10777 /**
10778 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10779 */
10780 // Used for SHELL command only right now.
10781 @Override
10782 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10783 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10784 "getLatestRcsContactUceCapabilityShell");
10785 final long identity = Binder.clearCallingIdentity();
10786 try {
10787 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10788 } catch (ImsException e) {
10789 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10790 } finally {
10791 Binder.restoreCallingIdentity(identity);
10792 }
10793 }
10794
10795 /**
10796 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10797 * device does not have an active PUBLISH.
10798 */
10799 // Used for SHELL command only right now.
10800 @Override
10801 public String getLastUcePidfXmlShell(int subId) {
10802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10803 final long identity = Binder.clearCallingIdentity();
10804 try {
10805 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10806 } catch (ImsException e) {
10807 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10808 } finally {
10809 Binder.restoreCallingIdentity(identity);
10810 }
10811 }
10812
James.cf Line8713a42021-04-29 16:04:26 +080010813 /**
10814 * Remove UCE requests cannot be sent to the network status.
10815 */
10816 // Used for SHELL command only right now.
10817 @Override
10818 public boolean removeUceRequestDisallowedStatus(int subId) {
10819 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10820 final long identity = Binder.clearCallingIdentity();
10821 try {
10822 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10823 } catch (ImsException e) {
10824 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10825 } finally {
10826 Binder.restoreCallingIdentity(identity);
10827 }
10828 }
10829
James.cf Lin0fc71b02021-05-25 01:37:38 +080010830 /**
10831 * Remove UCE requests cannot be sent to the network status.
10832 */
10833 // Used for SHELL command only.
10834 @Override
10835 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10836 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10837 final long identity = Binder.clearCallingIdentity();
10838 try {
10839 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10840 } catch (ImsException e) {
10841 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010846
James.cf Lin4b784aa2021-01-31 03:25:15 +080010847 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010848 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10849 String callingPackage) {
10850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10851 mApp, subId, "setSignalStrengthUpdateRequest");
10852
10853 final int callingUid = Binder.getCallingUid();
10854 // Verify that tha callingPackage belongs to the calling UID
10855 mApp.getSystemService(AppOpsManager.class)
10856 .checkPackage(callingUid, callingPackage);
10857
Rambo Wang3607f502021-02-01 21:51:40 -080010858 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010859
10860 final long identity = Binder.clearCallingIdentity();
10861 try {
10862 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10863 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10864
10865 if (result instanceof IllegalStateException) {
10866 throw (IllegalStateException) result;
10867 }
10868 } finally {
10869 Binder.restoreCallingIdentity(identity);
10870 }
10871 }
10872
10873 @Override
10874 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10875 String callingPackage) {
10876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10877 mApp, subId, "clearSignalStrengthUpdateRequest");
10878
10879 final int callingUid = Binder.getCallingUid();
10880 // Verify that tha callingPackage belongs to the calling UID
10881 mApp.getSystemService(AppOpsManager.class)
10882 .checkPackage(callingUid, callingPackage);
10883
10884 final long identity = Binder.clearCallingIdentity();
10885 try {
10886 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10887 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10888
10889 if (result instanceof IllegalStateException) {
10890 throw (IllegalStateException) result;
10891 }
10892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
10896
Rambo Wang3607f502021-02-01 21:51:40 -080010897 private static void validateSignalStrengthUpdateRequest(Context context,
10898 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010899 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10900 // phone/system process do not have further restriction on request
10901 return;
10902 }
10903
10904 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010905 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010906 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010907 context.enforceCallingOrSelfPermission(
10908 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10909 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010910 }
10911
10912 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10913 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10914 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10915 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10916 || info.isEnabled()) {
10917 throw new IllegalArgumentException(
10918 "Only system can set hide fields in SignalThresholdInfo");
10919 }
10920
10921 // Thresholds length for each RAN need in range. This has been validated in
10922 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10923 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10924 final int[] thresholds = info.getThresholds();
10925 Objects.requireNonNull(thresholds);
10926 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10927 || thresholds.length
10928 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10929 throw new IllegalArgumentException(
10930 "thresholds length is out of range: " + thresholds.length);
10931 }
10932 }
10933 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010934
10935 /**
10936 * Gets the current phone capability.
10937 *
10938 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10939 * @return the PhoneCapability which describes the data connection capability of modem.
10940 * It's used to evaluate possible phone config change, for example from single
10941 * SIM device to multi-SIM device.
10942 */
10943 @Override
10944 public PhoneCapability getPhoneCapability() {
10945 enforceReadPrivilegedPermission("getPhoneCapability");
10946 final long identity = Binder.clearCallingIdentity();
10947 try {
10948 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10949 } finally {
10950 Binder.restoreCallingIdentity(identity);
10951 }
10952 }
Michele Berionne5e411512020-11-13 02:36:59 +000010953
10954 /**
10955 * Prepare TelephonyManager for an unattended reboot. The reboot is
10956 * required to be done shortly after the API is invoked.
10957 */
10958 @Override
10959 @TelephonyManager.PrepareUnattendedRebootResult
10960 public int prepareForUnattendedReboot() {
10961 enforceRebootPermission();
10962
10963 final long identity = Binder.clearCallingIdentity();
10964 try {
10965 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10966 } finally {
10967 Binder.restoreCallingIdentity(identity);
10968 }
10969 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010970
10971 /**
10972 * Request to get the current slicing configuration including URSP rules and
10973 * NSSAIs (configured, allowed and rejected).
10974 *
10975 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10976 */
10977 @Override
10978 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000010979 TelephonyPermissions
10980 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
10981 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010982
10983 final long identity = Binder.clearCallingIdentity();
10984 try {
10985 Phone phone = getDefaultPhone();
10986 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10987 } finally {
10988 Binder.restoreCallingIdentity(identity);
10989 }
10990 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000010991
10992 /**
10993 * Register an IMS connection state callback
10994 */
10995 @Override
10996 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
10997 String callingPackage) {
10998 if (feature == ImsFeature.FEATURE_MMTEL) {
10999 // ImsMmTelManager
11000 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11001 TelephonyPermissions
11002 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11003 mApp, subId, "registerImsStateCallback");
11004 } else if (feature == ImsFeature.FEATURE_RCS) {
11005 // ImsRcsManager or SipDelegateManager
11006 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11007 Binder.getCallingUid(), "registerImsStateCallback",
11008 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11009 Manifest.permission.READ_PRECISE_PHONE_STATE,
11010 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11011 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11012 }
11013
11014 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11015 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11016 "IMS not available on device.");
11017 }
11018
11019 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11020 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11021 }
11022
11023 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11024 if (controller == null) {
11025 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11026 "IMS not available on device.");
11027 }
11028
11029 if (callingPackage == null) {
11030 callingPackage = getCurrentPackageName();
11031 }
11032
11033 final long token = Binder.clearCallingIdentity();
11034 try {
11035 int slotId = getSlotIndexOrException(subId);
11036 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11037 } catch (ImsException e) {
11038 throw new ServiceSpecificException(e.getCode());
11039 } finally {
11040 Binder.restoreCallingIdentity(token);
11041 }
11042 }
11043
11044 /**
11045 * Unregister an IMS connection state callback
11046 */
11047 @Override
11048 public void unregisterImsStateCallback(IImsStateCallback cb) {
11049 final long token = Binder.clearCallingIdentity();
11050 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11051 if (controller == null) {
11052 return;
11053 }
11054 try {
11055 controller.unregisterImsStateCallback(cb);
11056 } finally {
11057 Binder.restoreCallingIdentity(token);
11058 }
11059 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011060
11061 /**
11062 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11063 *
11064 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11065 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11066 * SecurityException.
11067 * If there is current registered network this value will be same as the registered cell
11068 * identity. If the device goes out of service the previous cell identity is cached and
11069 * will be returned. If the cache age of the Cell identity is more than 24 hours
11070 * it will be cleared and null will be returned.
11071 *
11072 */
11073 @Override
11074 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11075 String callingFeatureId) {
11076 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11077 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11078 LocationAccessPolicy.checkLocationPermission(mApp,
11079 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11080 .setCallingPackage(callingPackage)
11081 .setCallingFeatureId(callingFeatureId)
11082 .setCallingPid(Binder.getCallingPid())
11083 .setCallingUid(Binder.getCallingUid())
11084 .setMethod("getLastKnownCellIdentity")
11085 .setLogAsInfo(true)
11086 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11087 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11088 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11089 .build());
11090
11091 boolean hasFinePermission =
11092 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11093 if (!hasFinePermission
11094 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11095 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11096 + "and BIND_CONNECTION_SERVICE permission.");
11097 }
11098
11099 final long identity = Binder.clearCallingIdentity();
11100 try {
11101 Phone phone = getPhone(subId);
11102 if (phone == null) return null;
11103 ServiceStateTracker sst = phone.getServiceStateTracker();
11104 if (sst == null) return null;
11105 return sst.getLastKnownCellIdentity();
11106 } finally {
11107 Binder.restoreCallingIdentity(identity);
11108 }
11109 }
jimsun38340bf2021-10-26 15:01:23 +080011110
11111 /**
11112 * Sets the modem service class Name that Telephony will bind to.
11113 *
11114 * @param serviceName The class name of the modem service.
11115 * @return true if the operation is succeed, otherwise false.
11116 */
11117 public boolean setModemService(String serviceName) {
11118 Log.d(LOG_TAG, "setModemService - " + serviceName);
11119 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11121 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11122 "setModemService");
11123 return mPhoneConfigurationManager.setModemService(serviceName);
11124 }
11125
11126 /**
11127 * Return the class name of the currently bounded modem service.
11128 *
11129 * @return the class name of the modem service.
11130 */
11131 public String getModemService() {
11132 String result;
11133 Log.d(LOG_TAG, "getModemService");
11134 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11135 TelephonyPermissions
11136 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11137 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11138 "getModemService");
11139 result = mPhoneConfigurationManager.getModemService();
11140 Log.d(LOG_TAG, "result = " + result);
11141 return result;
11142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011143}