blob: cf365e785d847aee710bd88abfaa324b8349892d [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;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000034import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080035import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000036import android.compat.annotation.ChangeId;
37import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070038import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070039import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.content.Context;
41import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070042import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070043import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080044import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070075import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080076import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080077import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070078import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080079import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070080import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080081import android.telephony.CellIdentityCdma;
82import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070084import android.telephony.CellInfoGsm;
85import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070086import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080087import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070088import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070089import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070090import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080091import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070092import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070094import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080095import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080096import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800100import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800101import android.telephony.SignalStrengthUpdateRequest;
102import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800103import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800105import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800108import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800110import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000111import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000113import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700114import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700115import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800116import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800117import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800118import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700119import android.telephony.gba.GbaAuthRequest;
120import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700121import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000124import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700125import android.telephony.ims.RegistrationManager;
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 Gunnd4339262021-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 Choi3b742d62021-10-25 19:48:34 +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;
joonhunshin3e154242021-09-17 06:33:39 +0000190import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800191import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700192import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700193import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800194import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800196import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700197import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000200import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800201import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000202import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800203import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700204import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700205import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800206import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800207import com.android.phone.callcomposer.CallComposerPictureManager;
208import com.android.phone.callcomposer.CallComposerPictureTransfer;
209import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700210import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700211import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800212import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700213import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700214import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800215import com.android.services.telephony.TelecomAccountRegistry;
216import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800217import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800218
Hall Liu82694d52020-12-11 18:22:04 -0800219import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700220import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.io.IOException;
222import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800225import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000226import java.util.Collection;
sandeepjsb6c87872021-09-27 15:34:44 +0000227import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800228import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800229import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800230import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100231import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700233import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800235import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800237import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800238import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
240/**
241 * Implementation of the ITelephony interface.
242 */
Santos Cordon117fee72014-05-16 17:56:12 -0700243public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244 private static final String LOG_TAG = "PhoneInterfaceManager";
245 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
246 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800247 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
249 // Message codes used with mMainThreadHandler
250 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700251 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
252 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700253 private static final int CMD_OPEN_CHANNEL = 9;
254 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
255 private static final int CMD_CLOSE_CHANNEL = 11;
256 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800257 private static final int CMD_NV_READ_ITEM = 13;
258 private static final int EVENT_NV_READ_ITEM_DONE = 14;
259 private static final int CMD_NV_WRITE_ITEM = 15;
260 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
261 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
262 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700263 private static final int CMD_RESET_MODEM_CONFIG = 19;
264 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800265 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
266 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800267 private static final int CMD_SEND_ENVELOPE = 25;
268 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000269 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
270 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700271 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
272 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
273 private static final int CMD_EXCHANGE_SIM_IO = 31;
274 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800275 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
276 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700277 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
278 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700279 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
280 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700281 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
282 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
283 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
284 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700285 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
286 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
287 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
288 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700289 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800290 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
291 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000292 private static final int CMD_SWITCH_SLOTS = 50;
293 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700294 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
295 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
296 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
297 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
298 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
299 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
300 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
301 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700302 private static final int CMD_GET_ALL_CELL_INFO = 60;
303 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
304 private static final int CMD_GET_CELL_LOCATION = 62;
305 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700306 private static final int CMD_MODEM_REBOOT = 64;
307 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700308 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
309 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800310 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
311 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700312 private static final int CMD_GET_MODEM_STATUS = 70;
313 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700314 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
315 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700316 private static final int CMD_ERASE_MODEM_CONFIG = 74;
317 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800318 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
319 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
320 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
321 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800322 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
323 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800324 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800325 private static final int CMD_GET_CALL_FORWARDING = 83;
326 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
327 private static final int CMD_SET_CALL_FORWARDING = 85;
328 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
329 private static final int CMD_GET_CALL_WAITING = 87;
330 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
331 private static final int CMD_SET_CALL_WAITING = 89;
332 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700333 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
334 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
335 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
336 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700337 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
338 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800339 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
340 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800341 private static final int CMD_SET_DATA_THROTTLING = 99;
342 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800343 private static final int CMD_SET_SIM_POWER = 101;
344 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800345 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
346 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
347 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
348 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800349 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
350 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000351 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800352 private static final int CMD_GET_SLICING_CONFIG = 110;
353 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800354 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700355 private static final int CMD_ENABLE_VONR = 113;
356 private static final int EVENT_ENABLE_VONR_DONE = 114;
357 private static final int CMD_IS_VONR_ENABLED = 115;
358 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800360 // Parameters of select command.
361 private static final int SELECT_COMMAND = 0xA4;
362 private static final int SELECT_P1 = 0x04;
363 private static final int SELECT_P2 = 0;
364 private static final int SELECT_P3 = 0x10;
365
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 /** The singleton instance. */
367 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800368 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
Wink Saville3ab207e2014-11-20 13:07:20 -0800370 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800372 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700373 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700375 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800377 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700379 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800380 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Peter Wangdafb9ac2020-01-15 14:13:38 -0800382 /** User Activity */
383 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
385
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700386 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
387
Derek Tan97ebb422014-09-05 16:55:38 -0700388 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
389 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800390 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800391 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700392
Michelecea4cf22018-12-21 15:00:11 -0800393 // String to store multi SIM allowed
394 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
395
Derek Tan740e1672017-06-27 14:56:27 -0700396 // The AID of ISD-R.
397 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
398
yinxub1bed742017-04-17 11:45:04 -0700399 private NetworkScanRequestTracker mNetworkScanRequestTracker;
400
David Kelly5e06a7f2018-03-12 14:10:59 +0000401 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
402 private static final int MANUFACTURER_CODE_LENGTH = 8;
403
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800404 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800405 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406
Derek Tan89e89d42014-07-08 17:00:10 -0700407 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700408 * Experiment flag to enable erase modem config on reset network, default value is false
409 */
410 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
411 "reset_network_erase_modem_config_enabled";
412
Rambo Wang0f050d82021-02-12 11:43:36 -0800413 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjsb6c87872021-09-27 15:34:44 +0000414 /**
415 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
416 * one ICCID active at the same time.
417 * Apps should use below API signatures if targeting SDK is T and beyond.
418 *
419 * @hide
420 */
421 @ChangeId
422 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
423 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800424
Naina Nallurid63128d2019-09-17 14:10:30 -0700425 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 * A request object to use for transmitting data to an ICC.
427 */
428 private static final class IccAPDUArgument {
429 public int channel, cla, command, p1, p2, p3;
430 public String data;
431
432 public IccAPDUArgument(int channel, int cla, int command,
433 int p1, int p2, int p3, String data) {
434 this.channel = channel;
435 this.cla = cla;
436 this.command = command;
437 this.p1 = p1;
438 this.p2 = p2;
439 this.p3 = p3;
440 this.data = data;
441 }
442 }
443
444 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700445 * A request object to use for transmitting data to an ICC.
446 */
447 private static final class ManualNetworkSelectionArgument {
448 public OperatorInfo operatorInfo;
449 public boolean persistSelection;
450
451 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
452 this.operatorInfo = operatorInfo;
453 this.persistSelection = persistSelection;
454 }
455 }
456
457 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
459 * request after sending. The main thread will notify the request when it is complete.
460 */
461 private static final class MainThreadRequest {
462 /** The argument to use for the request */
463 public Object argument;
464 /** The result of the request that is run on the main thread */
465 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800466 // The subscriber id that this request applies to. Defaults to
467 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
468 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469
Nathan Harold92bed182018-10-12 18:16:49 -0700470 // In cases where subId is unavailable, the caller needs to specify the phone.
471 public Phone phone;
472
vagdeviaf9a5b92018-08-15 16:01:53 -0700473 public WorkSource workSource;
474
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 public MainThreadRequest(Object argument) {
476 this.argument = argument;
477 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800478
Nathan Harold92bed182018-10-12 18:16:49 -0700479 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
480 this.argument = argument;
481 if (phone != null) {
482 this.phone = phone;
483 }
484 this.workSource = workSource;
485 }
486
vagdeviaf9a5b92018-08-15 16:01:53 -0700487 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800488 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800489 if (subId != null) {
490 this.subId = subId;
491 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700492 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 }
495
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800496 private static final class IncomingThirdPartyCallArgs {
497 public final ComponentName component;
498 public final String callId;
499 public final String callerDisplayName;
500
501 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
502 String callerDisplayName) {
503 this.component = component;
504 this.callId = callId;
505 this.callerDisplayName = callerDisplayName;
506 }
507 }
508
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 /**
510 * A handler that processes messages on the main thread in the phone process. Since many
511 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
512 * inbound binder threads to the main thread in the phone process. The Binder thread
513 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
514 * on, which will be notified when the operation completes and will contain the result of the
515 * request.
516 *
517 * <p>If a MainThreadRequest object is provided in the msg.obj field,
518 * note that request.result must be set to something non-null for the calling thread to
519 * unblock.
520 */
521 private final class MainThreadHandler extends Handler {
522 @Override
523 public void handleMessage(Message msg) {
524 MainThreadRequest request;
525 Message onCompleted;
526 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000527 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800529 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
531 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 case CMD_HANDLE_USSD_REQUEST: {
533 request = (MainThreadRequest) msg.obj;
534 final Phone phone = getPhoneFromRequest(request);
535 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
536 String ussdRequest = ussdObject.first;
537 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700538
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 if (!isUssdApiAllowed(request.subId)) {
540 // Carrier does not support use of this API, return failure.
541 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
542 UssdResponse response = new UssdResponse(ussdRequest, null);
543 Bundle returnData = new Bundle();
544 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
545 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700546
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 request.result = true;
548 notifyRequester(request);
549 return;
550 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700551
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 try {
553 request.result = phone != null
554 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
555 } catch (CallStateException cse) {
556 request.result = false;
557 }
558 // Wake up the requesting thread
559 notifyRequester(request);
560 break;
pkanwar32d516d2016-10-14 19:37:38 -0700561 }
562
Yorke Lee716f67e2015-06-17 15:39:16 -0700563 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700565 final Phone phone = getPhoneFromRequest(request);
566 request.result = phone != null ?
567 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
568 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000577 uiccPort = getUiccPortFromRequest(request);
578 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 loge("iccTransmitApduLogicalChannel: No UICC");
580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
584 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000585 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 iccArgument.channel, iccArgument.cla, iccArgument.command,
587 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
595 if (ar.exception == null && ar.result != null) {
596 request.result = ar.result;
597 } else {
598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
599 if (ar.result == null) {
600 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800601 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800603 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 } else {
605 loge("iccTransmitApduLogicalChannel: Unknown exception");
606 }
607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
613 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000614 uiccPort = getUiccPortFromRequest(request);
615 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 loge("iccTransmitApduBasicChannel: No UICC");
617 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 } else {
620 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
621 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000622 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
624 iccArgument.p3, iccArgument.data, onCompleted);
625 }
626 break;
627
628 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result;
633 } else {
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
635 if (ar.result == null) {
636 loge("iccTransmitApduBasicChannel: Empty response");
637 } else if (ar.exception instanceof CommandException) {
638 loge("iccTransmitApduBasicChannel: CommandException: " +
639 ar.exception);
640 } else {
641 loge("iccTransmitApduBasicChannel: Unknown exception");
642 }
643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 break;
646
647 case CMD_EXCHANGE_SIM_IO:
648 request = (MainThreadRequest) msg.obj;
649 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000650 uiccPort = getUiccPortFromRequest(request);
651 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 loge("iccExchangeSimIO: No UICC");
653 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
657 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000658 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
660 iccArgument.data, onCompleted);
661 }
662 break;
663
664 case EVENT_EXCHANGE_SIM_IO_DONE:
665 ar = (AsyncResult) msg.obj;
666 request = (MainThreadRequest) ar.userObj;
667 if (ar.exception == null && ar.result != null) {
668 request.result = ar.result;
669 } else {
670 request.result = new IccIoResult(0x6f, 0, (byte[])null);
671 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 break;
674
Derek Tan4d5e5c12014-02-04 11:54:58 -0800675 case CMD_SEND_ENVELOPE:
676 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000677 uiccPort = getUiccPortFromRequest(request);
678 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 loge("sendEnvelopeWithStatus: No UICC");
680 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 } else {
683 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000684 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 break;
687
688 case EVENT_SEND_ENVELOPE_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700691 if (ar.exception == null && ar.result != null) {
692 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800693 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700694 request.result = new IccIoResult(0x6F, 0, (byte[])null);
695 if (ar.result == null) {
696 loge("sendEnvelopeWithStatus: Empty response");
697 } else if (ar.exception instanceof CommandException) {
698 loge("sendEnvelopeWithStatus: CommandException: " +
699 ar.exception);
700 } else {
701 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
702 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700704 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 break;
706
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 case CMD_OPEN_CHANNEL:
708 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000709 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800710 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000711 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700712 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800713 request.result = new IccOpenLogicalChannelResponse(-1,
714 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700716 } else {
717 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000718 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800719 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700720 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 break;
722
723 case EVENT_OPEN_CHANNEL_DONE:
724 ar = (AsyncResult) msg.obj;
725 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700728 int[] result = (int[]) ar.result;
729 int channelId = result[0];
730 byte[] selectResponse = null;
731 if (result.length > 1) {
732 selectResponse = new byte[result.length - 1];
733 for (int i = 1; i < result.length; ++i) {
734 selectResponse[i - 1] = (byte) result[i];
735 }
736 }
737 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700738 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.result == null) {
741 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 if (ar.exception != null) {
744 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
745 }
746
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700747 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700748 if (ar.exception instanceof CommandException) {
749 CommandException.Error error =
750 ((CommandException) (ar.exception)).getCommandError();
751 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700752 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700753 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700754 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700755 }
756 }
757 openChannelResp = new IccOpenLogicalChannelResponse(
758 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700760 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 break;
763
764 case CMD_CLOSE_CHANNEL:
765 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000766 uiccPort = getUiccPortFromRequest(request);
767 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900769 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 } else {
772 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000773 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700774 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 break;
776
777 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800778 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
779 break;
780
781 case CMD_NV_READ_ITEM:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
785 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800786 break;
787
788 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700789 ar = (AsyncResult) msg.obj;
790 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800791 if (ar.exception == null && ar.result != null) {
792 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700793 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800794 request.result = "";
795 if (ar.result == null) {
796 loge("nvReadItem: Empty response");
797 } else if (ar.exception instanceof CommandException) {
798 loge("nvReadItem: CommandException: " +
799 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800801 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 }
803 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700804 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 break;
806
Jake Hambye994d462014-02-03 13:10:13 -0800807 case CMD_NV_WRITE_ITEM:
808 request = (MainThreadRequest) msg.obj;
809 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
810 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800811 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700812 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800813 break;
814
815 case EVENT_NV_WRITE_ITEM_DONE:
816 handleNullReturnEvent(msg, "nvWriteItem");
817 break;
818
819 case CMD_NV_WRITE_CDMA_PRL:
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800822 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800823 break;
824
825 case EVENT_NV_WRITE_CDMA_PRL_DONE:
826 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
827 break;
828
chen xu6dac5ab2018-10-26 17:39:23 -0700829 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800830 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700831 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800832 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800833 break;
834
chen xu6dac5ab2018-10-26 17:39:23 -0700835 case EVENT_RESET_MODEM_CONFIG_DONE:
836 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800837 break;
838
Sooraj Sasindran37444802020-08-11 10:40:43 -0700839 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
842 request);
843 Phone phone = getPhoneFromRequest(request);
844 if (phone != null) {
845 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
846 } else {
847 loge("isNRDualConnectivityEnabled: No phone object");
848 request.result = false;
849 notifyRequester(request);
850 }
851 break;
852 }
853
854 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
860 // request.result must be set to something non-null
861 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700862 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700863 request.result = ar.result;
864 } else {
865 request.result = false;
866 }
867 if (ar.result == null) {
868 loge("isNRDualConnectivityEnabled: Empty response");
869 } else if (ar.exception instanceof CommandException) {
870 loge("isNRDualConnectivityEnabled: CommandException: "
871 + ar.exception);
872 } else {
873 loge("isNRDualConnectivityEnabled: Unknown exception");
874 }
875 }
876 notifyRequester(request);
877 break;
878
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700879 case CMD_IS_VONR_ENABLED: {
880 request = (MainThreadRequest) msg.obj;
881 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
882 request);
883 Phone phone = getPhoneFromRequest(request);
884 if (phone != null) {
885 phone.isVoNrEnabled(onCompleted, request.workSource);
886 } else {
887 loge("isVoNrEnabled: No phone object");
888 request.result = false;
889 notifyRequester(request);
890 }
891 break;
892 }
893
894 case EVENT_IS_VONR_ENABLED_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
899 } else {
900 // request.result must be set to something non-null
901 // for the calling thread to unblock
902 if (ar.result != null) {
903 request.result = ar.result;
904 } else {
905 request.result = false;
906 }
907 if (ar.result == null) {
908 loge("isVoNrEnabled: Empty response");
909 } else if (ar.exception instanceof CommandException) {
910 loge("isVoNrEnabled: CommandException: "
911 + ar.exception);
912 } else {
913 loge("isVoNrEnabled: Unknown exception");
914 }
915 }
916 notifyRequester(request);
917 break;
918
Sooraj Sasindran37444802020-08-11 10:40:43 -0700919 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
922 Phone phone = getPhoneFromRequest(request);
923 if (phone != null) {
924 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
925 request.workSource);
926 } else {
927 loge("enableNrDualConnectivity: No phone object");
928 request.result =
929 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
930 notifyRequester(request);
931 }
932 break;
933 }
934
935 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
938 if (ar.exception == null) {
939 request.result =
940 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
941 } else {
942 request.result =
943 TelephonyManager
944 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
945 if (ar.exception instanceof CommandException) {
946 CommandException.Error error =
947 ((CommandException) (ar.exception)).getCommandError();
948 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
949 request.result =
950 TelephonyManager
951 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000952 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
953 request.result =
954 TelephonyManager
955 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700956 }
957 loge("enableNrDualConnectivity" + ": CommandException: "
958 + ar.exception);
959 } else {
960 loge("enableNrDualConnectivity" + ": Unknown exception");
961 }
962 }
963 notifyRequester(request);
964 break;
965 }
966
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700967 case CMD_ENABLE_VONR: {
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
970 Phone phone = getPhoneFromRequest(request);
971 if (phone != null) {
972 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
973 request.workSource);
974 } else {
975 loge("setVoNrEnabled: No phone object");
976 request.result =
977 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
978 notifyRequester(request);
979 }
980 break;
981 }
982
983 case EVENT_ENABLE_VONR_DONE: {
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 if (ar.exception == null) {
987 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
988 } else {
989 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
990 if (ar.exception instanceof CommandException) {
991 CommandException.Error error =
992 ((CommandException) (ar.exception)).getCommandError();
993 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
994 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
995 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
996 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
997 } else {
998 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
999 }
1000 loge("setVoNrEnabled" + ": CommandException: "
1001 + ar.exception);
1002 } else {
1003 loge("setVoNrEnabled" + ": Unknown exception");
1004 }
1005 }
1006 notifyRequester(request);
1007 break;
1008 }
1009
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001011 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001012 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1013 request);
1014 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001015 break;
1016
SongFerngWang3ef3e072020-12-21 16:41:52 +08001017 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 if (ar.exception == null && ar.result != null) {
1021 request.result = ar.result; // Integer
1022 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301023 // request.result must be set to something non-null
1024 // for the calling thread to unblock
1025 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001026 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001027 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001028 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001029 loge("getAllowedNetworkTypesBitmask: CommandException: "
1030 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001032 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001033 }
1034 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001035 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001036 break;
1037
SongFerngWang3ef3e072020-12-21 16:41:52 +08001038 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001039 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001040 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1041 request);
1042 Pair<Integer, Long> reasonWithNetworkTypes =
1043 (Pair<Integer, Long>) request.argument;
1044 getPhoneFromRequest(request).setAllowedNetworkTypes(
1045 reasonWithNetworkTypes.first,
1046 reasonWithNetworkTypes.second,
1047 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001048 break;
1049
SongFerngWang3ef3e072020-12-21 16:41:52 +08001050 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1051 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001052 break;
1053
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001054 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1055 request = (MainThreadRequest)msg.obj;
1056 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001057 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001058 break;
1059
1060 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1061 ar = (AsyncResult)msg.obj;
1062 request = (MainThreadRequest)ar.userObj;
1063 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001064 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001065 break;
1066
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001067 case CMD_SET_VOICEMAIL_NUMBER:
1068 request = (MainThreadRequest) msg.obj;
1069 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1070 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001071 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1072 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001073 break;
1074
1075 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1076 handleNullReturnEvent(msg, "setVoicemailNumber");
1077 break;
1078
Stuart Scott54788802015-03-30 13:18:01 -07001079 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1082 request);
1083 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1084 break;
1085
1086 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1087 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1088 break;
1089
Shishir Agrawal302c8692015-06-19 13:49:39 -07001090 case CMD_PERFORM_NETWORK_SCAN:
1091 request = (MainThreadRequest) msg.obj;
1092 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1093 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1094 break;
1095
Hall Liu27d24262020-09-18 19:04:59 -07001096 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001097 request = (MainThreadRequest) msg.obj;
1098 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001099 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1100 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1101 request.argument;
1102 int callForwardingReason = args.first;
1103 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001104 break;
Hall Liu27d24262020-09-18 19:04:59 -07001105 }
1106 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001109 TelephonyManager.CallForwardingInfoCallback callback =
1110 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1111 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001112 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001113 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001114 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1115 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1116 // Service Class is a bit mask per 3gpp 27.007. Search for
1117 // any service for voice call.
1118 if ((callForwardInfo.serviceClass
1119 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001120 callForwardingInfo = new CallForwardingInfo(
1121 callForwardInfo.status
1122 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001123 callForwardInfo.reason,
1124 callForwardInfo.number,
1125 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001126 break;
1127 }
1128 }
1129 // Didn't find a call forward info for voice call.
1130 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001131 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1132 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
Hall Liu27d24262020-09-18 19:04:59 -07001134 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001135 } else {
1136 if (ar.result == null) {
1137 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1138 }
1139 if (ar.exception != null) {
1140 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1141 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001142 int errorCode = TelephonyManager
1143 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001144 if (ar.exception instanceof CommandException) {
1145 CommandException.Error error =
1146 ((CommandException) (ar.exception)).getCommandError();
1147 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001148 errorCode = TelephonyManager
1149 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001150 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001151 errorCode = TelephonyManager
1152 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001153 }
1154 }
Hall Liu27d24262020-09-18 19:04:59 -07001155 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001156 }
Shuo Qian4a594052020-01-23 11:59:30 -08001157 break;
Hall Liu27d24262020-09-18 19:04:59 -07001158 }
Shuo Qian4a594052020-01-23 11:59:30 -08001159
Hall Liu27d24262020-09-18 19:04:59 -07001160 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 request = (MainThreadRequest) msg.obj;
1162 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001163 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001164 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001165 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1166 request.argument).first;
1167 request.phone.setCallForwardingOption(
1168 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001169 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001170 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001171 callForwardingInfoToSet.getReason(),
1172 callForwardingInfoToSet.getNumber(),
1173 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1174 break;
Hall Liu27d24262020-09-18 19:04:59 -07001175 }
Shuo Qian4a594052020-01-23 11:59:30 -08001176
Hall Liu27d24262020-09-18 19:04:59 -07001177 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001178 ar = (AsyncResult) msg.obj;
1179 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001180 Consumer<Integer> callback =
1181 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1182 request.argument).second;
1183 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001184 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001185 int errorCode = TelephonyManager.CallForwardingInfoCallback
1186 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001187 if (ar.exception instanceof CommandException) {
1188 CommandException.Error error =
1189 ((CommandException) (ar.exception)).getCommandError();
1190 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001191 errorCode = TelephonyManager.CallForwardingInfoCallback
1192 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001193 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001194 errorCode = TelephonyManager.CallForwardingInfoCallback
1195 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001196 }
1197 }
1198 callback.accept(errorCode);
1199 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001200 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001201 }
Shuo Qian4a594052020-01-23 11:59:30 -08001202 break;
Hall Liu27d24262020-09-18 19:04:59 -07001203 }
Shuo Qian4a594052020-01-23 11:59:30 -08001204
Hall Liu27d24262020-09-18 19:04:59 -07001205 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1208 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1209 break;
Hall Liu27d24262020-09-18 19:04:59 -07001210 }
Shuo Qian4a594052020-01-23 11:59:30 -08001211
Hall Liu27d24262020-09-18 19:04:59 -07001212 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001213 ar = (AsyncResult) msg.obj;
1214 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001215 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001216 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1217 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001218 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 // Service Class is a bit mask per 3gpp 27.007.
1220 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001221 if (callForwardResults.length > 1
1222 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001223 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001224 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001225 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1226 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001228 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 }
1230 } else {
1231 if (ar.result == null) {
1232 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1233 }
1234 if (ar.exception != null) {
1235 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1236 }
1237 if (ar.exception instanceof CommandException) {
1238 CommandException.Error error =
1239 ((CommandException) (ar.exception)).getCommandError();
1240 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1241 callForwardingStatus =
1242 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1243 }
1244 }
1245 }
Hall Liu27d24262020-09-18 19:04:59 -07001246 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 break;
Hall Liu27d24262020-09-18 19:04:59 -07001248 }
Shuo Qian4a594052020-01-23 11:59:30 -08001249
Hall Liu27d24262020-09-18 19:04:59 -07001250 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001251 request = (MainThreadRequest) msg.obj;
1252 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001253 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1254 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 break;
Hall Liu27d24262020-09-18 19:04:59 -07001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257
Hall Liu27d24262020-09-18 19:04:59 -07001258 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 ar = (AsyncResult) msg.obj;
1260 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001261 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1262 Consumer<Integer> callback =
1263 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1264 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001265 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001266 if (ar.exception instanceof CommandException) {
1267 CommandException.Error error =
1268 ((CommandException) (ar.exception)).getCommandError();
1269 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1270 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1271 } else {
1272 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1273 }
1274 } else {
1275 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1276 }
1277 } else {
1278 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1279 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001280 }
Shuo Qian4a594052020-01-23 11:59:30 -08001281 break;
Hall Liu27d24262020-09-18 19:04:59 -07001282 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001283 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1284 ar = (AsyncResult) msg.obj;
1285 request = (MainThreadRequest) ar.userObj;
1286 CellNetworkScanResult cellScanResult;
1287 if (ar.exception == null && ar.result != null) {
1288 cellScanResult = new CellNetworkScanResult(
1289 CellNetworkScanResult.STATUS_SUCCESS,
1290 (List<OperatorInfo>) ar.result);
1291 } else {
1292 if (ar.result == null) {
1293 loge("getCellNetworkScanResults: Empty response");
1294 }
1295 if (ar.exception != null) {
1296 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1297 }
1298 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1299 if (ar.exception instanceof CommandException) {
1300 CommandException.Error error =
1301 ((CommandException) (ar.exception)).getCommandError();
1302 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1303 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1304 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1305 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1306 }
1307 }
1308 cellScanResult = new CellNetworkScanResult(errorCode, null);
1309 }
1310 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001311 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001312 break;
1313
1314 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1315 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001316 ManualNetworkSelectionArgument selArg =
1317 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001318 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1319 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001320 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1321 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001322 break;
1323
1324 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001325 ar = (AsyncResult) msg.obj;
1326 request = (MainThreadRequest) ar.userObj;
1327 if (ar.exception == null) {
1328 request.result = true;
1329 } else {
1330 request.result = false;
1331 loge("setNetworkSelectionModeManual " + ar.exception);
1332 }
1333 notifyRequester(request);
1334 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001335 break;
1336
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001337 case CMD_GET_MODEM_ACTIVITY_INFO:
1338 request = (MainThreadRequest) msg.obj;
1339 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001340 if (defaultPhone != null) {
1341 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001342 } else {
1343 ResultReceiver result = (ResultReceiver) request.argument;
1344 Bundle bundle = new Bundle();
1345 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001346 new ModemActivityInfo(0, 0, 0,
1347 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001348 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001349 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001350 break;
1351
Hall Liud0f208c2020-10-14 16:54:44 -07001352 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001353 ar = (AsyncResult) msg.obj;
1354 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001355 ResultReceiver result = (ResultReceiver) request.argument;
1356
Hall Liud0f208c2020-10-14 16:54:44 -07001357 ModemActivityInfo ret = null;
1358 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001359 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001360 // Update the last modem activity info and the result of the request.
1361 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1362 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001363 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001364 int[] txTimeMs = info.getTransmitTimeMillis();
1365 int[] lastModemTxTimeMs = mLastModemActivityInfo
1366 .getTransmitTimeMillis();
1367 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1368 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1369 }
Hall Liu49656c02020-10-09 19:00:11 -07001370 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001371 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1372 + mLastModemActivityInfo.getSleepTimeMillis());
1373 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1374 + mLastModemActivityInfo.getIdleTimeMillis());
1375 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1376 mLastModemActivityInfo.setReceiveTimeMillis(
1377 info.getReceiveTimeMillis()
1378 + mLastModemActivityInfo.getReceiveTimeMillis());
1379 }
Hall Liu49656c02020-10-09 19:00:11 -07001380 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001381 mLastModemActivityInfo.getSleepTimeMillis(),
1382 mLastModemActivityInfo.getIdleTimeMillis(),
1383 mLastModemActivityInfo.getTransmitTimeMillis(),
1384 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001385 } else {
1386 if (ar.result == null) {
1387 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001388 error = TelephonyManager.ModemActivityInfoException
1389 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390 } else if (ar.exception instanceof CommandException) {
1391 loge("queryModemActivityInfo: CommandException: " +
1392 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001393 error = TelephonyManager.ModemActivityInfoException
1394 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001395 } else {
1396 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001397 error = TelephonyManager.ModemActivityInfoException
1398 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001399 }
1400 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001401 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001402 if (ret != null) {
1403 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1404 } else {
1405 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1406 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001407 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001408 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001409 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001410 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001411
Meng Wang1a7c35a2016-05-05 20:56:15 -07001412 case CMD_SET_ALLOWED_CARRIERS:
1413 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001414 CarrierRestrictionRules argument =
1415 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001416 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001417 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001418 break;
1419
1420 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 if (ar.exception == null && ar.result != null) {
1424 request.result = ar.result;
1425 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001426 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1427 if (ar.exception instanceof CommandException) {
1428 loge("setAllowedCarriers: CommandException: " + ar.exception);
1429 CommandException.Error error =
1430 ((CommandException) (ar.exception)).getCommandError();
1431 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1432 request.result =
1433 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1434 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001435 } else {
1436 loge("setAllowedCarriers: Unknown exception");
1437 }
1438 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001439 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001440 break;
1441
1442 case CMD_GET_ALLOWED_CARRIERS:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001445 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001446 break;
1447
1448 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 if (ar.exception == null && ar.result != null) {
1452 request.result = ar.result;
1453 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001454 request.result = new IllegalStateException(
1455 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001456 if (ar.result == null) {
1457 loge("getAllowedCarriers: Empty response");
1458 } else if (ar.exception instanceof CommandException) {
1459 loge("getAllowedCarriers: CommandException: " +
1460 ar.exception);
1461 } else {
1462 loge("getAllowedCarriers: Unknown exception");
1463 }
1464 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001465 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001466 break;
1467
Nathan Haroldb3014052017-01-25 15:57:32 -08001468 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1469 ar = (AsyncResult) msg.obj;
1470 request = (MainThreadRequest) ar.userObj;
1471 if (ar.exception == null && ar.result != null) {
1472 request.result = ar.result;
1473 } else {
1474 request.result = new IllegalArgumentException(
1475 "Failed to retrieve Forbidden Plmns");
1476 if (ar.result == null) {
1477 loge("getForbiddenPlmns: Empty response");
1478 } else {
1479 loge("getForbiddenPlmns: Unknown exception");
1480 }
1481 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001482 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001483 break;
1484
1485 case CMD_GET_FORBIDDEN_PLMNS:
1486 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001487 uiccPort = getUiccPortFromRequest(request);
1488 if (uiccPort == null) {
1489 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001490 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001491 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001492 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001493 break;
1494 }
1495 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001496 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001497 if (uiccApp == null) {
1498 loge("getForbiddenPlmns() no app with specified type -- "
1499 + appType);
1500 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001502 break;
1503 } else {
1504 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1505 + " specified type -- " + appType);
1506 }
1507 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1508 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1509 onCompleted);
1510 break;
1511
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001512 case CMD_SWITCH_SLOTS:
1513 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001514 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001515 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001516 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001517 break;
1518
1519 case EVENT_SWITCH_SLOTS_DONE:
1520 ar = (AsyncResult) msg.obj;
1521 request = (MainThreadRequest) ar.userObj;
1522 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
1524 break;
1525 case CMD_GET_NETWORK_SELECTION_MODE:
1526 request = (MainThreadRequest) msg.obj;
1527 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1528 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1529 break;
1530
1531 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1532 ar = (AsyncResult) msg.obj;
1533 request = (MainThreadRequest) ar.userObj;
1534 if (ar.exception != null) {
1535 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1536 } else {
1537 int mode = ((int[]) ar.result)[0];
1538 if (mode == 0) {
1539 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1540 } else {
1541 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1542 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
1545 break;
1546 case CMD_GET_CDMA_ROAMING_MODE:
1547 request = (MainThreadRequest) msg.obj;
1548 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1549 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1550 break;
1551 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1552 ar = (AsyncResult) msg.obj;
1553 request = (MainThreadRequest) ar.userObj;
1554 if (ar.exception != null) {
1555 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1556 } else {
1557 request.result = ((int[]) ar.result)[0];
1558 }
1559 notifyRequester(request);
1560 break;
1561 case CMD_SET_CDMA_ROAMING_MODE:
1562 request = (MainThreadRequest) msg.obj;
1563 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1564 int mode = (int) request.argument;
1565 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1566 break;
1567 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1568 ar = (AsyncResult) msg.obj;
1569 request = (MainThreadRequest) ar.userObj;
1570 request.result = ar.exception == null;
1571 notifyRequester(request);
1572 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001573 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1574 request = (MainThreadRequest) msg.obj;
1575 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1576 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1577 break;
1578 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 if (ar.exception != null) {
1582 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1583 } else {
1584 request.result = ((int[]) ar.result)[0];
1585 }
1586 notifyRequester(request);
1587 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001588 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1591 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001592 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1593 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001594 break;
1595 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1596 ar = (AsyncResult) msg.obj;
1597 request = (MainThreadRequest) ar.userObj;
1598 request.result = ar.exception == null;
1599 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001600 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001601 case CMD_GET_ALL_CELL_INFO:
1602 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001603 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001604 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001605 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001606 case EVENT_GET_ALL_CELL_INFO_DONE:
1607 ar = (AsyncResult) msg.obj;
1608 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001609 // If a timeout occurs, the response will be null
1610 request.result = (ar.exception == null && ar.result != null)
1611 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001612 synchronized (request) {
1613 request.notifyAll();
1614 }
1615 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001616 case CMD_REQUEST_CELL_INFO_UPDATE:
1617 request = (MainThreadRequest) msg.obj;
1618 request.phone.requestCellInfoUpdate(request.workSource,
1619 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1620 break;
1621 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1622 ar = (AsyncResult) msg.obj;
1623 request = (MainThreadRequest) ar.userObj;
1624 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1625 try {
1626 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001627 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001628 cb.onError(
1629 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1630 ar.exception.getClass().getName(),
1631 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001632 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001633 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001634 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001635 } else {
1636 // use the result as returned
1637 cb.onCellInfo((List<CellInfo>) ar.result);
1638 }
1639 } catch (RemoteException re) {
1640 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1641 }
1642 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001643 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001644 request = (MainThreadRequest) msg.obj;
1645 WorkSource ws = (WorkSource) request.argument;
1646 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001647 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001648 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001649 }
1650 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 ar = (AsyncResult) msg.obj;
1652 request = (MainThreadRequest) ar.userObj;
1653 if (ar.exception == null) {
1654 request.result = ar.result;
1655 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001656 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001657 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001658 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001659 }
1660
1661 synchronized (request) {
1662 request.notifyAll();
1663 }
1664 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001665 }
chen xu6dac5ab2018-10-26 17:39:23 -07001666 case CMD_MODEM_REBOOT:
1667 request = (MainThreadRequest) msg.obj;
1668 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001669 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001670 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001671 case EVENT_CMD_MODEM_REBOOT_DONE:
1672 handleNullReturnEvent(msg, "rebootModem");
1673 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001674 case CMD_REQUEST_ENABLE_MODEM:
1675 request = (MainThreadRequest) msg.obj;
1676 boolean enable = (boolean) request.argument;
1677 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001678 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001679 PhoneConfigurationManager.getInstance()
1680 .enablePhone(request.phone, enable, onCompleted);
1681 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001682 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001686 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001687 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001688 if ((boolean) request.result) {
1689 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1690 updateModemStateMetrics();
1691 } else {
1692 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1693 + ar.exception);
1694 }
1695 notifyRequester(request);
1696 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001697 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001698 case CMD_GET_MODEM_STATUS:
1699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1701 PhoneConfigurationManager.getInstance()
1702 .getPhoneStatusFromModem(request.phone, onCompleted);
1703 break;
1704 case EVENT_GET_MODEM_STATUS_DONE:
1705 ar = (AsyncResult) msg.obj;
1706 request = (MainThreadRequest) ar.userObj;
1707 int id = request.phone.getPhoneId();
1708 if (ar.exception == null && ar.result != null) {
1709 request.result = ar.result;
1710 //update the cache as modem status has changed
1711 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1712 (boolean) request.result);
1713 } else {
1714 // Return true if modem status cannot be retrieved. For most cases,
1715 // modem status is on. And for older version modems, GET_MODEM_STATUS
1716 // and disable modem are not supported. Modem is always on.
1717 // TODO: this should be fixed in R to support a third
1718 // status UNKNOWN b/131631629
1719 request.result = true;
1720 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1721 + ar.exception);
1722 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001723 notifyRequester(request);
1724 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001725 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1728 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1729 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1730 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1731 break;
1732 }
1733 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1737 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1738 args.second.accept(ar.exception == null);
1739 notifyRequester(request);
1740 break;
1741 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001742 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1743 request = (MainThreadRequest) msg.obj;
1744 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1745 Phone phone = getPhoneFromRequest(request);
1746 if (phone != null) {
1747 phone.getSystemSelectionChannels(onCompleted);
1748 } else {
1749 loge("getSystemSelectionChannels: No phone object");
1750 request.result = new ArrayList<RadioAccessSpecifier>();
1751 notifyRequester(request);
1752 }
1753 break;
1754 }
1755 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1756 ar = (AsyncResult) msg.obj;
1757 request = (MainThreadRequest) ar.userObj;
1758 if (ar.exception == null && ar.result != null) {
1759 request.result = ar.result;
1760 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001761 request.result = new IllegalStateException(
1762 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001763 if (ar.result == null) {
1764 loge("getSystemSelectionChannels: Empty response");
1765 } else {
1766 loge("getSystemSelectionChannels: Unknown exception");
1767 }
1768 }
1769 notifyRequester(request);
1770 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001771 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1772 ar = (AsyncResult) msg.obj;
1773 request = (MainThreadRequest) ar.userObj;
1774 if (ar.exception == null && ar.result != null) {
1775 request.result = ar.result;
1776 } else {
1777 request.result = -1;
1778 loge("Failed to set Forbidden Plmns");
1779 if (ar.result == null) {
1780 loge("setForbidenPlmns: Empty response");
1781 } else if (ar.exception != null) {
1782 loge("setForbiddenPlmns: Exception: " + ar.exception);
1783 request.result = -1;
1784 } else {
1785 loge("setForbiddenPlmns: Unknown exception");
1786 }
1787 }
1788 notifyRequester(request);
1789 break;
1790 case CMD_SET_FORBIDDEN_PLMNS:
1791 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001792 uiccPort = getUiccPortFromRequest(request);
1793 if (uiccPort == null) {
1794 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001795 request.result = -1;
1796 notifyRequester(request);
1797 break;
1798 }
1799 Pair<Integer, List<String>> setFplmnsArgs =
1800 (Pair<Integer, List<String>>) request.argument;
1801 appType = setFplmnsArgs.first;
1802 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001803 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001804 if (uiccApp == null) {
1805 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1806 request.result = -1;
1807 loge("Failed to get UICC App");
1808 notifyRequester(request);
1809 } else {
1810 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1811 ((SIMRecords) uiccApp.getIccRecords())
1812 .setForbiddenPlmns(onCompleted, fplmns);
1813 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001814 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001815 case CMD_ERASE_MODEM_CONFIG:
1816 request = (MainThreadRequest) msg.obj;
1817 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1818 defaultPhone.eraseModemConfig(onCompleted);
1819 break;
1820 case EVENT_ERASE_MODEM_CONFIG_DONE:
1821 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001822 break;
zoey chene02881a2019-12-30 16:11:23 +08001823
Kai Shif70f46f2021-03-03 13:59:46 -08001824 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1825 request = (MainThreadRequest) msg.obj;
1826 request.result = defaultPhone.eraseDataInSharedPreferences();
1827 notifyRequester(request);
1828 break;
1829
zoey chene02881a2019-12-30 16:11:23 +08001830 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1831 request = (MainThreadRequest) msg.obj;
1832 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1833 Pair<String, String> changed = (Pair<String, String>) request.argument;
1834 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1835 changed.first, changed.second, onCompleted);
1836 break;
1837 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 if (ar.exception == null) {
1841 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001842 // If the operation is successful, update the PIN storage
1843 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1844 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001845 UiccController.getInstance().getPinStorage()
1846 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001847 } else {
1848 request.result = msg.arg1;
1849 }
1850 notifyRequester(request);
1851 break;
1852
Michele Berionne5e411512020-11-13 02:36:59 +00001853 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001854 request = (MainThreadRequest) msg.obj;
1855 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1856 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1857 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1858 enabled.first, enabled.second, onCompleted);
1859 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001860 }
zoey chene02881a2019-12-30 16:11:23 +08001861 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1862 ar = (AsyncResult) msg.obj;
1863 request = (MainThreadRequest) ar.userObj;
1864 if (ar.exception == null) {
1865 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001866 // If the operation is successful, update the PIN storage
1867 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1868 int phoneId = getPhoneFromRequest(request).getPhoneId();
1869 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001870 UiccController.getInstance().getPinStorage()
1871 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001872 } else {
1873 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1874 }
zoey chene02881a2019-12-30 16:11:23 +08001875 } else {
1876 request.result = msg.arg1;
1877 }
Michele Berionne5e411512020-11-13 02:36:59 +00001878
1879
zoey chene02881a2019-12-30 16:11:23 +08001880 notifyRequester(request);
1881 break;
1882
Peter Wangdafb9ac2020-01-15 14:13:38 -08001883 case MSG_NOTIFY_USER_ACTIVITY:
1884 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001885 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001886 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1887 getDefaultPhone().getContext().sendBroadcastAsUser(
1888 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1889 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001890
1891 case CMD_SET_DATA_THROTTLING: {
1892 request = (MainThreadRequest) msg.obj;
1893 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1894 DataThrottlingRequest dataThrottlingRequest =
1895 (DataThrottlingRequest) request.argument;
1896 Phone phone = getPhoneFromRequest(request);
1897 if (phone != null) {
1898 phone.setDataThrottling(onCompleted,
1899 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1900 dataThrottlingRequest.getCompletionDurationMillis());
1901 } else {
1902 loge("setDataThrottling: No phone object");
1903 request.result =
1904 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1905 notifyRequester(request);
1906 }
1907
1908 break;
1909 }
1910 case EVENT_SET_DATA_THROTTLING_DONE:
1911 ar = (AsyncResult) msg.obj;
1912 request = (MainThreadRequest) ar.userObj;
1913
1914 if (ar.exception == null) {
1915 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1916 } else if (ar.exception instanceof CommandException) {
1917 loge("setDataThrottling: CommandException: " + ar.exception);
1918 CommandException.Error error =
1919 ((CommandException) (ar.exception)).getCommandError();
1920
1921 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1922 request.result = TelephonyManager
1923 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1924 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1925 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001926 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1927 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001928 } else {
1929 request.result =
1930 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1931 }
1932 } else {
1933 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1934 }
1935 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1936 notifyRequester(request);
1937 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001938
1939 case CMD_SET_SIM_POWER: {
1940 request = (MainThreadRequest) msg.obj;
1941 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1942 request = (MainThreadRequest) msg.obj;
1943 int stateToSet =
1944 ((Pair<Integer, IIntegerConsumer>)
1945 request.argument).first;
1946 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1947 break;
1948 }
1949 case EVENT_SET_SIM_POWER_DONE: {
1950 ar = (AsyncResult) msg.obj;
1951 request = (MainThreadRequest) ar.userObj;
1952 IIntegerConsumer callback =
1953 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1954 if (ar.exception != null) {
1955 loge("setSimPower exception: " + ar.exception);
1956 int errorCode = TelephonyManager.CallForwardingInfoCallback
1957 .RESULT_ERROR_UNKNOWN;
1958 if (ar.exception instanceof CommandException) {
1959 CommandException.Error error =
1960 ((CommandException) (ar.exception)).getCommandError();
1961 if (error == CommandException.Error.SIM_ERR) {
1962 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1963 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1964 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1965 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1966 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1967 } else {
1968 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1969 }
1970 }
1971 try {
1972 callback.accept(errorCode);
1973 } catch (RemoteException e) {
1974 // Ignore if the remote process is no longer available to call back.
1975 Log.w(LOG_TAG, "setSimPower: callback not available.");
1976 }
1977 } else {
1978 try {
1979 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1980 } catch (RemoteException e) {
1981 // Ignore if the remote process is no longer available to call back.
1982 Log.w(LOG_TAG, "setSimPower: callback not available.");
1983 }
1984 }
1985 break;
1986 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001987 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1988 request = (MainThreadRequest) msg.obj;
1989
1990 final Phone phone = getPhoneFromRequest(request);
1991 if (phone == null || phone.getServiceStateTracker() == null) {
1992 request.result = new IllegalStateException("Phone or SST is null");
1993 notifyRequester(request);
1994 break;
1995 }
1996
1997 Pair<Integer, SignalStrengthUpdateRequest> pair =
1998 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1999 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2000 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002001 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002002 request.subId, pair.first /*callingUid*/,
2003 pair.second /*request*/, onCompleted);
2004 break;
2005 }
2006 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2007 ar = (AsyncResult) msg.obj;
2008 request = (MainThreadRequest) ar.userObj;
2009 // request.result will be the exception of ar if present, true otherwise.
2010 // Be cautious not to leave result null which will wait() forever
2011 request.result = ar.exception != null ? ar.exception : true;
2012 notifyRequester(request);
2013 break;
2014 }
2015 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2016 request = (MainThreadRequest) msg.obj;
2017
2018 Phone phone = getPhoneFromRequest(request);
2019 if (phone == null || phone.getServiceStateTracker() == null) {
2020 request.result = new IllegalStateException("Phone or SST is null");
2021 notifyRequester(request);
2022 break;
2023 }
2024
2025 Pair<Integer, SignalStrengthUpdateRequest> pair =
2026 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2027 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2028 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002029 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002030 request.subId, pair.first /*callingUid*/,
2031 pair.second /*request*/, onCompleted);
2032 break;
2033 }
2034 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2035 ar = (AsyncResult) msg.obj;
2036 request = (MainThreadRequest) ar.userObj;
2037 request.result = ar.exception != null ? ar.exception : true;
2038 notifyRequester(request);
2039 break;
2040 }
Jordan Liu109698e2020-11-24 14:50:34 -08002041
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002042 case CMD_GET_SLICING_CONFIG: {
2043 request = (MainThreadRequest) msg.obj;
2044 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2045 request.phone.getSlicingConfig(onCompleted);
2046 break;
2047 }
2048 case EVENT_GET_SLICING_CONFIG_DONE: {
2049 ar = (AsyncResult) msg.obj;
2050 request = (MainThreadRequest) ar.userObj;
2051 ResultReceiver result = (ResultReceiver) request.argument;
2052
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002053 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002054 Bundle bundle = new Bundle();
2055 int resultCode = 0;
2056 if (ar.exception != null) {
2057 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2058 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002059 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002060 } else if (ar.result == null) {
2061 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002062 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002063 } else {
2064 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002065 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2066 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002067 }
2068
2069 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002070 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002071 }
2072 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2073 result.send(resultCode, bundle);
2074 notifyRequester(request);
2075 break;
2076 }
2077
Michele Berionne5e411512020-11-13 02:36:59 +00002078 case CMD_PREPARE_UNATTENDED_REBOOT:
2079 request = (MainThreadRequest) msg.obj;
2080 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002081 UiccController.getInstance().getPinStorage()
2082 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002083 notifyRequester(request);
2084 break;
2085
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 default:
2087 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2088 break;
2089 }
2090 }
Jake Hambye994d462014-02-03 13:10:13 -08002091
Pengquan Menga1bb6272018-09-06 09:59:22 -07002092 private void notifyRequester(MainThreadRequest request) {
2093 synchronized (request) {
2094 request.notifyAll();
2095 }
2096 }
2097
Jake Hambye994d462014-02-03 13:10:13 -08002098 private void handleNullReturnEvent(Message msg, String command) {
2099 AsyncResult ar = (AsyncResult) msg.obj;
2100 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2101 if (ar.exception == null) {
2102 request.result = true;
2103 } else {
2104 request.result = false;
2105 if (ar.exception instanceof CommandException) {
2106 loge(command + ": CommandException: " + ar.exception);
2107 } else {
2108 loge(command + ": Unknown exception");
2109 }
2110 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002111 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114
2115 /**
2116 * Posts the specified command to be executed on the main thread,
2117 * waits for the request to complete, and returns the result.
2118 * @see #sendRequestAsync
2119 */
2120 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002121 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2122 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002123 }
2124
2125 /**
2126 * Posts the specified command to be executed on the main thread,
2127 * waits for the request to complete, and returns the result.
2128 * @see #sendRequestAsync
2129 */
2130 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2131 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002132 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002133 }
2134
2135 /**
2136 * Posts the specified command to be executed on the main thread,
2137 * waits for the request to complete, and returns the result.
2138 * @see #sendRequestAsync
2139 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002140 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002141 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2142 }
2143
2144 /**
2145 * Posts the specified command to be executed on the main thread,
2146 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2147 * if not timeout or null otherwise.
2148 * @see #sendRequestAsync
2149 */
2150 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2151 long timeoutInMs) {
2152 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002153 }
2154
2155 /**
2156 * Posts the specified command to be executed on the main thread,
2157 * waits for the request to complete, and returns the result.
2158 * @see #sendRequestAsync
2159 */
Nathan Harold92bed182018-10-12 18:16:49 -07002160 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002161 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002162 }
2163
2164 /**
2165 * Posts the specified command to be executed on the main thread,
2166 * waits for the request to complete, and returns the result.
2167 * @see #sendRequestAsync
2168 */
2169 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002170 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2171 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002172 }
2173
2174 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002175 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2176 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2177 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002178 * @see #sendRequestAsync
2179 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002180 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2181 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2183 throw new RuntimeException("This method will deadlock if called from the main thread.");
2184 }
2185
Nathan Harold92bed182018-10-12 18:16:49 -07002186 MainThreadRequest request = null;
2187 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2188 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2189 } else if (phone != null) {
2190 request = new MainThreadRequest(argument, phone, workSource);
2191 } else {
2192 request = new MainThreadRequest(argument, subId, workSource);
2193 }
2194
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 Message msg = mMainThreadHandler.obtainMessage(command, request);
2196 msg.sendToTarget();
2197
Rambo Wang0f050d82021-02-12 11:43:36 -08002198
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002200 if (timeoutInMs >= 0) {
2201 // Wait for at least timeoutInMs before returning null request result
2202 long now = SystemClock.elapsedRealtime();
2203 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002204 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002205 try {
2206 request.wait(deadline - now);
2207 } catch (InterruptedException e) {
2208 // Do nothing, go back and check if request is completed or timeout
2209 } finally {
2210 now = SystemClock.elapsedRealtime();
2211 }
2212 }
2213 } else {
2214 // Wait for the request to complete
2215 while (request.result == null) {
2216 try {
2217 request.wait();
2218 } catch (InterruptedException e) {
2219 // Do nothing, go back and wait until the request is complete
2220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 }
2222 }
2223 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002224 if (request.result == null) {
2225 Log.wtf(LOG_TAG,
2226 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 return request.result;
2229 }
2230
2231 /**
2232 * Asynchronous ("fire and forget") version of sendRequest():
2233 * Posts the specified command to be executed on the main thread, and
2234 * returns immediately.
2235 * @see #sendRequest
2236 */
2237 private void sendRequestAsync(int command) {
2238 mMainThreadHandler.sendEmptyMessage(command);
2239 }
2240
2241 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002242 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002244 */
2245 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002246 sendRequestAsync(command, argument, null, null);
2247 }
2248
2249 /**
2250 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2251 * @see {@link #sendRequest(int,Object)}
2252 */
2253 private void sendRequestAsync(
2254 int command, Object argument, Phone phone, WorkSource workSource) {
2255 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002256 Message msg = mMainThreadHandler.obtainMessage(command, request);
2257 msg.sendToTarget();
2258 }
2259
2260 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 * Initialize the singleton PhoneInterfaceManager instance.
2262 * This is only done once, at startup, from PhoneApp.onCreate().
2263 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002264 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 synchronized (PhoneInterfaceManager.class) {
2266 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002267 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 } else {
2269 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2270 }
2271 return sInstance;
2272 }
2273 }
2274
2275 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002276 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002279 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002280 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002282 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002284 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002285 mTelephonySharedPreferences =
2286 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002287 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002288 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002289 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002290 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 publish();
2293 }
2294
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002295 private Phone getDefaultPhone() {
2296 Phone thePhone = getPhone(getDefaultSubscription());
2297 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2298 }
2299
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 private void publish() {
2301 if (DBG) log("publish: " + this);
2302
Peter Wangc035ce42020-01-08 21:00:22 -08002303 TelephonyFrameworkInitializer
2304 .getTelephonyServiceManager()
2305 .getTelephonyServiceRegisterer()
2306 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 }
2308
Stuart Scott584921c2015-01-15 17:10:34 -08002309 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002310 if (request.phone != null) {
2311 return request.phone;
2312 } else {
2313 return getPhoneFromSubId(request.subId);
2314 }
2315 }
2316
2317 private Phone getPhoneFromSubId(int subId) {
2318 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2319 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002320 }
2321
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002322 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002323 Phone phone = getPhoneFromRequest(request);
2324 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002325 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002326 }
2327
Wink Saville36469e72014-06-11 15:17:00 -07002328 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002329 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002330 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332
Kai Shif70f46f2021-03-03 13:59:46 -08002333 private void sendEraseModemConfig(@NonNull Phone phone) {
2334 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2335 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2336 }
2337
2338 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2339 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2340 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002341 }
2342
Peter Wang44b186e2020-01-13 23:33:09 -08002343 private boolean isImsAvailableOnDevice() {
2344 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2345 if (pm == null) {
2346 // For some reason package manger is not available.. This will fail internally anyway,
2347 // so do not throw error and allow.
2348 return true;
2349 }
2350 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2351 }
2352
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002354 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002355 }
2356
Wink Savilleb564aae2014-10-23 10:18:09 -07002357 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 if (DBG) log("dial: " + number);
2359 // No permission check needed here: This is just a wrapper around the
2360 // ACTION_DIAL intent, which is available to any app since it puts up
2361 // the UI before it does anything.
2362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002363 final long identity = Binder.clearCallingIdentity();
2364 try {
2365 String url = createTelUrl(number);
2366 if (url == null) {
2367 return;
2368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370 // PENDING: should we just silently fail if phone is offhook or ringing?
2371 PhoneConstants.State state = mCM.getState(subId);
2372 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2373 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2374 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2375 mApp.startActivity(intent);
2376 }
2377 } finally {
2378 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 }
2380 }
2381
2382 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002383 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002384 }
2385
Wink Savilleb564aae2014-10-23 10:18:09 -07002386 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 if (DBG) log("call: " + number);
2388
2389 // This is just a wrapper around the ACTION_CALL intent, but we still
2390 // need to do a permission check since we're calling startActivity()
2391 // from the context of the phone app.
2392 enforceCallPermission();
2393
Jordan Liu1617b712019-07-10 15:06:26 -07002394 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 != AppOpsManager.MODE_ALLOWED) {
2396 return;
2397 }
2398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 String url = createTelUrl(number);
2402 if (url == null) {
2403 return;
2404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002406 boolean isValid = false;
2407 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2408 if (slist != null) {
2409 for (SubscriptionInfo subInfoRecord : slist) {
2410 if (subInfoRecord.getSubscriptionId() == subId) {
2411 isValid = true;
2412 break;
2413 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002414 }
Wink Saville08874612014-08-31 19:19:58 -07002415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 if (!isValid) {
2417 return;
2418 }
Wink Saville08874612014-08-31 19:19:58 -07002419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2421 intent.putExtra(SUBSCRIPTION_KEY, subId);
2422 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2423 mApp.startActivity(intent);
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 }
2428
Wink Savilleb564aae2014-10-23 10:18:09 -07002429 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002430 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002431 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2432 }
2433
Wink Savilleb564aae2014-10-23 10:18:09 -07002434 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002435 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002436 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2437 }
2438
Wink Savilleb564aae2014-10-23 10:18:09 -07002439 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002441
2442 final long identity = Binder.clearCallingIdentity();
2443 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002444 Phone phone = getPhone(subId);
2445 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446 checkSimPin.start();
2447 return checkSimPin.unlockSim(null, pin);
2448 } finally {
2449 Binder.restoreCallingIdentity(identity);
2450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 }
2452
Wink Savilleb564aae2014-10-23 10:18:09 -07002453 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002455
2456 final long identity = Binder.clearCallingIdentity();
2457 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002458 Phone phone = getPhone(subId);
2459 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460 checkSimPuk.start();
2461 return checkSimPuk.unlockSim(puk, pin);
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
2464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 }
2466
2467 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002468 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 * a synchronous one.
2470 */
2471 private static class UnlockSim extends Thread {
2472
2473 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002474 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475
2476 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002477 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2478 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479
2480 // For replies from SimCard interface
2481 private Handler mHandler;
2482
2483 // For async handler to identify request type
2484 private static final int SUPPLY_PIN_COMPLETE = 100;
2485
Michele Berionne5e411512020-11-13 02:36:59 +00002486 UnlockSim(int phoneId, IccCard simCard) {
2487 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 mSimCard = simCard;
2489 }
2490
2491 @Override
2492 public void run() {
2493 Looper.prepare();
2494 synchronized (UnlockSim.this) {
2495 mHandler = new Handler() {
2496 @Override
2497 public void handleMessage(Message msg) {
2498 AsyncResult ar = (AsyncResult) msg.obj;
2499 switch (msg.what) {
2500 case SUPPLY_PIN_COMPLETE:
2501 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2502 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002503 mRetryCount = msg.arg1;
2504 if (ar.exception != null) {
2505 if (ar.exception instanceof CommandException &&
2506 ((CommandException)(ar.exception)).getCommandError()
2507 == CommandException.Error.PASSWORD_INCORRECT) {
2508 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002509 } //When UiccCardApp dispose,handle message and return exception
2510 else if (ar.exception instanceof CommandException &&
2511 ((CommandException) (ar.exception)).getCommandError()
2512 == CommandException.Error.ABORTED) {
2513 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002514 } else {
2515 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2516 }
2517 } else {
2518 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 mDone = true;
2521 UnlockSim.this.notifyAll();
2522 }
2523 break;
2524 }
2525 }
2526 };
2527 UnlockSim.this.notifyAll();
2528 }
2529 Looper.loop();
2530 }
2531
2532 /*
2533 * Use PIN or PUK to unlock SIM card
2534 *
2535 * If PUK is null, unlock SIM card with PIN
2536 *
2537 * If PUK is not null, unlock SIM card with PUK and set PIN code
2538 */
Wink Saville9de0f752013-10-22 19:04:03 -07002539 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540
2541 while (mHandler == null) {
2542 try {
2543 wait();
2544 } catch (InterruptedException e) {
2545 Thread.currentThread().interrupt();
2546 }
2547 }
2548 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2549
2550 if (puk == null) {
2551 mSimCard.supplyPin(pin, callback);
2552 } else {
2553 mSimCard.supplyPuk(puk, pin, callback);
2554 }
2555
2556 while (!mDone) {
2557 try {
2558 Log.d(LOG_TAG, "wait for done");
2559 wait();
2560 } catch (InterruptedException e) {
2561 // Restore the interrupted status
2562 Thread.currentThread().interrupt();
2563 }
2564 }
2565 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002566 int[] resultArray = new int[2];
2567 resultArray[0] = mResult;
2568 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002569
2570 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002571 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002572 }
2573
Wink Saville9de0f752013-10-22 19:04:03 -07002574 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 }
2576 }
2577
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002578 /**
2579 * This method has been removed due to privacy and stability concerns.
2580 */
2581 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002583 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2584 return;
Wink Saville36469e72014-06-11 15:17:00 -07002585 }
2586
Nathan Harold1f889d82020-06-04 17:05:26 -07002587 @Override
2588 public void updateServiceLocationWithPackageName(String callingPackage) {
2589 mApp.getSystemService(AppOpsManager.class)
2590 .checkPackage(Binder.getCallingUid(), callingPackage);
2591
Nathan Haroldf096d982020-11-18 17:18:06 -08002592 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002593 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2594 // Callers targeting S have no business invoking this method.
2595 return;
2596 }
2597
2598 LocationAccessPolicy.LocationPermissionResult locationResult =
2599 LocationAccessPolicy.checkLocationPermission(mApp,
2600 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2601 .setCallingPackage(callingPackage)
2602 .setCallingFeatureId(null)
2603 .setCallingPid(Binder.getCallingPid())
2604 .setCallingUid(Binder.getCallingUid())
2605 .setMethod("updateServiceLocation")
2606 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2607 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2608 .build());
2609 // Apps that lack location permission have no business calling this method;
2610 // however, because no permission was declared in the public API, denials must
2611 // all be "soft".
2612 switch (locationResult) {
2613 case DENIED_HARD: /* fall through */
2614 case DENIED_SOFT:
2615 return;
2616 }
2617
2618 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002621 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002623 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 }
2629
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002630 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002631 @Override
2632 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002633 return isRadioOnWithFeature(callingPackage, null);
2634 }
2635
2636
2637 @Override
2638 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2639 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2640 callingFeatureId);
2641 }
2642
2643 @Deprecated
2644 @Override
2645 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2646 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002647 }
2648
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002649 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002650 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2651 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002653 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002654 return false;
2655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656
2657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 return isRadioOnForSubscriber(subId);
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002663 }
2664
2665 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 final Phone phone = getPhone(subId);
2669 if (phone != null) {
2670 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2671 } else {
2672 return false;
2673 }
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 }
2678
2679 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002680 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 }
Wink Saville36469e72014-06-11 15:17:00 -07002682
Wink Savilleb564aae2014-10-23 10:18:09 -07002683 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
2686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 final Phone phone = getPhone(subId);
2689 if (phone != null) {
2690 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2691 }
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 }
Wink Saville36469e72014-06-11 15:17:00 -07002695 }
2696
2697 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002698 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002699 }
2700
Wink Savilleb564aae2014-10-23 10:18:09 -07002701 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703
2704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 final Phone phone = getPhone(subId);
2707 if (phone == null) {
2708 return false;
2709 }
2710 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2711 toggleRadioOnOffForSubscriber(subId);
2712 }
2713 return true;
2714 } finally {
2715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 }
Wink Saville36469e72014-06-11 15:17:00 -07002718
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002719 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002720 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002721 /*
2722 * If any of the Radios are available, it will need to be
2723 * shutdown. So return true if any Radio is available.
2724 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2728 Phone phone = PhoneFactory.getPhone(i);
2729 if (phone != null && phone.isRadioAvailable()) return true;
2730 }
2731 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2732 return false;
2733 } finally {
2734 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002735 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 }
2737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002739 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 enforceModifyPermission();
2741
2742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2745 logv("Shutting down Phone " + i);
2746 shutdownRadioUsingPhoneId(i);
2747 }
2748 } finally {
2749 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002750 }
2751 }
2752
2753 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002754 Phone phone = PhoneFactory.getPhone(phoneId);
2755 if (phone != null && phone.isRadioAvailable()) {
2756 phone.shutdownRadio();
2757 }
2758 }
2759
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2766 if (defaultPhone != null) {
2767 defaultPhone.setRadioPower(turnOn);
2768 return true;
2769 } else {
2770 loge("There's no default phone.");
2771 return false;
2772 }
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002775 }
Wink Saville36469e72014-06-11 15:17:00 -07002776 }
2777
Wink Savilleb564aae2014-10-23 10:18:09 -07002778 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 final Phone phone = getPhone(subId);
2784 if (phone != null) {
2785 phone.setRadioPower(turnOn);
2786 return true;
2787 } else {
2788 return false;
2789 }
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002793 }
2794
Wink Saville36469e72014-06-11 15:17:00 -07002795 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 public boolean enableDataConnectivity() {
2798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 int subId = mSubscriptionController.getDefaultDataSubId();
2803 final Phone phone = getPhone(subId);
2804 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002805 phone.getDataEnabledSettings().setDataEnabled(
2806 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 return true;
2808 } else {
2809 return false;
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
2815
Wink Saville36469e72014-06-11 15:17:00 -07002816 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002817 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 public boolean disableDataConnectivity() {
2819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 int subId = mSubscriptionController.getDefaultDataSubId();
2824 final Phone phone = getPhone(subId);
2825 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002826 phone.getDataEnabledSettings().setDataEnabled(
2827 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 return true;
2829 } else {
2830 return false;
2831 }
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 }
2836
Sanket Padawe356d7632015-06-22 14:03:32 -07002837 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002838 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 final Phone phone = getPhone(subId);
2842 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002843 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 } else {
2845 return false;
2846 }
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851
2852 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002853 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002854 }
2855
pkanwarae03a6b2016-11-06 20:37:09 -08002856 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857 enforceCallPermission();
2858
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2862 return;
2863 }
2864 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2865 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2866 } finally {
2867 Binder.restoreCallingIdentity(identity);
2868 }
pkanwar32d516d2016-10-14 19:37:38 -07002869 };
2870
Wink Savilleb564aae2014-10-23 10:18:09 -07002871 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873
2874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2877 return false;
2878 }
2879 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002885 /**
2886 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2887 * tag on getCallState Binder call.
2888 */
2889 @Deprecated
2890 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002892 if (CompatChanges.isChangeEnabled(
2893 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2894 Binder.getCallingUid())) {
2895 // Do not allow this API to be called on API version 31+, it should only be
2896 // called on old apps using this Binder call directly.
2897 throw new SecurityException("This method can only be used for applications "
2898 + "targeting API version 30 or less.");
2899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 final long identity = Binder.clearCallingIdentity();
2901 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002902 Phone phone = getPhone(getDefaultSubscription());
2903 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2904 PhoneConstantConversions.convertCallState(phone.getState());
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
2908 }
2909
2910 @Override
2911 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2912 if (CompatChanges.isChangeEnabled(
2913 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2914 Binder.getCallingUid())) {
2915 // Check READ_PHONE_STATE for API version 31+
2916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2917 featureId, "getCallStateForSubscription")) {
2918 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2919 + "targeting API level 31+.");
2920 }
2921 }
2922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2926 PhoneConstantConversions.convertCallState(phone.getState());
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
2929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002933 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002934 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2935 }
2936
2937 @Override
2938 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 final long identity = Binder.clearCallingIdentity();
2940 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002941 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002943 if (phone.isUsingNewDataStack()) {
2944 return phone.getDataNetworkController().getInternetDataNetworkState();
2945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2947 } else {
2948 return PhoneConstantConversions.convertDataState(
2949 PhoneConstants.DataState.DISCONNECTED);
2950 }
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 }
2955
Sanket Padawe356d7632015-06-22 14:03:32 -07002956 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002957 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002958 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2959 }
2960
2961 @Override
2962 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963 final long identity = Binder.clearCallingIdentity();
2964 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002965 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966 if (phone != null) {
2967 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2968 } else {
2969 return TelephonyManager.DATA_ACTIVITY_NONE;
2970 }
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 }
2975
2976 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002977 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002978 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002979 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002980
2981 LocationAccessPolicy.LocationPermissionResult locationResult =
2982 LocationAccessPolicy.checkLocationPermission(mApp,
2983 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2984 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002985 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002986 .setCallingPid(Binder.getCallingPid())
2987 .setCallingUid(Binder.getCallingUid())
2988 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002989 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002990 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2991 .build());
2992 switch (locationResult) {
2993 case DENIED_HARD:
2994 throw new SecurityException("Not allowed to access cell location");
2995 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002996 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2997 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002998 }
2999
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003004 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003005 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
Svetoslav64fad262015-04-14 14:35:21 -07003009 }
3010
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003012 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003013 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3014 // registered cell info, so return a NULL country instead.
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003017 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3018 // Get default phone in this case.
3019 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3020 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003021 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003023 if (phone == null) return "";
3024 ServiceStateTracker sst = phone.getServiceStateTracker();
3025 if (sst == null) return "";
3026 LocaleTracker lt = sst.getLocaleTracker();
3027 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003028 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003029 } finally {
3030 Binder.restoreCallingIdentity(identity);
3031 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003032 }
3033
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003034 /**
3035 * This method was removed due to potential issues caused by performing partial
3036 * updates of service state, and lack of a credible use case.
3037 *
3038 * This has the ability to break the telephony implementation by disabling notification of
3039 * changes in device connectivity. DO NOT USE THIS!
3040 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003041 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 public void enableLocationUpdates() {
3043 mApp.enforceCallingOrSelfPermission(
3044 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003045 }
3046
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003047 /**
3048 * This method was removed due to potential issues caused by performing partial
3049 * updates of service state, and lack of a credible use case.
3050 *
3051 * This has the ability to break the telephony implementation by disabling notification of
3052 * changes in device connectivity. DO NOT USE THIS!
3053 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 @Override
3055 public void disableLocationUpdates() {
3056 mApp.enforceCallingOrSelfPermission(
3057 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 }
3059
3060 @Override
3061 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003062 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3063 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003064 try {
3065 mApp.getSystemService(AppOpsManager.class)
3066 .checkPackage(Binder.getCallingUid(), callingPackage);
3067 } catch (SecurityException e) {
3068 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3069 throw e;
3070 }
3071
Nathan Haroldf096d982020-11-18 17:18:06 -08003072 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003073 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3074 throw new SecurityException(
3075 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3076 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003077
Jordan Liu1617b712019-07-10 15:06:26 -07003078 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003079 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3080 return null;
3081 }
Svetoslav64fad262015-04-14 14:35:21 -07003082
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003083 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003085 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003086 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003087
Nathan Haroldf180aac2018-06-01 18:43:55 -07003088 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3089 for (CellInfo ci : info) {
3090 if (ci instanceof CellInfoGsm) {
3091 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3092 } else if (ci instanceof CellInfoWcdma) {
3093 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003095 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003096 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 }
3098
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003099 private List<CellInfo> getCachedCellInfo() {
3100 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3101 for (Phone phone : PhoneFactory.getPhones()) {
3102 List<CellInfo> info = phone.getAllCellInfo();
3103 if (info != null) cellInfos.addAll(info);
3104 }
3105 return cellInfos;
3106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107
3108 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003109 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003110 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003111 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003112
3113 LocationAccessPolicy.LocationPermissionResult locationResult =
3114 LocationAccessPolicy.checkLocationPermission(mApp,
3115 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3116 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003117 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003118 .setCallingPid(Binder.getCallingPid())
3119 .setCallingUid(Binder.getCallingUid())
3120 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003121 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003122 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3123 .build());
3124 switch (locationResult) {
3125 case DENIED_HARD:
3126 throw new SecurityException("Not allowed to access cell info");
3127 case DENIED_SOFT:
3128 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 }
3130
Nathan Haroldf096d982020-11-18 17:18:06 -08003131 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003132 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3133 return getCachedCellInfo();
3134 }
3135
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003136 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3141 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003142 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003143 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144 if (info != null) cellInfos.addAll(info);
3145 }
3146 return cellInfos;
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 }
3150 }
3151
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003152 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003153 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3154 String callingFeatureId) {
3155 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3156 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003157 }
3158
3159 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003160 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3161 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003162 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003163 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003164 }
3165
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003166 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3167 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003168 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003169 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003170
3171 LocationAccessPolicy.LocationPermissionResult locationResult =
3172 LocationAccessPolicy.checkLocationPermission(mApp,
3173 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3174 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003175 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003176 .setCallingPid(Binder.getCallingPid())
3177 .setCallingUid(Binder.getCallingUid())
3178 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003179 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3180 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003181 .build());
3182 switch (locationResult) {
3183 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003184 if (TelephonyPermissions
3185 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003186 // Safetynet logging for b/154934934
3187 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3188 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003189 throw new SecurityException("Not allowed to access cell info");
3190 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003191 if (TelephonyPermissions
3192 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003193 // Safetynet logging for b/154934934
3194 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3195 }
Nathan Harold5320c422019-05-09 10:26:08 -07003196 try {
3197 cb.onCellInfo(new ArrayList<CellInfo>());
3198 } catch (RemoteException re) {
3199 // Drop without consequences
3200 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003201 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003202 }
3203
Nathan Harolda939a962019-05-09 10:13:47 -07003204
3205 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003206 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3207
3208 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3209 }
3210
3211 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003213 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003214 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003218 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003222 }
3223
Shishir Agrawala9f32182016-04-12 12:00:16 -07003224 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003225 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003226 Phone phone = PhoneFactory.getPhone(slotIndex);
3227 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003228 return null;
3229 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003230 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003231 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003232 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003233 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003234 return null;
3235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 return phone.getImei();
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003243 }
3244
3245 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003246 public String getTypeAllocationCodeForSlot(int slotIndex) {
3247 Phone phone = PhoneFactory.getPhone(slotIndex);
3248 String tac = null;
3249 if (phone != null) {
3250 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003251 try {
3252 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3253 } catch (IndexOutOfBoundsException e) {
3254 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3255 return null;
3256 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003257 }
3258 return tac;
3259 }
3260
3261 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003262 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003263 try {
3264 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3265 } catch (SecurityException se) {
3266 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3267 throw new SecurityException("Package " + callingPackage + " does not belong to "
3268 + Binder.getCallingUid());
3269 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003270 Phone phone = PhoneFactory.getPhone(slotIndex);
3271 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003272 return null;
3273 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274
Jeff Davidson913390f2018-02-23 17:11:49 -08003275 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003276 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003277 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003278 return null;
3279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
3281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 return phone.getMeid();
3284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
Jack Yu2af8d712017-03-15 17:14:14 -07003287 }
3288
3289 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003290 public String getManufacturerCodeForSlot(int slotIndex) {
3291 Phone phone = PhoneFactory.getPhone(slotIndex);
3292 String manufacturerCode = null;
3293 if (phone != null) {
3294 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003295 try {
3296 manufacturerCode =
3297 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3298 } catch (IndexOutOfBoundsException e) {
3299 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3300 return null;
3301 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003302 }
3303 return manufacturerCode;
3304 }
3305
3306 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003307 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3308 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003309 Phone phone = PhoneFactory.getPhone(slotIndex);
3310 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003311 return null;
3312 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003313 int subId = phone.getSubId();
3314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003315 mApp, subId, callingPackage, callingFeatureId,
3316 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003317 return null;
3318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319
3320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 return phone.getDeviceSvn();
3323 } finally {
3324 Binder.restoreCallingIdentity(identity);
3325 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003326 }
3327
fionaxu43304da2017-11-27 22:51:16 -08003328 @Override
3329 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 final Phone phone = getPhone(subId);
3333 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
fionaxu43304da2017-11-27 22:51:16 -08003337 }
3338
3339 @Override
3340 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 final Phone phone = getPhone(subId);
3344 return phone == null ? null : phone.getCarrierName();
3345 } finally {
3346 Binder.restoreCallingIdentity(identity);
3347 }
fionaxu43304da2017-11-27 22:51:16 -08003348 }
3349
calvinpanffe225e2018-11-01 19:43:06 +08003350 @Override
chen xu0026ca62019-03-06 15:28:50 -08003351 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 final Phone phone = getPhone(subId);
3355 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003356 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
3360 }
3361
3362 @Override
chen xu0026ca62019-03-06 15:28:50 -08003363 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003364 final long identity = Binder.clearCallingIdentity();
3365 try {
3366 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003367 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
3371 }
3372
chen xu651eec72018-11-11 19:03:44 -08003373 @Override
chen xu864e11c2018-12-06 22:10:03 -08003374 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3375 if (!isSubscriptionMccMnc) {
3376 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3377 }
chen xu651eec72018-11-11 19:03:44 -08003378 final Phone phone = PhoneFactory.getPhone(slotIndex);
3379 if (phone == null) {
3380 return TelephonyManager.UNKNOWN_CARRIER_ID;
3381 }
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3385 } finally {
3386 Binder.restoreCallingIdentity(identity);
3387 }
3388 }
3389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 //
3391 // Internal helper methods.
3392 //
3393
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003394 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003395 * Make sure the caller is the calling package itself
3396 *
3397 * @throws SecurityException if the caller is not the calling package
3398 */
3399 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3400 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003401 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3402 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003403 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003404 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003405 } catch (PackageManager.NameNotFoundException e) {
3406 // packageUid is -1
3407 }
3408 if (packageUid != callingUid) {
3409 throw new SecurityException(message + ": Package " + callingPackage
3410 + " does not belong to " + callingUid);
3411 }
3412 }
3413
3414 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3416 *
3417 * @throws SecurityException if the caller does not have the required permission
3418 */
3419 private void enforceModifyPermission() {
3420 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3421 }
3422
Shuo Qian3b6ee772019-11-13 17:43:31 -08003423 private void enforceActiveEmergencySessionPermission() {
3424 mApp.enforceCallingOrSelfPermission(
3425 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3426 }
3427
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003428 /**
3429 * Make sure the caller has the CALL_PHONE permission.
3430 *
3431 * @throws SecurityException if the caller does not have the required permission
3432 */
3433 private void enforceCallPermission() {
3434 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3435 }
3436
paulhu5a773602019-08-23 19:17:33 +08003437 private void enforceSettingsPermission() {
3438 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003439 }
3440
Michele Berionne5e411512020-11-13 02:36:59 +00003441 private void enforceRebootPermission() {
3442 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3443 }
3444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 private String createTelUrl(String number) {
3446 if (TextUtils.isEmpty(number)) {
3447 return null;
3448 }
3449
Jake Hambye994d462014-02-03 13:10:13 -08003450 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 }
3452
Ihab Awadf9e92732013-12-05 18:02:52 -08003453 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003454 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3455 }
3456
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003457 private static void logv(String msg) {
3458 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3459 }
3460
Ihab Awadf9e92732013-12-05 18:02:52 -08003461 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003462 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3463 }
3464
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003465 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003466 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003467 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003468 }
3469
Sanket Padawe356d7632015-06-22 14:03:32 -07003470 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003471 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472 final long identity = Binder.clearCallingIdentity();
3473 try {
3474 final Phone phone = PhoneFactory.getPhone(slotIndex);
3475 if (phone == null) {
3476 return PhoneConstants.PHONE_TYPE_NONE;
3477 } else {
3478 return phone.getPhoneType();
3479 }
3480 } finally {
3481 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483 }
3484
3485 /**
3486 * Returns the CDMA ERI icon index to display
3487 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003489 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3490 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3491 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003492 }
3493
Sanket Padawe356d7632015-06-22 14:03:32 -07003494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003495 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3496 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003498 mApp, subId, callingPackage, callingFeatureId,
3499 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003500 return -1;
3501 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003502
3503 final long identity = Binder.clearCallingIdentity();
3504 try {
3505 final Phone phone = getPhone(subId);
3506 if (phone != null) {
3507 return phone.getCdmaEriIconIndex();
3508 } else {
3509 return -1;
3510 }
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514 }
3515
3516 /**
3517 * Returns the CDMA ERI icon mode,
3518 * 0 - ON
3519 * 1 - FLASHING
3520 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003521 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003522 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3523 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3524 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003525 }
3526
Sanket Padawe356d7632015-06-22 14:03:32 -07003527 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003528 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3529 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003531 mApp, subId, callingPackage, callingFeatureId,
3532 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003533 return -1;
3534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535
3536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 final Phone phone = getPhone(subId);
3539 if (phone != null) {
3540 return phone.getCdmaEriIconMode();
3541 } else {
3542 return -1;
3543 }
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003547 }
3548
3549 /**
3550 * Returns the CDMA ERI text,
3551 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003553 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3554 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3555 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003556 }
3557
Sanket Padawe356d7632015-06-22 14:03:32 -07003558 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003559 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3560 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003562 mApp, subId, callingPackage, callingFeatureId,
3563 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003564 return null;
3565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566
3567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 final Phone phone = getPhone(subId);
3570 if (phone != null) {
3571 return phone.getCdmaEriText();
3572 } else {
3573 return null;
3574 }
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003578 }
3579
3580 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003581 * Returns the CDMA MDN.
3582 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003583 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003584 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3586 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592 return phone.getLine1Number();
3593 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003594 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595 return null;
3596 }
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003599 }
3600 }
3601
3602 /**
3603 * Returns the CDMA MIN.
3604 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003605 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003606 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3608 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609
3610 final long identity = Binder.clearCallingIdentity();
3611 try {
3612 final Phone phone = getPhone(subId);
3613 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3614 return phone.getCdmaMin();
3615 } else {
3616 return null;
3617 }
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003620 }
3621 }
3622
Hall Liud892bec2018-11-30 14:51:45 -08003623 @Override
3624 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3625 INumberVerificationCallback callback, String callingPackage) {
3626 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3627 != PERMISSION_GRANTED) {
3628 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3629 }
3630 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3631
3632 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3633 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003634 throw new SecurityException("Calling package must be configured in the device config: "
3635 + "calling package: " + callingPackage
3636 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003637 }
3638
3639 if (range == null) {
3640 throw new NullPointerException("Range must be non-null");
3641 }
3642
3643 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003644 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003645
3646 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3647 }
3648
Junda Liuca05d5d2014-08-14 22:36:34 -07003649 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003650 * Returns true if CDMA provisioning needs to run.
3651 */
3652 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 final long identity = Binder.clearCallingIdentity();
3654 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003655 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003659 }
3660
3661 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003662 * Sets the voice mail number of a given subId.
3663 */
3664 @Override
3665 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003666 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3667 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668
3669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3672 new Pair<String, String>(alphaTag, number), new Integer(subId));
3673 return success;
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003677 }
3678
Ta-wei Yen87c49842016-05-13 21:19:52 -07003679 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003680 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003682 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3683 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003684 if (!TextUtils.equals(callingPackage, systemDialer)) {
3685 throw new SecurityException("caller must be system dialer");
3686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3691 if (phoneAccountHandle == null) {
3692 return null;
3693 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003694 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003695 } finally {
3696 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003697 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003698 }
3699
3700 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003701 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3702 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003705 mApp, subId, callingPackage, callingFeatureId,
3706 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003707 return null;
3708 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003709
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003710 final long identity = Binder.clearCallingIdentity();
3711 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003716 }
3717
3718 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003719 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3720 VisualVoicemailSmsFilterSettings settings) {
3721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003722
3723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003726 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003730 }
3731
3732 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003733 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003743 }
3744
3745 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003746 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3747 String callingPackage, int subId) {
3748 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749
3750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003753 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754 } finally {
3755 Binder.restoreCallingIdentity(identity);
3756 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003757 }
3758
3759 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003760 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762
3763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003766 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767 } finally {
3768 Binder.restoreCallingIdentity(identity);
3769 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003770 }
3771
3772 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003773 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3774 String callingAttributionTag, int subId, String number, int port, String text,
3775 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003777 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003778 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003779 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003780 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3781 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003782 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003783
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003784 /**
fionaxu0152e512016-11-14 13:36:14 -08003785 * Sets the voice activation state of a given subId.
3786 */
3787 @Override
3788 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3790 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 final Phone phone = getPhone(subId);
3795 if (phone != null) {
3796 phone.setVoiceActivationState(activationState);
3797 } else {
3798 loge("setVoiceActivationState fails with invalid subId: " + subId);
3799 }
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003802 }
3803 }
3804
3805 /**
3806 * Sets the data activation state of a given subId.
3807 */
3808 @Override
3809 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3811 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
3813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 final Phone phone = getPhone(subId);
3816 if (phone != null) {
3817 phone.setDataActivationState(activationState);
3818 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003819 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 }
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003823 }
3824 }
3825
3826 /**
3827 * Returns the voice activation state of a given subId.
3828 */
3829 @Override
3830 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832
fionaxu0152e512016-11-14 13:36:14 -08003833 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 if (phone != null) {
3837 return phone.getVoiceActivationState();
3838 } else {
3839 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003843 }
3844 }
3845
3846 /**
3847 * Returns the data activation state of a given subId.
3848 */
3849 @Override
3850 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003852
fionaxu0152e512016-11-14 13:36:14 -08003853 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 if (phone != null) {
3857 return phone.getDataActivationState();
3858 } else {
3859 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3860 }
3861 } finally {
3862 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003863 }
3864 }
3865
3866 /**
Wink Saville36469e72014-06-11 15:17:00 -07003867 * Returns the unread count of voicemails for a subId
3868 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003869 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003870 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3871 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003873 mApp, subId, callingPackage, callingFeatureId,
3874 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003875 return 0;
3876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003877 final long identity = Binder.clearCallingIdentity();
3878 try {
3879 final Phone phone = getPhone(subId);
3880 if (phone != null) {
3881 return phone.getVoiceMessageCount();
3882 } else {
3883 return 0;
3884 }
3885 } finally {
3886 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003888 }
3889
3890 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003891 * returns true, if the device is in a state where both voice and data
3892 * are supported simultaneously. This can change based on location or network condition.
3893 */
3894 @Override
3895 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 final Phone phone = getPhone(subId);
3899 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
3902 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003903 }
3904
3905 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003906 * Send the dialer code if called from the current default dialer or the caller has
3907 * carrier privilege.
3908 * @param inputCode The dialer code to send
3909 */
3910 @Override
3911 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003912 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003913 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003914 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3915 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003916 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003917 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003918 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920
3921 final long identity = Binder.clearCallingIdentity();
3922 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003923 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003924 } finally {
3925 Binder.restoreCallingIdentity(identity);
3926 }
fionaxu235cc5e2017-03-06 22:25:57 -08003927 }
3928
Pengquan Menga1bb6272018-09-06 09:59:22 -07003929 @Override
3930 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003931 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003932 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003933 mApp, subId, "getNetworkSelectionMode");
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 if (!isActiveSubscription(subId)) {
3937 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3938 }
3939 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003942 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003943 }
3944
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003946 public boolean isInEmergencySmsMode() {
3947 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 for (Phone phone : PhoneFactory.getPhones()) {
3951 if (phone.isInEmergencySmsMode()) {
3952 return true;
3953 }
3954 }
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
3958 return false;
3959 }
3960
shilu366312e2019-12-17 09:28:10 -08003961 /**
3962 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3963 * @param subId The subscription to use to check the configuration.
3964 * @param c The callback that will be used to send the result.
3965 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003966 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003967 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3968 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003969 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003970 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003971
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003972 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3973 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3974 "IMS not available on device.");
3975 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 final long token = Binder.clearCallingIdentity();
3977 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003978 int slotId = getSlotIndexOrException(subId);
3979 verifyImsMmTelConfiguredOrThrow(slotId);
3980 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003981 } catch (ImsException e) {
3982 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 } finally {
3984 Binder.restoreCallingIdentity(token);
3985 }
3986 }
3987
shilu366312e2019-12-17 09:28:10 -08003988 /**
3989 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3990 * @param subId The subscription to use to check the configuration.
3991 * @param c The callback that will be used to send the result.
3992 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003994 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003995 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003996 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003997 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3998 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3999 }
Meng Wangafbc5852019-09-19 17:37:13 -07004000 final long token = Binder.clearCallingIdentity();
4001 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004002 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4003 .removeRegistrationCallbackForSubscription(c, subId);
4004 } catch (ImsException e) {
4005 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4006 + "is inactive, ignoring unregister.");
4007 // If the subscription is no longer active, just return, since the callback
4008 // will already have been removed internally.
4009 } finally {
4010 Binder.restoreCallingIdentity(token);
4011 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004012 }
4013
Brad Ebingera34a6c22019-10-22 17:36:18 -07004014 /**
4015 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4016 */
4017 @Override
4018 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4019 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4020 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4021 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4022 "IMS not available on device.");
4023 }
4024 final long token = Binder.clearCallingIdentity();
4025 try {
4026 Phone phone = getPhone(subId);
4027 if (phone == null) {
4028 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4029 + subId + "'");
4030 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4031 }
4032 phone.getImsRegistrationState(regState -> {
4033 try {
4034 consumer.accept((regState == null)
4035 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4036 } catch (RemoteException e) {
4037 // Ignore if the remote process is no longer available to call back.
4038 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4039 }
4040 });
4041 } finally {
4042 Binder.restoreCallingIdentity(token);
4043 }
4044 }
4045
4046 /**
4047 * Get the transport type for the IMS service registration state.
4048 */
4049 @Override
4050 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004051 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004052 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004053 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4054 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4055 "IMS not available on device.");
4056 }
4057 final long token = Binder.clearCallingIdentity();
4058 try {
4059 Phone phone = getPhone(subId);
4060 if (phone == null) {
4061 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4062 + subId + "'");
4063 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4064 }
4065 phone.getImsRegistrationTech(regTech -> {
4066 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4067 int regTechConverted = (regTech == null)
4068 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4069 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4070 regTechConverted);
4071 try {
4072 consumer.accept(regTechConverted);
4073 } catch (RemoteException e) {
4074 // Ignore if the remote process is no longer available to call back.
4075 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4076 }
4077 });
4078 } finally {
4079 Binder.restoreCallingIdentity(token);
4080 }
4081 }
4082
shilu366312e2019-12-17 09:28:10 -08004083 /**
4084 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4085 * @param subId The subscription to use to check the configuration.
4086 * @param c The callback that will be used to send the result.
4087 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004088 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004089 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4090 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004091 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004092 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004093 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4094 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4095 "IMS not available on device.");
4096 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004097 final long token = Binder.clearCallingIdentity();
4098 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004099 int slotId = getSlotIndexOrException(subId);
4100 verifyImsMmTelConfiguredOrThrow(slotId);
4101 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004102 } catch (ImsException e) {
4103 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004104 } finally {
4105 Binder.restoreCallingIdentity(token);
4106 }
4107 }
4108
shilu366312e2019-12-17 09:28:10 -08004109 /**
4110 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4111 * @param subId The subscription to use to check the configuration.
4112 * @param c The callback that will be used to send the result.
4113 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004115 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004116 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004117 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004118 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4119 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4120 }
Meng Wangafbc5852019-09-19 17:37:13 -07004121
4122 final long token = Binder.clearCallingIdentity();
4123 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004124 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004125 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004126 } catch (ImsException e) {
4127 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4128 + "is inactive, ignoring unregister.");
4129 // If the subscription is no longer active, just return, since the callback
4130 // will already have been removed internally.
4131 } finally {
4132 Binder.restoreCallingIdentity(token);
4133 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 }
4135
4136 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004137 public boolean isCapable(int subId, int capability, int regTech) {
4138 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 final long token = Binder.clearCallingIdentity();
4140 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004141 int slotId = getSlotIndexOrException(subId);
4142 verifyImsMmTelConfiguredOrThrow(slotId);
4143 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004144 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4146 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004147 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004148 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4149 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 } finally {
4151 Binder.restoreCallingIdentity(token);
4152 }
4153 }
4154
4155 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004156 public boolean isAvailable(int subId, int capability, int regTech) {
4157 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 final long token = Binder.clearCallingIdentity();
4159 try {
4160 Phone phone = getPhone(subId);
4161 if (phone == null) return false;
4162 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004163 } catch (com.android.ims.ImsException e) {
4164 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4165 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 } finally {
4167 Binder.restoreCallingIdentity(token);
4168 }
4169 }
4170
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004171 /**
4172 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4173 * subscription.
4174 * @param subId The subscription to use to check the configuration.
4175 * @param callback The callback that will be used to send the result.
4176 * @param capability The MmTelFeature capability that will be used to send the result.
4177 * @param transportType The transport type of the MmTelFeature capability.
4178 */
4179 @Override
4180 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4181 int transportType) {
4182 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4183 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4184 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4185 "IMS not available on device.");
4186 }
4187 final long token = Binder.clearCallingIdentity();
4188 try {
4189 int slotId = getSlotIndex(subId);
4190 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4191 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4192 + subId + "'");
4193 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4194 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004195 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004196 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4197 transportType, aBoolean -> {
4198 try {
4199 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4200 } catch (RemoteException e) {
4201 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4202 + "running. Ignore");
4203 }
4204 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004205 } catch (ImsException e) {
4206 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004207 } finally {
4208 Binder.restoreCallingIdentity(token);
4209 }
4210 }
4211
shilu366312e2019-12-17 09:28:10 -08004212 /**
4213 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4214 * @param subId The subscription to use to check the configuration.
4215 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 @Override
4217 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004218 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004219 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004220
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 final long token = Binder.clearCallingIdentity();
4222 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004223 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004224 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004225 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004226 } catch (ImsException e) {
4227 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 } finally {
4229 Binder.restoreCallingIdentity(token);
4230 }
4231 }
4232
4233 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004234 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004236 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 final long identity = Binder.clearCallingIdentity();
4238 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004239 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004240 // This setting doesn't require an active ImsService connection, so do not verify. The
4241 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004242 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004243 } catch (ImsException e) {
4244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
4248 }
4249
shilu366312e2019-12-17 09:28:10 -08004250 /**
4251 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4252 * @param subId The subscription to use to check the configuration.
4253 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004254 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004255 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004256 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004257 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 final long identity = Binder.clearCallingIdentity();
4259 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004260 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004261 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004262 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004263 } catch (ImsException e) {
4264 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
4268 }
4269
4270 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004271 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004273 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004274 final long identity = Binder.clearCallingIdentity();
4275 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004276 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004277 // This setting doesn't require an active ImsService connection, so do not verify. The
4278 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004280 } catch (ImsException e) {
4281 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
4285 }
4286
shilu366312e2019-12-17 09:28:10 -08004287 /**
4288 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4289 * @param subId The subscription to use to check the configuration.
4290 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 @Override
4292 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004293 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004294 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004300 } catch (ImsException e) {
4301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
4305 }
4306
4307 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004308 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004310 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 final long identity = Binder.clearCallingIdentity();
4312 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004313 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004314 // This setting doesn't require an active ImsService connection, so do not verify. The
4315 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004317 } catch (ImsException e) {
4318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
shilu366312e2019-12-17 09:28:10 -08004324 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004325 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4326 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4327 * @param subId The subscription to use to check the configuration.
4328 */
4329 @Override
4330 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004331 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004332 mApp, subId, "isCrossSimCallingEnabledByUser");
4333 final long identity = Binder.clearCallingIdentity();
4334 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004336 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004337 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004338 } catch (ImsException e) {
4339 throw new ServiceSpecificException(e.getCode());
4340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
4343 }
4344
4345 /**
4346 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4347 * Requires MODIFY_PHONE_STATE permission.
4348 * @param subId The subscription to use to check the configuration.
4349 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4350 * false otherwise
4351 */
4352 @Override
4353 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4355 "setCrossSimCallingEnabled");
4356 final long identity = Binder.clearCallingIdentity();
4357 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004359 // This setting doesn't require an active ImsService connection, so do not verify. The
4360 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004361 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004362 } catch (ImsException e) {
4363 throw new ServiceSpecificException(e.getCode());
4364 } finally {
4365 Binder.restoreCallingIdentity(identity);
4366 }
4367 }
4368
4369 /**
shilu366312e2019-12-17 09:28:10 -08004370 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4371 * @param subId The subscription to use to check the configuration.
4372 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004373 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004374
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004376 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004377 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 final long identity = Binder.clearCallingIdentity();
4379 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004380 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004381 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004382 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004383 } catch (ImsException e) {
4384 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
4388 }
4389
4390 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004391 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004393 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 final long identity = Binder.clearCallingIdentity();
4395 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004396 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004397 // This setting doesn't require an active ImsService connection, so do not verify. The
4398 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004399 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004400 } catch (ImsException e) {
4401 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
4405 }
4406
4407 @Override
4408 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4410 "setVoWiFiNonPersistent");
4411 final long identity = Binder.clearCallingIdentity();
4412 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004413 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004414 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004415 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004416 } catch (ImsException e) {
4417 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004418 } finally {
4419 Binder.restoreCallingIdentity(identity);
4420 }
4421 }
4422
shilu366312e2019-12-17 09:28:10 -08004423 /**
4424 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4425 * @param subId The subscription to use to check the configuration.
4426 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004427 @Override
4428 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004429 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004430 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 final long identity = Binder.clearCallingIdentity();
4432 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004433 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004434 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004435 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004436 } catch (ImsException e) {
4437 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 } finally {
4439 Binder.restoreCallingIdentity(identity);
4440 }
4441 }
4442
4443 @Override
4444 public void setVoWiFiModeSetting(int subId, int mode) {
4445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4446 "setVoWiFiModeSetting");
4447 final long identity = Binder.clearCallingIdentity();
4448 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004449 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004450 // This setting doesn't require an active ImsService connection, so do not verify. The
4451 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004452 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004453 } catch (ImsException e) {
4454 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
4458 }
4459
4460 @Override
4461 public int getVoWiFiRoamingModeSetting(int subId) {
4462 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4463 final long identity = Binder.clearCallingIdentity();
4464 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004465 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004466 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004467 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004468 } catch (ImsException e) {
4469 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004470 } finally {
4471 Binder.restoreCallingIdentity(identity);
4472 }
4473 }
4474
4475 @Override
4476 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4478 "setVoWiFiRoamingModeSetting");
4479 final long identity = Binder.clearCallingIdentity();
4480 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004482 // This setting doesn't require an active ImsService connection, so do not verify. The
4483 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004484 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004485 } catch (ImsException e) {
4486 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
4490 }
4491
4492 @Override
4493 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4495 "setRttCapabilityEnabled");
4496 final long identity = Binder.clearCallingIdentity();
4497 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004499 // This setting doesn't require an active ImsService connection, so do not verify. The
4500 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004501 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004502 } catch (ImsException e) {
4503 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
4507 }
4508
shilu366312e2019-12-17 09:28:10 -08004509 /**
4510 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4511 * @param subId The subscription to use to check the configuration.
4512 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 @Override
4514 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004515 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004516 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004517 final long identity = Binder.clearCallingIdentity();
4518 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004519 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004520 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004521 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004522 } catch (ImsException e) {
4523 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 }
4528
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004529 @Override
4530 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4531 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4532 final long identity = Binder.clearCallingIdentity();
4533 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004534 if (!isImsAvailableOnDevice()) {
4535 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4536 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004537 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 int slotId = getSlotIndexOrException(subId);
4539 verifyImsMmTelConfiguredOrThrow(slotId);
4540 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004541 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004542 } catch (ImsException e) {
4543 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004544 } finally {
4545 Binder.restoreCallingIdentity(identity);
4546 }
4547 }
4548
4549 @Override
4550 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4551 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4552 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004553 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4554 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4555 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004556 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004557 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004558 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004559 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004560 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4561 + "is inactive, ignoring unregister.");
4562 // If the subscription is no longer active, just return, since the callback will already
4563 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
4567 }
4568
allenwtsu99c623b2020-01-03 18:24:23 +08004569
4570 private void checkModifyPhoneStatePermission(int subId, String message) {
4571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4572 message);
4573 }
4574
4575 private boolean isImsProvisioningRequired(int subId, int capability,
4576 boolean isMmtelCapability) {
4577 Phone phone = getPhone(subId);
4578 if (phone == null) {
4579 loge("phone instance null for subid " + subId);
4580 return false;
4581 }
4582 if (isMmtelCapability) {
4583 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4584 return false;
4585 }
4586 } else {
4587 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4588 return false;
4589 }
4590 }
4591 return true;
4592 }
4593
4594 @Override
4595 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4596 boolean isProvisioned) {
4597 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4598
4599 final long identity = Binder.clearCallingIdentity();
4600 try {
4601 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4602 if (!isImsProvisioningRequired(subId, capability, false)) {
4603 return;
4604 }
4605
4606 // this capability requires provisioning, route to the correct API.
4607 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4608 switch (capability) {
4609 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4610 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4611 ims.setEabProvisioned(isProvisioned);
4612 break;
4613 default: {
4614 throw new IllegalArgumentException("Tried to set provisioning for "
4615 + "rcs capability '" + capability + "', which does not require "
4616 + "provisioning.");
4617 }
4618 }
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
4622
4623 }
4624
4625
4626 @Override
4627 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4628 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4629 final long identity = Binder.clearCallingIdentity();
4630 try {
4631 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4632 if (!isImsProvisioningRequired(subId, capability, false)) {
4633 return true;
4634 }
4635
4636 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4637 switch (capability) {
4638 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4639 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4640 return ims.isEabProvisionedOnDevice();
4641
4642 default: {
4643 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4644 + "capability '" + capability + "', which does not require "
4645 + "provisioning.");
4646 }
4647 }
4648
4649 } finally {
4650 Binder.restoreCallingIdentity(identity);
4651 }
4652 }
4653
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004654 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004655 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4656 boolean isProvisioned) {
4657 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004658 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4659 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4660 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004661 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4662 }
allenwtsu99c623b2020-01-03 18:24:23 +08004663 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004664 final long identity = Binder.clearCallingIdentity();
4665 try {
4666 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004667 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004668 return;
4669 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004670 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4671 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4672 loge("setImsProvisioningStatusForCapability: called for technology that does "
4673 + "not support provisioning - " + tech);
4674 return;
4675 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004676
4677 // this capability requires provisioning, route to the correct API.
4678 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4679 switch (capability) {
4680 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4681 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4682 ims.setVolteProvisioned(isProvisioned);
4683 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4684 ims.setWfcProvisioned(isProvisioned);
4685 }
4686 break;
4687 }
4688 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4689 // There is currently no difference in VT provisioning type.
4690 ims.setVtProvisioned(isProvisioned);
4691 break;
4692 }
4693 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4694 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4695 // change the capability of the feature instead if needed.
4696 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4697 == isProvisioned) {
4698 // No change in provisioning.
4699 return;
4700 }
4701 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4702 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004703 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004704 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4706 + ", Exception" + e.getMessage());
4707 }
4708 break;
4709 }
4710 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004711 throw new IllegalArgumentException("Tried to set provisioning for "
4712 + "MmTel capability '" + capability + "', which does not require "
4713 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 }
4715 }
4716
4717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
4720 }
4721
4722 @Override
4723 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4724 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004725 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4726 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4727 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004728 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4729 }
4730 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004734 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 return true;
4736 }
4737
Brad Ebinger0d79c572021-04-17 15:20:49 -07004738 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4739 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4740 loge("getImsProvisioningStatusForCapability: called for technology that does "
4741 + "not support provisioning - " + tech);
4742 return true;
4743 }
4744
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004745 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4746 switch (capability) {
4747 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4748 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4749 return ims.isVolteProvisionedOnDevice();
4750 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4751 return ims.isWfcProvisionedOnDevice();
4752 }
4753 // This should never happen, since we are checking tech above to make sure it
4754 // is either LTE or IWLAN.
4755 throw new IllegalArgumentException("Invalid radio technology for voice "
4756 + "capability.");
4757 }
4758 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4759 // There is currently no difference in VT provisioning type.
4760 return ims.isVtProvisionedOnDevice();
4761 }
4762 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4763 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4764 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4765 }
4766 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004767 throw new IllegalArgumentException(
4768 "Tried to get provisioning for MmTel capability '" + capability
4769 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004770 }
4771 }
4772
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
4776 }
4777
4778 @Override
4779 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4780 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4781 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4782 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4783 }
4784 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4785 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4786 return (provisionedBits & capability) > 0;
4787 }
4788
4789 @Override
4790 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4791 boolean isProvisioned) {
4792 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4793 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4794 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4795 }
4796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4797 "setProvisioningStatusForCapability");
4798 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4799 // If the current provisioning status for capability already matches isProvisioned,
4800 // do nothing.
4801 if (((provisionedBits & capability) > 0) == isProvisioned) {
4802 return;
4803 }
4804 if (isProvisioned) {
4805 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4806 } else {
4807 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4808 }
4809 }
4810
4811 /**
4812 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4813 * technology. The bitfield should mirror the bitfield defined by
4814 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4815 */
4816 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4817 String key = getMmTelProvisioningKey(subId, tech);
4818 // Default is no capabilities are provisioned.
4819 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4820 }
4821
4822 /**
4823 * Sets the MmTel capability provisioning bitfield (defined by
4824 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4825 * technology specified.
4826 *
4827 * Note: This is a synchronous command and should not be called on UI thread.
4828 */
4829 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4830 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4831 String key = getMmTelProvisioningKey(subId, tech);
4832 editor.putInt(key, newField);
4833 editor.commit();
4834 }
4835
4836 private static String getMmTelProvisioningKey(int subId, int tech) {
4837 // resulting key is provision_ims_mmtel_{subId}_{tech}
4838 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4839 }
4840
4841 /**
4842 * Query CarrierConfig to see if the specified capability requires provisioning for the
4843 * carrier associated with the subscription id.
4844 */
4845 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4846 int capability) {
4847 CarrierConfigManager configManager = new CarrierConfigManager(context);
4848 PersistableBundle c = configManager.getConfigForSubId(subId);
4849 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004850 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004851 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4852 false);
4853 boolean requireVoiceVtProvisioning = c.getBoolean(
4854 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4855
4856 // First check to make sure that the capability requires provisioning.
4857 switch (capability) {
4858 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4859 // intentional fallthrough
4860 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4861 if (requireVoiceVtProvisioning) {
4862 // Voice and Video requires provisioning
4863 return true;
4864 }
4865 break;
4866 }
4867 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4868 if (requireUtProvisioning) {
4869 // UT requires provisioning
4870 return true;
4871 }
4872 break;
4873 }
4874 }
4875 return false;
4876 }
4877
allenwtsu99c623b2020-01-03 18:24:23 +08004878 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4879 int capability) {
4880 CarrierConfigManager configManager = new CarrierConfigManager(context);
4881 PersistableBundle c = configManager.getConfigForSubId(subId);
4882
4883 boolean requireRcsProvisioning = c.getBoolean(
4884 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4885
4886 // First check to make sure that the capability requires provisioning.
4887 switch (capability) {
4888 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4889 // intentional fallthrough
4890 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4891 if (requireRcsProvisioning) {
4892 // OPTION or PRESENCE requires provisioning
4893 return true;
4894 }
4895 break;
4896 }
4897 }
4898 return false;
4899 }
4900
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004901 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004902 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004903 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4904 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4905 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004906 enforceReadPrivilegedPermission("getImsProvisioningInt");
4907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004910 int slotId = getSlotIndex(subId);
4911 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4912 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4913 + subId + "' for key:" + key);
4914 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4915 }
calvinpanb5a34062021-02-08 19:59:36 +08004916 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004917 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004918 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4919 + subId + "' for key:" + key);
4920 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
4924 }
4925
4926 @Override
4927 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004928 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4929 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4930 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004931 enforceReadPrivilegedPermission("getImsProvisioningString");
4932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004935 int slotId = getSlotIndex(subId);
4936 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4937 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4938 + subId + "' for key:" + key);
4939 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4940 }
calvinpanb5a34062021-02-08 19:59:36 +08004941 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004942 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4944 + subId + "' for key:" + key);
4945 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
4949 }
4950
4951 @Override
4952 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004953 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4954 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4955 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4957 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004961 int slotId = getSlotIndex(subId);
4962 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4963 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4964 + subId + "' for key:" + key);
4965 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4966 }
calvinpanb5a34062021-02-08 19:59:36 +08004967 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4968 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004969 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004970 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004971 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
4975 }
4976
4977 @Override
4978 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004979 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4980 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4981 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4983 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004984 final long identity = Binder.clearCallingIdentity();
4985 try {
4986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004987 int slotId = getSlotIndex(subId);
4988 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4989 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4990 + subId + "' for key:" + key);
4991 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4992 }
calvinpanb5a34062021-02-08 19:59:36 +08004993 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4994 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004995 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004996 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004997 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004998 } finally {
4999 Binder.restoreCallingIdentity(identity);
5000 }
5001 }
5002
Brad Ebinger919631e2021-06-02 17:46:35 -07005003 /**
5004 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5005 * for the given slot ID or no ImsResolver instance has been created.
5006 * @param slotId The slot ID that the IMS service is created for.
5007 * @throws ImsException If there is no ImsService configured for this slot.
5008 */
5009 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5010 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5011 ImsFeature.FEATURE_MMTEL)) {
5012 throw new ImsException("This subscription does not support MMTEL over IMS",
5013 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5014 }
5015 }
5016
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005017 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005018 int slotId = SubscriptionManager.getSlotIndex(subId);
5019 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005020 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5021 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005022 }
5023 return slotId;
5024 }
5025
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005026 private int getSlotIndex(int subId) {
5027 int slotId = SubscriptionManager.getSlotIndex(subId);
5028 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5029 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5030 }
5031 return slotId;
5032 }
5033
Wink Saville36469e72014-06-11 15:17:00 -07005034 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005035 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005036 */
5037 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005038 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5039 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005040 try {
5041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5042 } catch (SecurityException se) {
5043 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5044 throw new SecurityException("Package " + callingPackage + " does not belong to "
5045 + Binder.getCallingUid());
5046 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005047 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005048 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005049 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005050 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005051 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005052 mApp, subId, callingPackage, callingFeatureId,
5053 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005054 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5055 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 final long identity = Binder.clearCallingIdentity();
5058 try {
5059 final Phone phone = getPhone(subId);
5060 if (phone != null) {
5061 return phone.getServiceState().getDataNetworkType();
5062 } else {
5063 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5064 }
5065 } finally {
5066 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005067 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005068 }
5069
5070 /**
5071 * Returns the data network type
5072 */
5073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005074 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005075 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5076 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005077 }
5078
5079 /**
5080 * Returns the data network type for a subId
5081 */
5082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005083 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5084 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005086 mApp, subId, callingPackage, callingFeatureId,
5087 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005088 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5089 }
5090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 final Phone phone = getPhone(subId);
5094 if (phone != null) {
5095 return phone.getServiceState().getDataNetworkType();
5096 } else {
5097 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5098 }
5099 } finally {
5100 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005101 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005102 }
5103
5104 /**
Wink Saville36469e72014-06-11 15:17:00 -07005105 * Returns the Voice network type for a subId
5106 */
5107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005108 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005111 mApp, subId, callingPackage, callingFeatureId,
5112 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005113 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5114 }
5115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 final Phone phone = getPhone(subId);
5119 if (phone != null) {
5120 return phone.getServiceState().getVoiceNetworkType();
5121 } else {
5122 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5123 }
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005127 }
5128
5129 /**
5130 * @return true if a ICC card is present
5131 */
5132 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005133 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005134 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5135 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005136 }
5137
5138 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005139 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005140 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005141 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005142 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 final Phone phone = PhoneFactory.getPhone(slotIndex);
5146 if (phone != null) {
5147 return phone.getIccCard().hasIccCard();
5148 } else {
5149 return false;
5150 }
5151 } finally {
5152 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005154 }
5155
5156 /**
5157 * Return if the current radio is LTE on CDMA. This
5158 * is a tri-state return value as for a period of time
5159 * the mode may be unknown.
5160 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005161 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005162 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005163 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005164 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005166 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5167 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5168 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005169 }
5170
Sanket Padawe356d7632015-06-22 14:03:32 -07005171 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005172 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5173 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005174 try {
5175 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5176 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005177 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5178 }
5179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 final long identity = Binder.clearCallingIdentity();
5181 try {
5182 final Phone phone = getPhone(subId);
5183 if (phone == null) {
5184 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5185 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005186 return TelephonyProperties.lte_on_cdma_device()
5187 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 }
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005191 }
Wink Saville36469e72014-06-11 15:17:00 -07005192 }
5193
Wink Saville36469e72014-06-11 15:17:00 -07005194 /**
5195 * {@hide}
5196 * Returns Default subId, 0 in the case of single standby.
5197 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005198 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005199 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005200 }
5201
Shishir Agrawala9f32182016-04-12 12:00:16 -07005202 private int getSlotForDefaultSubscription() {
5203 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5204 }
5205
Wink Savilleb564aae2014-10-23 10:18:09 -07005206 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005207 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005208 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005209
Pengquan Menge92a50d2018-09-21 15:54:48 -07005210 private boolean isActiveSubscription(int subId) {
5211 return mSubscriptionController.isActiveSubId(subId);
5212 }
5213
Ihab Awadf2177b72013-11-25 13:33:23 -08005214 /**
5215 * @see android.telephony.TelephonyManager.WifiCallingChoices
5216 */
5217 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005220 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5222 getWhenToMakeWifiCallsDefaultPreference());
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005226 }
5227
5228 /**
5229 * @see android.telephony.TelephonyManager.WifiCallingChoices
5230 */
5231 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005235 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005240 }
5241
Sailesh Nepald1e68152013-12-12 19:08:02 -08005242 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005243 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005244 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005245 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005246
Jordan Liu4c733742019-02-28 12:03:40 -08005247 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5248 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5249 if (phoneId == -1) {
5250 throw new IllegalArgumentException("Given slot index: " + slotIndex
5251 + " does not correspond to an active phone");
5252 }
5253 return PhoneFactory.getPhone(phoneId);
5254 }
5255
Shishir Agrawal566b7612013-10-28 14:41:00 -07005256 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005257 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5258 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5260 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005262 if (DBG) {
5263 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5264 }
5265 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5266 p2);
5267 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005268
Jordan Liu4c733742019-02-28 12:03:40 -08005269
5270 @Override
5271 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5272 int slotIndex, String callingPackage, String aid, int p2) {
5273 enforceModifyPermission();
5274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5275 if (DBG) {
5276 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5277 }
5278 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5279 callingPackage, aid, p2);
5280 }
5281
5282 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5283 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final long identity = Binder.clearCallingIdentity();
5285 try {
5286 if (TextUtils.equals(ISDR_AID, aid)) {
5287 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005288 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5289 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 if (bestComponent == null
5291 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5292 loge("The calling package is not allowed to access ISD-R.");
5293 throw new SecurityException(
5294 "The calling package is not allowed to access ISD-R.");
5295 }
Derek Tan740e1672017-06-27 14:56:27 -07005296 }
Derek Tan740e1672017-06-27 14:56:27 -07005297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005299 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5300 null /* workSource */);
5301 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 return response;
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005306 }
5307
5308 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005309 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5311 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005312 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5313 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5314 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005315
Jordan Liu4c733742019-02-28 12:03:40 -08005316 @Override
5317 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5318 enforceModifyPermission();
5319 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5320 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5321 channel);
5322 }
5323
5324 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 final long identity = Binder.clearCallingIdentity();
5326 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 if (channel < 0) {
5328 return false;
5329 }
Jordan Liu4c733742019-02-28 12:03:40 -08005330 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5331 null /* workSource */);
5332 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 return success;
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337 }
5338
5339 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005340 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005341 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5343 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005344 if (DBG) {
5345 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5346 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5347 + p3 + " data=" + data);
5348 }
5349 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5350 command, p1, p2, p3, data);
5351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005352
Jordan Liu4c733742019-02-28 12:03:40 -08005353 @Override
5354 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5355 int command, int p1, int p2, int p3, String data) {
5356 enforceModifyPermission();
5357 if (DBG) {
5358 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5359 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5360 + p3 + " data=" + data);
5361 }
5362 return iccTransmitApduLogicalChannelWithPermission(
5363 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5364 data);
5365 }
5366
5367 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5368 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 final long identity = Binder.clearCallingIdentity();
5370 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005371 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 return "";
5373 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005376 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5377 null /* workSource */);
5378 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 // Append the returned status code to the end of the response payload.
5381 String s = Integer.toHexString(
5382 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5383 if (response.payload != null) {
5384 s = IccUtils.bytesToHexString(response.payload) + s;
5385 }
5386 return s;
5387 } finally {
5388 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005389 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005390 }
Jake Hambye994d462014-02-03 13:10:13 -08005391
Evan Charltonc66da362014-05-16 14:06:40 -07005392 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005393 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5394 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5396 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005398 if (DBG) {
5399 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5400 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5401 }
5402 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5403 cla, command, p1, p2, p3, data);
5404 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005405
Jordan Liu4c733742019-02-28 12:03:40 -08005406 @Override
5407 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5408 int command, int p1, int p2, int p3, String data) {
5409 enforceModifyPermission();
5410 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5411 if (DBG) {
5412 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5413 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5414 + " data=" + data);
5415 }
5416
5417 return iccTransmitApduBasicChannelWithPermission(
5418 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5419 p2, p3, data);
5420 }
5421
5422 // open APDU basic channel assuming the caller has sufficient permissions
5423 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5424 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5428 && TextUtils.equals(ISDR_AID, data)) {
5429 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005430 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5431 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 if (bestComponent == null
5433 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5434 loge("The calling package is not allowed to select ISD-R.");
5435 throw new SecurityException(
5436 "The calling package is not allowed to select ISD-R.");
5437 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005438 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005441 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5442 null /* workSource */);
5443 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 // Append the returned status code to the end of the response payload.
5446 String s = Integer.toHexString(
5447 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5448 if (response.payload != null) {
5449 s = IccUtils.bytesToHexString(response.payload) + s;
5450 }
5451 return s;
5452 } finally {
5453 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005454 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005455 }
5456
5457 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005458 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005459 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5461 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 if (DBG) {
5466 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5467 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5468 }
5469
5470 IccIoResult response =
5471 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5472 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5473 subId);
5474
5475 if (DBG) {
5476 log("Exchange SIM_IO [R]" + response);
5477 }
5478
5479 byte[] result = null;
5480 int length = 2;
5481 if (response.payload != null) {
5482 length = 2 + response.payload.length;
5483 result = new byte[length];
5484 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5485 } else {
5486 result = new byte[length];
5487 }
5488
5489 result[length - 1] = (byte) response.sw2;
5490 result[length - 2] = (byte) response.sw1;
5491 return result;
5492 } finally {
5493 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005494 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005495 }
5496
Nathan Haroldb3014052017-01-25 15:57:32 -08005497 /**
5498 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5499 * on a particular subscription
5500 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005501 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5502 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005504 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005505 return null;
5506 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507
5508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 if (appType != TelephonyManager.APPTYPE_USIM
5511 && appType != TelephonyManager.APPTYPE_SIM) {
5512 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5513 return null;
5514 }
5515 Object response = sendRequest(
5516 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5517 if (response instanceof String[]) {
5518 return (String[]) response;
5519 }
yincheng zhao2737e882019-09-06 17:06:54 -07005520 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005522 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 } finally {
5524 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005525 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005526 }
5527
yincheng zhao2737e882019-09-06 17:06:54 -07005528 /**
5529 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5530 * subscription.
5531 *
5532 * @param subId the id of the subscription.
5533 * @param appType the uicc app type, must be USIM or SIM.
5534 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5535 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005536 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005537 * @return number of fplmns that is successfully written to the SIM.
5538 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005539 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5540 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5542 mApp, subId, "setForbiddenPlmns");
5543
yincheng zhao2737e882019-09-06 17:06:54 -07005544 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5545 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5546 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5547 }
5548 if (fplmns == null) {
5549 throw new IllegalArgumentException("Fplmn List provided is null");
5550 }
5551 for (String fplmn : fplmns) {
5552 if (!CellIdentity.isValidPlmn(fplmn)) {
5553 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5554 }
5555 }
5556 final long identity = Binder.clearCallingIdentity();
5557 try {
5558 Object response = sendRequest(
5559 CMD_SET_FORBIDDEN_PLMNS,
5560 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5561 subId);
5562 return (int) response;
5563 } finally {
5564 Binder.restoreCallingIdentity(identity);
5565 }
5566 }
5567
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005568 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005569 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5571 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 final long identity = Binder.clearCallingIdentity();
5574 try {
5575 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5576 if (response.payload == null) {
5577 return "";
5578 }
Evan Charltonc66da362014-05-16 14:06:40 -07005579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 // Append the returned status code to the end of the response payload.
5581 String s = Integer.toHexString(
5582 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5583 s = IccUtils.bytesToHexString(response.payload) + s;
5584 return s;
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
Evan Charltonc66da362014-05-16 14:06:40 -07005588 }
5589
Jake Hambye994d462014-02-03 13:10:13 -08005590 /**
5591 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5592 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5593 *
5594 * @param itemID the ID of the item to read
5595 * @return the NV item as a String, or null on error.
5596 */
5597 @Override
5598 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005599 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5601 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602
5603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005606 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5608 return value;
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
5611 }
Jake Hambye994d462014-02-03 13:10:13 -08005612 }
5613
5614 /**
5615 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5616 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5617 *
5618 * @param itemID the ID of the item to read
5619 * @param itemValue the value to write, as a String
5620 * @return true on success; false on any failure
5621 */
5622 @Override
5623 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005624 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5631 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005632 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5634 return success;
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
Jake Hambye994d462014-02-03 13:10:13 -08005638 }
5639
5640 /**
5641 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5642 * Used for device configuration by some CDMA operators.
5643 *
5644 * @param preferredRoamingList byte array containing the new PRL
5645 * @return true on success; false on any failure
5646 */
5647 @Override
5648 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5650 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5655 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5656 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5657 return success;
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
Jake Hambye994d462014-02-03 13:10:13 -08005661 }
5662
5663 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005664 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005665 * Used for device configuration by some CDMA operators.
5666 *
chen xu6dac5ab2018-10-26 17:39:23 -07005667 * @param slotIndex - device slot.
5668 *
Jake Hambye994d462014-02-03 13:10:13 -08005669 * @return true on success; false on any failure
5670 */
5671 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005672 public boolean resetModemConfig(int slotIndex) {
5673 Phone phone = PhoneFactory.getPhone(slotIndex);
5674 if (phone != null) {
5675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5676 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677
chen xu6dac5ab2018-10-26 17:39:23 -07005678 final long identity = Binder.clearCallingIdentity();
5679 try {
5680 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5681 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5682 return success;
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 }
chen xu6dac5ab2018-10-26 17:39:23 -07005687 return false;
5688 }
5689
5690 /**
5691 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5692 *
5693 * @param slotIndex - device slot.
5694 *
5695 * @return true on success; false on any failure
5696 */
5697 @Override
5698 public boolean rebootModem(int slotIndex) {
5699 Phone phone = PhoneFactory.getPhone(slotIndex);
5700 if (phone != null) {
5701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5702 mApp, phone.getSubId(), "rebootModem");
5703
5704 final long identity = Binder.clearCallingIdentity();
5705 try {
5706 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5707 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5708 return success;
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
5712 }
5713 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005714 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005715
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005716 public String[] getPcscfAddress(String apnType, String callingPackage,
5717 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005718 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5720 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005721 return new String[0];
5722 }
5723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 final long identity = Binder.clearCallingIdentity();
5725 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005726 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
Wink Saville36469e72014-06-11 15:17:00 -07005730 }
5731
Brad Ebinger51f743a2017-01-23 13:50:20 -08005732 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005733 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5734 * {@link #disableIms(int)}.
5735 * @param slotIndex device slot.
5736 */
5737 public void resetIms(int slotIndex) {
5738 enforceModifyPermission();
5739
5740 final long identity = Binder.clearCallingIdentity();
5741 try {
5742 if (mImsResolver == null) {
5743 // may happen if the does not support IMS.
5744 return;
5745 }
5746 mImsResolver.disableIms(slotIndex);
5747 mImsResolver.enableIms(slotIndex);
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
5751 }
5752
5753 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005754 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5755 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005756 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005757 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759
5760 final long identity = Binder.clearCallingIdentity();
5761 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005762 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005763 // may happen if the device does not support IMS.
5764 return;
5765 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005770 }
5771
5772 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005773 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5774 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005775 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005776 public void disableIms(int slotId) {
5777 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778
5779 final long identity = Binder.clearCallingIdentity();
5780 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005781 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005782 // may happen if the device does not support IMS.
5783 return;
5784 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005785 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005789 }
5790
5791 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005792 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5793 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005794 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005795 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005796 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798
5799 final long identity = Binder.clearCallingIdentity();
5800 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005801 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005802 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5803 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005804 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005805 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005809 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005810 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005811 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5812 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005813 @Override
5814 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005815 enforceModifyPermission();
5816
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005820 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005821 } finally {
5822 Binder.restoreCallingIdentity(identity);
5823 }
5824 }
5825
5826 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005827 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005828 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005829 */
5830 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5831 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832
5833 final long identity = Binder.clearCallingIdentity();
5834 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005835 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005836 // may happen if the device does not support IMS.
5837 return null;
5838 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840 } finally {
5841 Binder.restoreCallingIdentity(identity);
5842 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005843 }
5844
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005845 /**
5846 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005847 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005848 */
5849 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851
5852 final long identity = Binder.clearCallingIdentity();
5853 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005854 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005855 // may happen if the device does not support IMS.
5856 return null;
5857 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005858 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005862 }
5863
Brad Ebinger884c07b2018-02-15 16:17:40 -08005864 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005865 * Sets the ImsService Package Name that Telephony will bind to.
5866 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 * @param slotIndex the slot ID that the ImsService should bind for.
5868 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005869 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 * @param featureTypes An integer array of feature types associated with a packageName.
5871 * @param packageName The name of the package that the current configuration will be replaced
5872 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005873 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005874 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005875 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5876 int[] featureTypes, String packageName) {
5877 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5878 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5880 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005881 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 final long identity = Binder.clearCallingIdentity();
5884 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005885 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005886 // may happen if the device does not support IMS.
5887 return false;
5888 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005889 Map<Integer, String> featureConfig = new HashMap<>();
5890 for (int featureType : featureTypes) {
5891 featureConfig.put(featureType, packageName);
5892 }
5893 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5894 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005898 }
5899
5900 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005901 * Clears any carrier ImsService overrides for the slot index specified that were previously
5902 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5903 *
5904 * This should only be used for testing.
5905 *
5906 * @param slotIndex the slot ID that the ImsService should bind for.
5907 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5908 */
5909 @Override
5910 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5911 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5912 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5913 "clearCarrierImsServiceOverride");
5914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5915 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5916 "clearCarrierImsServiceOverride");
5917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 if (mImsResolver == null) {
5921 // may happen if the device does not support IMS.
5922 return false;
5923 }
5924 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5925 } finally {
5926 Binder.restoreCallingIdentity(identity);
5927 }
5928 }
5929
5930 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005931 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005932 *
5933 * @param slotId The slot that the ImsService is associated with.
5934 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5935 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005937 * @return the package name of the ImsService configuration.
5938 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005939 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5940 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005941 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005942 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005943 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005944 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5945 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 final long identity = Binder.clearCallingIdentity();
5948 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005949 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005950 // may happen if the device does not support IMS.
5951 return "";
5952 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005953 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005954 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5955 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005959 }
5960
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005961 /**
5962 * Get the MmTelFeature state associated with the requested subscription id.
5963 * @param subId The subscription that the MmTelFeature is associated with.
5964 * @param callback A callback with an integer containing the
5965 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5966 */
5967 @Override
5968 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5969 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5970 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5971 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5972 "IMS not available on device.");
5973 }
5974 final long token = Binder.clearCallingIdentity();
5975 try {
5976 int slotId = getSlotIndex(subId);
5977 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5978 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5979 + subId + "'");
5980 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5981 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005982 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005983 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5984 try {
5985 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5986 } catch (RemoteException e) {
5987 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5988 + "Ignore");
5989 }
5990 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005991 } catch (ImsException e) {
5992 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005993 } finally {
5994 Binder.restoreCallingIdentity(token);
5995 }
5996 }
5997
Daniel Brightbb5840b2021-01-12 15:48:18 -08005998 /**
5999 * Sets the ims registration state on all valid {@link Phone}s.
6000 */
6001 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003
6004 final long identity = Binder.clearCallingIdentity();
6005 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006006 // NOTE: Before S, this method only set the default phone.
6007 for (final Phone phone : PhoneFactory.getPhones()) {
6008 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6009 phone.setImsRegistrationState(registered);
6010 }
6011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 } finally {
6013 Binder.restoreCallingIdentity(identity);
6014 }
Wink Saville36469e72014-06-11 15:17:00 -07006015 }
6016
6017 /**
Stuart Scott54788802015-03-30 13:18:01 -07006018 * Set the network selection mode to automatic.
6019 *
6020 */
6021 @Override
6022 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6024 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
shilufc958392020-01-20 11:36:01 -08006028 if (!isActiveSubscription(subId)) {
6029 return;
6030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006032 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6033 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
Stuart Scott54788802015-03-30 13:18:01 -07006037 }
6038
Jack Yud10cdd42020-09-28 20:28:01 -07006039 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006040 * Ask the radio to connect to the input network and change selection mode to manual.
6041 *
6042 * @param subId the id of the subscription.
6043 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6044 * the operator to attach to.
6045 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6046 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6047 * normal network selection next time.
6048 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006049 */
6050 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006051 public boolean setNetworkSelectionModeManual(
6052 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6054 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006055
6056 if (!isActiveSubscription(subId)) {
6057 return false;
6058 }
6059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 final long identity = Binder.clearCallingIdentity();
6061 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006062 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006064 if (DBG) {
6065 log("setNetworkSelectionModeManual: subId: " + subId
6066 + " operator: " + operatorInfo);
6067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6069 } finally {
6070 Binder.restoreCallingIdentity(identity);
6071 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006072 }
shilu84f6e8b2019-12-19 13:58:01 -08006073 /**
6074 * Get the manual network selection
6075 *
6076 * @param subId the id of the subscription.
6077 *
6078 * @return the previously saved user selected PLMN
6079 */
6080 @Override
6081 public String getManualNetworkSelectionPlmn(int subId) {
6082 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006083 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006084 mApp, subId, "getManualNetworkSelectionPlmn");
6085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006089 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006090 }
6091
6092 final Phone phone = getPhone(subId);
6093 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006094 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006095 }
6096 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6097 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6098 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
6102 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006103
6104 /**
6105 * Scans for available networks.
6106 */
6107 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006108 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6111 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006112 LocationAccessPolicy.LocationPermissionResult locationResult =
6113 LocationAccessPolicy.checkLocationPermission(mApp,
6114 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6115 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006116 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006117 .setCallingPid(Binder.getCallingPid())
6118 .setCallingUid(Binder.getCallingUid())
6119 .setMethod("getCellNetworkScanResults")
6120 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006121 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6122 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006123 .build());
6124 switch (locationResult) {
6125 case DENIED_HARD:
6126 throw new SecurityException("Not allowed to access scan results -- location");
6127 case DENIED_SOFT:
6128 return null;
6129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130
Pengquan Menga1bb6272018-09-06 09:59:22 -07006131 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 try {
6133 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006134 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006139 }
6140
6141 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006142 * Get the call forwarding info, given the call forwarding reason.
6143 */
6144 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006145 public void getCallForwarding(int subId, int callForwardingReason,
6146 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006147 enforceReadPrivilegedPermission("getCallForwarding");
6148 long identity = Binder.clearCallingIdentity();
6149 try {
6150 if (DBG) {
6151 log("getCallForwarding: subId " + subId
6152 + " callForwardingReason" + callForwardingReason);
6153 }
Hall Liu27d24262020-09-18 19:04:59 -07006154
6155 Phone phone = getPhone(subId);
6156 if (phone == null) {
6157 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006158 callback.onError(
6159 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006160 } catch (RemoteException e) {
6161 // ignore
6162 }
6163 return;
6164 }
6165
6166 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6167 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6168 @Override
6169 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6170 try {
6171 callback.onCallForwardingInfoAvailable(info);
6172 } catch (RemoteException e) {
6173 // ignore
6174 }
6175 }
6176
6177 @Override
6178 public void onError(int error) {
6179 try {
6180 callback.onError(error);
6181 } catch (RemoteException e) {
6182 // ignore
6183 }
6184 }
6185 });
6186 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
6193 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6194 * reason, the number to forward, and the timeout before the forwarding is attempted.
6195 */
6196 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006197 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6198 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006199 enforceModifyPermission();
6200 long identity = Binder.clearCallingIdentity();
6201 try {
6202 if (DBG) {
6203 log("setCallForwarding: subId " + subId
6204 + " callForwardingInfo" + callForwardingInfo);
6205 }
Hall Liu27d24262020-09-18 19:04:59 -07006206
6207 Phone phone = getPhone(subId);
6208 if (phone == null) {
6209 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006210 callback.accept(
6211 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006212 } catch (RemoteException e) {
6213 // ignore
6214 }
6215 return;
6216 }
6217
6218 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6219 FunctionalUtils.ignoreRemoteException(callback::accept));
6220
6221 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006222 } finally {
6223 Binder.restoreCallingIdentity(identity);
6224 }
6225 }
6226
6227 /**
Hall Liu27d24262020-09-18 19:04:59 -07006228 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006229 */
6230 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006231 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006232 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006233 long identity = Binder.clearCallingIdentity();
6234 try {
Hall Liu27d24262020-09-18 19:04:59 -07006235 Phone phone = getPhone(subId);
6236 if (phone == null) {
6237 try {
6238 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6239 } catch (RemoteException e) {
6240 // ignore
6241 }
6242 return;
6243 }
SongFerngWang0e767992021-03-31 22:08:45 +08006244 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6245 PersistableBundle c = configManager.getConfigForSubId(subId);
6246 boolean requireUssd = c.getBoolean(
6247 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006248
Shuo Qian4a594052020-01-23 11:59:30 -08006249 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006250 if (requireUssd) {
6251 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6252 getSubscriptionCarrierId(subId));
6253 String newUssdCommand = "";
6254 try {
6255 newUssdCommand = carrierXmlParser.getFeature(
6256 CarrierXmlParser.FEATURE_CALL_WAITING)
6257 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6258 } catch (NullPointerException e) {
6259 loge("Failed to generate USSD number" + e);
6260 }
6261 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6262 mMainThreadHandler, callback, carrierXmlParser,
6263 CarrierXmlParser.SsEntry.SSAction.QUERY);
6264 final String ussdCommand = newUssdCommand;
6265 Executors.newSingleThreadExecutor().execute(() -> {
6266 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6267 });
6268 } else {
6269 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6270 callback::accept);
6271 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6272 }
Shuo Qian4a594052020-01-23 11:59:30 -08006273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
6276 }
6277
6278 /**
Hall Liu27d24262020-09-18 19:04:59 -07006279 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006280 */
6281 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006282 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006283 enforceModifyPermission();
6284 long identity = Binder.clearCallingIdentity();
6285 try {
Hall Liu27d24262020-09-18 19:04:59 -07006286 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6287
6288 Phone phone = getPhone(subId);
6289 if (phone == null) {
6290 try {
6291 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6292 } catch (RemoteException e) {
6293 // ignore
6294 }
6295 return;
6296 }
6297
SongFerngWang0e767992021-03-31 22:08:45 +08006298 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6299 PersistableBundle c = configManager.getConfigForSubId(subId);
6300 boolean requireUssd = c.getBoolean(
6301 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006302
SongFerngWang0e767992021-03-31 22:08:45 +08006303 if (DBG) log("getCallWaitingStatus: subId " + subId);
6304 if (requireUssd) {
6305 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6306 getSubscriptionCarrierId(subId));
6307 CarrierXmlParser.SsEntry.SSAction ssAction =
6308 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6309 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6310 String newUssdCommand = "";
6311 try {
6312 newUssdCommand = carrierXmlParser.getFeature(
6313 CarrierXmlParser.FEATURE_CALL_WAITING)
6314 .makeCommand(ssAction, null);
6315 } catch (NullPointerException e) {
6316 loge("Failed to generate USSD number" + e);
6317 }
6318 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6319 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6320 final String ussdCommand = newUssdCommand;
6321 Executors.newSingleThreadExecutor().execute(() -> {
6322 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6323 });
6324 } else {
6325 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6326 FunctionalUtils.ignoreRemoteException(callback::accept));
6327
6328 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6329 }
Shuo Qian4a594052020-01-23 11:59:30 -08006330 } finally {
6331 Binder.restoreCallingIdentity(identity);
6332 }
6333 }
6334
6335 /**
yinxub1bed742017-04-17 11:45:04 -07006336 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006337 *
yinxub1bed742017-04-17 11:45:04 -07006338 * @param subId id of the subscription
6339 * @param request contains the radio access networks with bands/channels to scan
6340 * @param messenger callback messenger for scan results or errors
6341 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006342 * @return the id of the requested scan which can be used to stop the scan.
6343 */
6344 @Override
6345 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006346 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6348 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006349 LocationAccessPolicy.LocationPermissionResult locationResult =
6350 LocationAccessPolicy.checkLocationPermission(mApp,
6351 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6352 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006353 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006354 .setCallingPid(Binder.getCallingPid())
6355 .setCallingUid(Binder.getCallingUid())
6356 .setMethod("requestNetworkScan")
6357 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006358 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6359 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006360 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006361 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006362 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6363 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006364 if (e != null) {
6365 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6366 throw e;
6367 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006368 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006369 return TelephonyScanManager.INVALID_SCAN_ID;
6370 }
6371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372 }
Hall Liu912dfd32019-04-25 14:02:26 -07006373 int callingUid = Binder.getCallingUid();
6374 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006375 final long identity = Binder.clearCallingIdentity();
6376 try {
6377 return mNetworkScanRequestTracker.startNetworkScan(
6378 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006379 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
yinxu504e1392017-04-12 16:03:22 -07006383 }
6384
Hall Liub2ac8ef2019-02-28 15:56:23 -08006385 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006386 NetworkScanRequest request, int subId, String callingPackage) {
6387 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006388 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6389 boolean hasNetworkScanPermission =
6390 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6391 == PERMISSION_GRANTED;
6392
6393 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6394 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6395 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006396 }
6397
6398 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6399 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006400 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6401 return new SecurityException("Specific channels must not be"
6402 + " scanned without location access.");
6403 }
6404 }
6405 }
6406
Hall Liub2ac8ef2019-02-28 15:56:23 -08006407 return null;
6408 }
6409
yinxu504e1392017-04-12 16:03:22 -07006410 /**
6411 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006412 *
6413 * @param subId id of the subscription
6414 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006415 */
6416 @Override
6417 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6419 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420
Hall Liu912dfd32019-04-25 14:02:26 -07006421 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422 final long identity = Binder.clearCallingIdentity();
6423 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006424 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
yinxu504e1392017-04-12 16:03:22 -07006428 }
6429
6430 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006431 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006432 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006433 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006434 */
6435 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006436 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006437 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006438 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006439 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440
6441 final long identity = Binder.clearCallingIdentity();
6442 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006443 if (DBG) log("getAllowedNetworkTypesBitmask");
6444 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6445 int networkTypesBitmask = (result != null ? result[0] : -1);
6446 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6447 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006451 }
6452
6453 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006454 * Get the allowed network types for certain reason.
6455 *
6456 * @param subId the id of the subscription.
6457 * @param reason the reason the allowed network type change is taking place
6458 * @return the allowed network types.
6459 */
6460 @Override
6461 public long getAllowedNetworkTypesForReason(int subId,
6462 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006463 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006464 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
6471 }
6472
6473 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006474 * Enable/Disable E-UTRA-NR Dual Connectivity
6475 * @param subId subscription id of the sim card
6476 * @param nrDualConnectivityState expected NR dual connectivity state
6477 * This can be passed following states
6478 * <ol>
6479 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6480 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6481 * <li>Disable NR dual connectivity and force secondary cell to be released
6482 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6483 * </ol>
6484 * @return operation result.
6485 */
6486 @Override
6487 public int setNrDualConnectivityState(int subId,
6488 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6490 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006491 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006492 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6493 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6494 }
6495
Sooraj Sasindran37444802020-08-11 10:40:43 -07006496 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6497 final long identity = Binder.clearCallingIdentity();
6498 try {
6499 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6500 nrDualConnectivityState, subId,
6501 workSource);
6502 if (DBG) log("enableNRDualConnectivity result: " + result);
6503 return result;
6504 } finally {
6505 Binder.restoreCallingIdentity(identity);
6506 }
6507 }
6508
6509 /**
6510 * Is E-UTRA-NR Dual Connectivity enabled
6511 * @return true if dual connectivity is enabled else false
6512 */
6513 @Override
6514 public boolean isNrDualConnectivityEnabled(int subId) {
6515 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006516 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006517 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006518 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006519 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6520 return false;
6521 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006522 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6523 final long identity = Binder.clearCallingIdentity();
6524 try {
6525 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6526 null, subId, workSource);
6527 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6528 return isEnabled;
6529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
6532 }
6533
6534 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006535 * Set the allowed network types of the device and
6536 * provide the reason triggering the allowed network change.
6537 *
6538 * @param subId the id of the subscription.
6539 * @param reason the reason the allowed network type change is taking place
6540 * @param allowedNetworkTypes the allowed network types.
6541 * @return true on success; false on any failure.
6542 */
6543 @Override
6544 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006545 @TelephonyManager.AllowedNetworkTypesReason int reason,
6546 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6548 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006549 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006550 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6551 return false;
6552 }
6553 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6554 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006555 return false;
6556 }
6557
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006558 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6559 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6560
6561
6562 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6563 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6564 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006565 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006566
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006567 final long identity = Binder.clearCallingIdentity();
6568 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006569 Boolean success = (Boolean) sendRequest(
6570 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6571 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6572
6573 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6574 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006575 } finally {
6576 Binder.restoreCallingIdentity(identity);
6577 }
6578 }
6579
6580 /**
Miaoa84611c2019-03-15 09:21:10 +08006581 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006582 *
Miaoa84611c2019-03-15 09:21:10 +08006583 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006584 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006585 * @hide
6586 */
6587 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006588 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006591 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 try {
Miaoa84611c2019-03-15 09:21:10 +08006593 if (phone != null) {
6594 return phone.hasMatchedTetherApnSetting();
6595 } else {
6596 return false;
6597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 } finally {
6599 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006600 }
Junda Liu475951f2014-11-07 16:45:03 -08006601 }
6602
6603 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006604 * Get the user enabled state of Mobile Data.
6605 *
6606 * TODO: remove and use isUserDataEnabled.
6607 * This can't be removed now because some vendor codes
6608 * calls through ITelephony directly while they should
6609 * use TelephonyManager.
6610 *
6611 * @return true on enabled
6612 */
6613 @Override
6614 public boolean getDataEnabled(int subId) {
6615 return isUserDataEnabled(subId);
6616 }
6617
6618 /**
6619 * Get whether mobile data is enabled per user setting.
6620 *
6621 * There are other factors deciding whether mobile data is actually enabled, but they are
6622 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006623 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006624 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006625 *
6626 * @return {@code true} if data is enabled else {@code false}
6627 */
6628 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006629 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006630 try {
6631 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6632 null);
6633 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6635 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637
6638 final long identity = Binder.clearCallingIdentity();
6639 try {
6640 int phoneId = mSubscriptionController.getPhoneId(subId);
6641 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6642 Phone phone = PhoneFactory.getPhone(phoneId);
6643 if (phone != null) {
6644 boolean retVal = phone.isUserDataEnabled();
6645 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6646 return retVal;
6647 } else {
6648 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6649 return false;
6650 }
6651 } finally {
6652 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006653 }
6654 }
6655
6656 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006657 * Checks if the device is capable of mobile data by considering whether whether the
6658 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6659 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006660 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006661 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006662 */
6663 @Override
6664 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 try {
6666 try {
6667 mApp.enforceCallingOrSelfPermission(
6668 android.Manifest.permission.ACCESS_NETWORK_STATE,
6669 null);
6670 } catch (Exception e) {
6671 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6672 "isDataEnabled");
6673 }
6674 } catch (Exception e) {
6675 enforceReadPrivilegedPermission("isDataEnabled");
6676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 int phoneId = mSubscriptionController.getPhoneId(subId);
6681 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6682 Phone phone = PhoneFactory.getPhone(phoneId);
6683 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006684 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6686 return retVal;
6687 } else {
6688 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6689 return false;
6690 }
6691 } finally {
6692 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006693 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006694 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006695
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006696 /**
6697 * Check if data is enabled for a specific reason
6698 * @param subId Subscription index
6699 * @param reason the reason the data enable change is taking place
6700 * @return {@code true} if the overall data is enabled; {@code false} if not.
6701 */
6702 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006703 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006704 @TelephonyManager.DataEnabledReason int reason) {
6705 try {
6706 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6707 null);
6708 } catch (Exception e) {
6709 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006710 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006711 }
6712
6713
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
6716 int phoneId = mSubscriptionController.getPhoneId(subId);
6717 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006718 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006719 + " reason=" + reason);
6720 }
6721 Phone phone = PhoneFactory.getPhone(phoneId);
6722 if (phone != null) {
6723 boolean retVal;
6724 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6725 retVal = phone.isUserDataEnabled();
6726 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006727 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006728 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006729 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006730 return retVal;
6731 } else {
6732 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006733 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 + subId + " retVal=false");
6735 }
6736 return false;
6737 }
6738 } finally {
6739 Binder.restoreCallingIdentity(identity);
6740 }
6741 }
6742
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006743 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006744 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006745 if (uid == Process.PHONE_UID) {
6746 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6747 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006748 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6749 }
6750
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006751 //load access rules from carrier configs, and check those as well: b/139133814
6752 SubscriptionController subController = SubscriptionController.getInstance();
6753 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6754 || subController == null) return privilegeFromSim;
6755
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006756 PackageManager pkgMgr = phone.getContext().getPackageManager();
6757 String[] packages = pkgMgr.getPackagesForUid(uid);
6758
6759 final long identity = Binder.clearCallingIdentity();
6760 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006761 int subId = phone.getSubId();
6762 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6763 // A test override is in place for the privileges for this subId, so don't try to
6764 // read the subscription privileges.
6765 return privilegeFromSim;
6766 }
6767 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006768 SubscriptionManager subManager = (SubscriptionManager)
6769 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6770 for (String pkg : packages) {
6771 if (subManager.canManageSubscription(subInfo, pkg)) {
6772 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6773 }
6774 }
6775 return privilegeFromSim;
6776 } finally {
6777 Binder.restoreCallingIdentity(identity);
6778 }
6779 }
6780
6781 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6782 String pkgName) {
6783 //load access rules from carrier configs, and check those as well: b/139133814
6784 SubscriptionController subController = SubscriptionController.getInstance();
6785 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6786 || subController == null) return privilegeFromSim;
6787
6788 final long identity = Binder.clearCallingIdentity();
6789 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006790 int subId = phone.getSubId();
6791 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6792 // A test override is in place for the privileges for this subId, so don't try to
6793 // read the subscription privileges.
6794 return privilegeFromSim;
6795 }
6796 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006797 SubscriptionManager subManager = (SubscriptionManager)
6798 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6799 return subManager.canManageSubscription(subInfo, pkgName)
6800 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6801 } finally {
6802 Binder.restoreCallingIdentity(identity);
6803 }
6804 }
6805
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006806 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006807 public int getCarrierPrivilegeStatus(int subId) {
6808 final Phone phone = getPhone(subId);
6809 if (phone == null) {
6810 loge("getCarrierPrivilegeStatus: Invalid subId");
6811 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6812 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006813 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6814 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006815 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006816 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6817 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006818
6819 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006820 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006821 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006822 }
Junda Liu29340342014-07-10 15:23:27 -07006823
6824 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006825 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006826 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006827 final Phone phone = getPhone(subId);
6828 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006829 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006830 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6831 }
6832 UiccProfile profile =
6833 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6834 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006835 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006836 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6837 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006838 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006839 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006840 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006841 }
6842
6843 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006844 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006845 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006846 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006847 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006848 }
6849
6850 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006851 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6852 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006853 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6855 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006856 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006857 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006858 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006859 }
6860
6861 @Override
6862 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006863 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006864 if (TextUtils.isEmpty(pkgName))
6865 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006866 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6867 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006868 UiccPort port = UiccController.getInstance().getUiccPort(i);
6869 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006870 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006871 continue;
6872 }
6873
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006874 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006875 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006876 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006877 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6878 break;
6879 }
6880 }
6881
6882 return result;
Junda Liu29340342014-07-10 15:23:27 -07006883 }
Derek Tan89e89d42014-07-08 17:00:10 -07006884
6885 @Override
Junda Liue64de782015-04-16 17:19:16 -07006886 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006887 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006888 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6889 loge("phoneId " + phoneId + " is not valid.");
6890 return null;
6891 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006892 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6893 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006894 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006895 return null ;
6896 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006897 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006898 }
6899
Amith Yamasani6e118872016-02-19 12:53:51 -08006900 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006901 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006902 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006903 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006904 List<String> privilegedPackages = new ArrayList<>();
6905 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006906 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006907 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006908 if (port != null) {
6909 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006910 if (packages == null) {
6911 // Only check packages in user 0 for now
6912 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006913 PackageManager.MATCH_DISABLED_COMPONENTS
6914 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006915 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006916 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006917 }
6918 for (int p = packages.size() - 1; p >= 0; p--) {
6919 PackageInfo pkgInfo = packages.get(p);
6920 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006921 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6922 port.getCarrierPrivilegeStatus(pkgInfo),
6923 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006924 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006925 privilegedPackages.add(pkgInfo.packageName);
6926 }
6927 }
6928 }
6929 }
6930 return privilegedPackages;
6931 }
6932
chen xuf7e9fe82019-05-09 19:31:02 -07006933 @Override
6934 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006935 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6936
6937 final long identity = Binder.clearCallingIdentity();
6938
chen xuf7e9fe82019-05-09 19:31:02 -07006939 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006940 try {
6941 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6942 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6943 }
6944 } finally {
6945 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006946 }
6947 return privilegedPackages;
6948 }
6949
Wink Savilleb564aae2014-10-23 10:18:09 -07006950 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006951 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006952 UiccPort port = phone == null ? null : phone.getUiccPort();
6953 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006954 return null;
6955 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006956 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006957 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006958 return null;
6959 }
6960 return iccId;
6961 }
6962
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006963 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006964 public void setCallComposerStatus(int subId, int status) {
6965 enforceModifyPermission();
6966
6967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 Phone phone = getPhone(subId);
6970 if (phone != null) {
6971 Phone defaultPhone = phone.getImsPhone();
6972 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6973 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6974 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006975 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6976 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006977 }
6978 }
Shuo Qian284ae752020-12-22 19:10:14 -08006979 } catch (ImsException e) {
6980 throw new ServiceSpecificException(e.getCode());
6981 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006982 Binder.restoreCallingIdentity(identity);
6983 }
6984 }
6985
6986 @Override
6987 public int getCallComposerStatus(int subId) {
6988 enforceReadPrivilegedPermission("getCallComposerStatus");
6989
6990 final long identity = Binder.clearCallingIdentity();
6991 try {
6992 Phone phone = getPhone(subId);
6993 if (phone != null) {
6994 Phone defaultPhone = phone.getImsPhone();
6995 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6996 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6997 return imsPhone.getCallComposerStatus();
6998 }
6999 }
7000 } finally {
7001 Binder.restoreCallingIdentity(identity);
7002 }
7003 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7004 }
7005
7006 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007007 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7008 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007009 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007010 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 final long identity = Binder.clearCallingIdentity();
7013 try {
7014 final String iccId = getIccId(subId);
7015 final Phone phone = getPhone(subId);
7016 if (phone == null) {
7017 return false;
7018 }
7019 final String subscriberId = phone.getSubscriberId();
7020
7021 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007022 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 + subscriberId + " to " + number);
7024 }
7025
7026 if (TextUtils.isEmpty(iccId)) {
7027 return false;
7028 }
7029
7030 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7031
7032 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7033 if (alphaTag == null) {
7034 editor.remove(alphaTagPrefKey);
7035 } else {
7036 editor.putString(alphaTagPrefKey, alphaTag);
7037 }
7038
7039 // Record both the line number and IMSI for this ICCID, since we need to
7040 // track all merged IMSIs based on line number
7041 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7042 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7043 if (number == null) {
7044 editor.remove(numberPrefKey);
7045 editor.remove(subscriberPrefKey);
7046 } else {
7047 editor.putString(numberPrefKey, number);
7048 editor.putString(subscriberPrefKey, subscriberId);
7049 }
7050
7051 editor.commit();
7052 return true;
7053 } finally {
7054 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007055 }
Derek Tan7226c842014-07-02 17:42:23 -07007056 }
7057
7058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007059 public String getLine1NumberForDisplay(int subId, String callingPackage,
7060 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007061 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007063 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007064 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007065 return null;
7066 }
Derek Tan97ebb422014-09-05 16:55:38 -07007067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068 final long identity = Binder.clearCallingIdentity();
7069 try {
7070 String iccId = getIccId(subId);
7071 if (iccId != null) {
7072 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7073 if (DBG_MERGE) {
7074 log("getLine1NumberForDisplay returning "
7075 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7076 }
7077 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7080 return null;
7081 } finally {
7082 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007083 }
Derek Tan7226c842014-07-02 17:42:23 -07007084 }
7085
7086 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007087 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7088 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007090 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007091 return null;
7092 }
Derek Tan97ebb422014-09-05 16:55:38 -07007093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094 final long identity = Binder.clearCallingIdentity();
7095 try {
7096 String iccId = getIccId(subId);
7097 if (iccId != null) {
7098 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7099 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7100 }
7101 return null;
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007104 }
Derek Tan7226c842014-07-02 17:42:23 -07007105 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007106
7107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007108 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7109 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007110 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7111 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007113 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007114 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007115 return null;
7116 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007117
Jordan Liub49b04b2019-05-06 14:45:15 -07007118 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7119 // the process, where TelephonyManager was instantiated.
7120 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007121 final long identity = Binder.clearCallingIdentity();
7122 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007123 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124 final TelephonyManager tele = TelephonyManager.from(context);
7125 final SubscriptionManager sub = SubscriptionManager.from(context);
7126
7127 // Figure out what subscribers are currently active
7128 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129
Jordan Liub49b04b2019-05-06 14:45:15 -07007130 // Only consider subs which match the current subId
7131 // This logic can be simplified. See b/131189269 for progress.
7132 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007133 activeSubscriberIds.add(tele.getSubscriberId(subId));
7134 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007135
7136 // First pass, find a number override for an active subscriber
7137 String mergeNumber = null;
7138 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7139 for (String key : prefs.keySet()) {
7140 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7141 final String subscriberId = (String) prefs.get(key);
7142 if (activeSubscriberIds.contains(subscriberId)) {
7143 final String iccId = key.substring(
7144 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7145 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7146 mergeNumber = (String) prefs.get(numberKey);
7147 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007148 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 + " for active subscriber " + subscriberId);
7150 }
7151 if (!TextUtils.isEmpty(mergeNumber)) {
7152 break;
7153 }
7154 }
7155 }
7156 }
7157
7158 // Shortcut when no active merged subscribers
7159 if (TextUtils.isEmpty(mergeNumber)) {
7160 return null;
7161 }
7162
7163 // Second pass, find all subscribers under that line override
7164 final ArraySet<String> result = new ArraySet<>();
7165 for (String key : prefs.keySet()) {
7166 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7167 final String number = (String) prefs.get(key);
7168 if (mergeNumber.equals(number)) {
7169 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7170 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7171 final String subscriberId = (String) prefs.get(subscriberKey);
7172 if (!TextUtils.isEmpty(subscriberId)) {
7173 result.add(subscriberId);
7174 }
7175 }
7176 }
7177 }
7178
7179 final String[] resultArray = result.toArray(new String[result.size()]);
7180 Arrays.sort(resultArray);
7181 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007182 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7184 }
7185 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007186 } finally {
7187 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007188 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007189 }
7190
7191 @Override
zoey chen38003472019-12-13 17:16:31 +08007192 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7193 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007194
7195 final long identity = Binder.clearCallingIdentity();
7196 try {
7197 final TelephonyManager telephonyManager = mApp.getSystemService(
7198 TelephonyManager.class);
7199 String subscriberId = telephonyManager.getSubscriberId(subId);
7200 if (subscriberId == null) {
7201 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007202 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007203 + subId);
7204 }
7205 return null;
7206 }
7207
7208 final SubscriptionInfo info = SubscriptionController.getInstance()
7209 .getSubscriptionInfo(subId);
7210 final ParcelUuid groupUuid = info.getGroupUuid();
7211 // If it doesn't belong to any group, return just subscriberId of itself.
7212 if (groupUuid == null) {
7213 return new String[]{subscriberId};
7214 }
7215
7216 // Get all subscriberIds from the group.
7217 final List<String> mergedSubscriberIds = new ArrayList<>();
7218 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007219 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007220 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007221 for (SubscriptionInfo subInfo : groupInfos) {
7222 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7223 if (subscriberId != null) {
7224 mergedSubscriberIds.add(subscriberId);
7225 }
7226 }
7227
7228 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7229 } finally {
7230 Binder.restoreCallingIdentity(identity);
7231
7232 }
7233 }
7234
7235 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007236 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007237 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007238 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239
7240 final long identity = Binder.clearCallingIdentity();
7241 try {
7242 final Phone phone = getPhone(subId);
7243 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7244 } finally {
7245 Binder.restoreCallingIdentity(identity);
7246 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007247 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007248
7249 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007250 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007251 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7252 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007253 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7254 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255
7256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 final Phone phone = getPhone(subId);
7259 if (phone == null) {
7260 return false;
7261 }
7262 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7263 cdmaNonRoamingList);
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007266 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007267 }
7268
7269 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007270 @Deprecated
7271 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7272 enforceModifyPermission();
7273
7274 int returnValue = 0;
7275 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007276 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007277 if(result.exception == null) {
7278 if (result.result != null) {
7279 byte[] responseData = (byte[])(result.result);
7280 if(responseData.length > oemResp.length) {
7281 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7282 responseData.length + "bytes. Buffer Size is " +
7283 oemResp.length + "bytes.");
7284 }
7285 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7286 returnValue = responseData.length;
7287 }
7288 } else {
7289 CommandException ex = (CommandException) result.exception;
7290 returnValue = ex.getCommandError().ordinal();
7291 if(returnValue > 0) returnValue *= -1;
7292 }
7293 } catch (RuntimeException e) {
7294 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7295 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7296 if(returnValue > 0) returnValue *= -1;
7297 }
7298
7299 return returnValue;
7300 }
7301
7302 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007303 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007304 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007305 try {
7306 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007307 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007308 mApp, phone.getSubId(), "getRadioAccessFamily");
7309 } catch (SecurityException e) {
7310 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7311 throw e;
7312 }
chen xub97461a2018-10-26 14:17:57 -07007313 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007314 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007315 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 final long identity = Binder.clearCallingIdentity();
7318 try {
chen xub97461a2018-10-26 14:17:57 -07007319 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007320 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007321 mApp, phone.getSubId(), "getRadioAccessFamily");
7322 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
chen xub97461a2018-10-26 14:17:57 -07007326 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007327 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007328
7329 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007330 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007331 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007332 try {
7333 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7334 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007335 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007336 }
7337 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007338 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007339 }
7340 RoleManager rm = mApp.getSystemService(RoleManager.class);
7341 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7342 if (!dialerRoleHolders.contains(callingPackage)) {
7343 throw new SecurityException("App must be the dialer role holder to"
7344 + " upload a call composer pic");
7345 }
7346
7347 Executors.newSingleThreadExecutor().execute(() -> {
7348 ByteArrayOutputStream output = new ByteArrayOutputStream(
7349 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7350 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7351 boolean readUntilEnd = false;
7352 int totalBytesRead = 0;
7353 byte[] buffer = new byte[16 * 1024];
7354 while (true) {
7355 int numRead;
7356 try {
7357 numRead = input.read(buffer);
7358 } catch (IOException e) {
7359 try {
7360 fd.checkError();
7361 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7362 null);
7363 } catch (IOException e1) {
7364 // This means that the other side closed explicitly with an error. If this
7365 // happens, log and ignore.
7366 loge("Remote end of call composer picture pipe closed: " + e1);
7367 }
7368 break;
7369 }
7370 if (numRead == -1) {
7371 readUntilEnd = true;
7372 break;
7373 }
7374 totalBytesRead += numRead;
7375 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7376 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7377 try {
7378 input.close();
7379 } catch (IOException e) {
7380 // ignore
7381 }
7382 break;
7383 }
7384 output.write(buffer, 0, numRead);
7385 }
7386 // Generally, the remote end will close the file descriptors. The only case where we
7387 // close is above, where the picture size is too big.
7388
7389 try {
7390 fd.checkError();
7391 } catch (IOException e) {
7392 loge("Remote end for call composer closed with an error: " + e);
7393 return;
7394 }
7395
Hall Liuaa4211e2021-01-20 15:43:39 -08007396 if (!readUntilEnd) {
7397 loge("Did not finish reading entire image; aborting");
7398 return;
7399 }
Hall Liu82694d52020-12-11 18:22:04 -08007400
Hall Liuaa4211e2021-01-20 15:43:39 -08007401 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7402 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7403 new CallComposerPictureTransfer.Factory() {},
7404 imageData,
7405 (result) -> {
7406 if (result.first != null) {
7407 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7408 Bundle outputResult = new Bundle();
7409 outputResult.putParcelable(
7410 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7411 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7412 outputResult);
7413 } else {
7414 callback.send(result.second, null);
7415 }
7416 }
7417 );
Hall Liu82694d52020-12-11 18:22:04 -08007418 });
7419 }
7420
7421 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007422 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007423 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007424 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425
7426 final long identity = Binder.clearCallingIdentity();
7427 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007428 ImsManager.getInstance(defaultPhone.getContext(),
7429 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 } finally {
7431 Binder.restoreCallingIdentity(identity);
7432 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007433 }
7434
7435 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007436 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007437 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7439 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007440 return false;
7441 }
Svet Ganovb320e182015-04-16 12:30:10 -07007442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 final long identity = Binder.clearCallingIdentity();
7444 try {
7445 // Check the user preference and the system-level IMS setting. Even if the user has
7446 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7447 // In the long run, we may instead need to check if there exists a connection service
7448 // which can support video calling.
7449 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007450 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 return imsManager.isVtEnabledByPlatform()
7452 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7453 && imsManager.isVtEnabledByUser();
7454 } finally {
7455 Binder.restoreCallingIdentity(identity);
7456 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007457 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007458
Andrew Leea1239f22015-03-02 17:44:07 -08007459 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007460 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7461 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007463 mApp, subId, callingPackage, callingFeatureId,
7464 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 return false;
7466 }
7467
7468 final long identity = Binder.clearCallingIdentity();
7469 try {
7470 CarrierConfigManager configManager =
7471 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007472 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7474 } finally {
7475 Binder.restoreCallingIdentity(identity);
7476 }
Andrew Leea1239f22015-03-02 17:44:07 -08007477 }
7478
7479 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007480 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007482 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 return false;
7484 }
7485
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
7488 CarrierConfigManager configManager =
7489 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007490 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Andrew Leea1239f22015-03-02 17:44:07 -08007495 }
7496
Andrew Lee9431b832015-03-09 18:46:45 -07007497 @Override
7498 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007499 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007500 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007501 }
7502
7503 @Override
7504 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505 final long identity = Binder.clearCallingIdentity();
7506 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007507 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
Andrew Lee9431b832015-03-09 18:46:45 -07007511 }
7512
Hall Liuf6668912018-10-31 17:05:23 -07007513 /**
7514 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7515 * support for the feature and device firmware support.
7516 *
7517 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7518 */
7519 @Override
7520 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007522 final Phone phone = getPhone(subscriptionId);
7523 if (phone == null) {
7524 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7525 return false;
7526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007528 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7530 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007531 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 return isCarrierSupported && isDeviceSupported;
7533 } finally {
7534 Binder.restoreCallingIdentity(identity);
7535 }
Hall Liu98187582018-01-22 19:15:32 -08007536 }
7537
Hall Liuf6668912018-10-31 17:05:23 -07007538 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007539 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7540 * RTT setting, will return true if the device and carrier both support RTT.
7541 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007542 */
7543 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 final long identity = Binder.clearCallingIdentity();
7545 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007546 boolean isRttSupported = isRttSupported(subscriptionId);
7547 boolean isUserRttSettingOn = Settings.Secure.getInt(
7548 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7549 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7550 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7551 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 } finally {
7553 Binder.restoreCallingIdentity(identity);
7554 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007555 }
7556
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007557 @Deprecated
7558 @Override
7559 public String getDeviceId(String callingPackage) {
7560 return getDeviceIdWithFeature(callingPackage, null);
7561 }
7562
Sanket Padawe7310cc72015-01-14 09:53:20 -08007563 /**
7564 * Returns the unique device ID of phone, for example, the IMEI for
7565 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7566 *
7567 * <p>Requires Permission:
7568 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7569 */
7570 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007571 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007572 try {
7573 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7574 } catch (SecurityException se) {
7575 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7576 throw new SecurityException("Package " + callingPackage + " does not belong to "
7577 + Binder.getCallingUid());
7578 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007579 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007580 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007581 return null;
7582 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007583 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007584 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007585 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007586 return null;
7587 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007588
7589 final long identity = Binder.clearCallingIdentity();
7590 try {
7591 return phone.getDeviceId();
7592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007595 }
7596
Ping Sunc67b7c22016-03-02 19:16:45 +08007597 /**
7598 * {@hide}
7599 * Returns the IMS Registration Status on a particular subid
7600 *
7601 * @param subId
7602 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007603 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007604 Phone phone = getPhone(subId);
7605 if (phone != null) {
7606 return phone.isImsRegistered();
7607 } else {
7608 return false;
7609 }
7610 }
7611
Santos Cordon7a1885b2015-02-03 11:15:19 -08007612 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007613 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007614 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007616 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007617 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7618 }
7619 final long identity = Binder.clearCallingIdentity();
7620 try {
7621 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7622 } finally {
7623 Binder.restoreCallingIdentity(identity);
7624 }
7625 }
7626
7627 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007628 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007629 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007630 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007631 mApp,
7632 subscriptionId,
7633 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007634 final long identity = Binder.clearCallingIdentity();
7635 try {
7636 Phone phone = getPhone(subscriptionId);
7637 if (phone == null) {
7638 return null;
7639 }
7640 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7641 } finally {
7642 Binder.restoreCallingIdentity(identity);
7643 }
7644 }
7645
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007646 /**
7647 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007648 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007649 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 Phone phone = getPhone(subId);
7653 if (phone != null) {
7654 return phone.isWifiCallingEnabled();
7655 } else {
7656 return false;
7657 }
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007660 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007661 }
7662
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007663 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007664 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007665 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007666 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 final long identity = Binder.clearCallingIdentity();
7668 try {
7669 Phone phone = getPhone(subId);
7670 if (phone != null) {
7671 return phone.isVideoEnabled();
7672 } else {
7673 return false;
7674 }
7675 } finally {
7676 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007677 }
7678 }
7679
7680 /**
7681 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7682 * defined in {@link ImsRegistrationImplBase}.
7683 */
7684 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 final long identity = Binder.clearCallingIdentity();
7686 try {
7687 Phone phone = getPhone(subId);
7688 if (phone != null) {
7689 return phone.getImsRegistrationTech();
7690 } else {
7691 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7692 }
7693 } finally {
7694 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007695 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007696 }
7697
Stuart Scott8eef64f2015-04-08 15:13:54 -07007698 @Override
7699 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007700 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007701 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7702 return;
7703 }
Kai Shif70f46f2021-03-03 13:59:46 -08007704 Phone defaultPhone = getDefaultPhone();
7705 if (defaultPhone != null) {
7706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7707 mApp, getDefaultPhone().getSubId(), "factoryReset");
7708 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007709 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007710
Svet Ganovcc087f82015-05-12 20:35:54 -07007711 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007712 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7713 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007714 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007715 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007716 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007717 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007718 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007719 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007720 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007721 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007722 // There has been issues when Sms raw table somehow stores orphan
7723 // fragments. They lead to garbled message when new fragments come
7724 // in and combined with those stale ones. In case this happens again,
7725 // user can reset all network settings which will clean up this table.
7726 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007727 // Clean up IMS settings as well here.
7728 int slotId = getSlotIndex(subId);
7729 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7730 ImsManager.getInstance(mApp, slotId).factoryReset();
7731 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007732
Kai Shif70f46f2021-03-03 13:59:46 -08007733 if (defaultPhone == null) {
7734 return;
7735 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007736 // Erase modem config if erase modem on network setting is enabled.
7737 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7738 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7739 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007740 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007741 }
Kai Shif70f46f2021-03-03 13:59:46 -08007742
7743 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007744 } finally {
7745 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007746 }
7747 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007748
SongFerngWangfd89b102021-05-27 22:44:54 +08007749 @VisibleForTesting
7750 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7751 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7752 return;
7753 }
7754 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7755 RILConstants.PREFERRED_NETWORK_MODE);
7756 SubscriptionManager.setSubscriptionProperty(subId,
7757 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7758 "user=" + defaultNetworkType);
7759 phone.loadAllowedNetworksFromSubscriptionDatabase();
7760 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7761 defaultNetworkType, null);
7762 }
7763
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007764 private void cleanUpSmsRawTable(Context context) {
7765 ContentResolver resolver = context.getContentResolver();
7766 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7767 resolver.delete(uri, null, null);
7768 }
7769
Narayan Kamath1c496c22015-04-16 14:40:19 +01007770 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007771 public String getSimLocaleForSubscriber(int subId) {
7772 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7773 final Phone phone = getPhone(subId);
7774 if (phone == null) {
7775 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007776 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007777 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 final long identity = Binder.clearCallingIdentity();
7779 try {
chen xu5d3637b2019-01-21 23:31:38 -08007780 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007781 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007782 if (info == null) {
7783 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7784 return null;
7785 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 // Try and fetch the locale from the carrier properties or from the SIM language
7787 // preferences (EF-PL and EF-LI)...
7788 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007790 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7791 if (localeFromDefaultSim != null) {
7792 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7793 if (DBG) log("Using locale from subId: " + subId + " locale: "
7794 + localeFromDefaultSim);
7795 return localeFromDefaultSim.toLanguageTag();
7796 } else {
7797 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798 }
7799 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 // The SIM language preferences only store a language (e.g. fr = French), not an
7802 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7803 // the SIM and carrier preferences does not include a country we add the country
7804 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007805 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007807 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 return mccLocale.toLanguageTag();
7809 }
7810
7811 if (DBG) log("No locale found - returning null");
7812 return null;
7813 } finally {
7814 Binder.restoreCallingIdentity(identity);
7815 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007816 }
7817
7818 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007819 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007820 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007821 }
7822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 /**
7824 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7825 */
7826 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007827 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007828 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007829 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007830
Chenjie Yu1ba97252018-01-11 18:16:20 -08007831 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007832 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007833
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007834 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007835 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7836 * representing the state of the modem.
7837 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007838 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7839 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007840 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007841 */
7842 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007843 public void requestModemActivityInfo(ResultReceiver result) {
7844 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007845 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846
7847 final long identity = Binder.clearCallingIdentity();
7848 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007849 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 } finally {
7851 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007852 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007853 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007854
Siddharth Rayb8114062018-06-17 15:02:38 -07007855 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7856 // less than total activity duration.
7857 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7858 if (info == null) {
7859 return false;
7860 }
7861 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007862 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7863 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7864
Siddharth Rayb8114062018-06-17 15:02:38 -07007865 return (info.isValid()
7866 && (info.getSleepTimeMillis() <= activityDurationMs)
7867 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007868 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007869 && (totalTxTimeMs <= activityDurationMs));
7870 }
7871
Jack Yu85bd38a2015-11-09 11:34:32 -08007872 /**
7873 * {@hide}
7874 * Returns the service state information on specified subscription.
7875 */
7876 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007877 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7878 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007880 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007881 return null;
7882 }
7883
Hall Liuf19c44f2018-11-27 14:38:17 -08007884 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7885 LocationAccessPolicy.checkLocationPermission(mApp,
7886 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7887 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007888 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007889 .setCallingPid(Binder.getCallingPid())
7890 .setCallingUid(Binder.getCallingUid())
7891 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007892 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007893 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007894 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7895 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007896 .build());
7897
7898 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7899 LocationAccessPolicy.checkLocationPermission(mApp,
7900 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7901 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007902 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007903 .setCallingPid(Binder.getCallingPid())
7904 .setCallingUid(Binder.getCallingUid())
7905 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007906 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007907 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007908 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7909 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007910 .build());
7911 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7912 boolean hasFinePermission =
7913 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7914 boolean hasCoarsePermission =
7915 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7916
Jack Yu479f40e2020-10-27 21:29:25 -07007917 final Phone phone = getPhone(subId);
7918 if (phone == null) {
7919 return null;
7920 }
7921
Jordan Liu0f2bc442020-11-18 16:47:37 -08007922 final long identity = Binder.clearCallingIdentity();
7923
Jack Yu479f40e2020-10-27 21:29:25 -07007924 boolean isCallingPackageDataService = phone.getDataServicePackages()
7925 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007927 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7928 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7929 Rlog.d(LOG_TAG,
7930 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7931 return null;
7932 }
7933
Hall Liuf19c44f2018-11-27 14:38:17 -08007934 ServiceState ss = phone.getServiceState();
7935
7936 // Scrub out the location info in ServiceState depending on what level of access
7937 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007938 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007939 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7940 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007941 } finally {
7942 Binder.restoreCallingIdentity(identity);
7943 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007944 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007945
7946 /**
7947 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7948 *
7949 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7950 * voicemail ringtone.
7951 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7952 * PhoneAccount.
7953 */
7954 @Override
7955 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956 final long identity = Binder.clearCallingIdentity();
7957 try {
7958 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7959 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007960 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7964 } finally {
7965 Binder.restoreCallingIdentity(identity);
7966 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007967 }
7968
7969 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007970 * Sets the per-account voicemail ringtone.
7971 *
7972 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7973 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7974 *
7975 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7976 * voicemail ringtone.
7977 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7978 * PhoneAccount.
7979 */
7980 @Override
7981 public void setVoicemailRingtoneUri(String callingPackage,
7982 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007983 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007985 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7986 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7988 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7989 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007991
7992 final long identity = Binder.clearCallingIdentity();
7993 try {
7994 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7995 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007996 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 }
7998 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7999 } finally {
8000 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008002 }
8003
8004 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008005 * Returns whether vibration is set for voicemail notification in Phone settings.
8006 *
8007 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8008 * voicemail vibration setting.
8009 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8010 */
8011 @Override
8012 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 final long identity = Binder.clearCallingIdentity();
8014 try {
8015 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8016 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008017 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8021 } finally {
8022 Binder.restoreCallingIdentity(identity);
8023 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008024 }
8025
Youhan Wange64578a2016-05-02 15:32:42 -07008026 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008027 * Sets the per-account voicemail vibration.
8028 *
8029 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8030 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8031 *
8032 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8033 * voicemail vibration setting.
8034 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8035 * specific PhoneAccount.
8036 */
8037 @Override
8038 public void setVoicemailVibrationEnabled(String callingPackage,
8039 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008040 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008042 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8043 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8045 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8046 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008047 }
8048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 final long identity = Binder.clearCallingIdentity();
8050 try {
8051 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8052 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008053 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 }
8055 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008058 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008059 }
8060
8061 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008062 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8063 *
8064 * @throws SecurityException if the caller does not have the required permission
8065 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008066 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008067 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008068 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008069 }
8070
8071 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008072 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8073 * permission.
8074 *
8075 * @throws SecurityException if the caller does not have the required permission
8076 */
8077 private void enforceSendSmsPermission() {
8078 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8079 }
8080
8081 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008082 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008083 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008084 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008085 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008086 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 final long identity = Binder.clearCallingIdentity();
8088 try {
8089 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008090 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 if (componentName == null) {
8092 throw new SecurityException(
8093 "Caller not current active visual voicemail package[null]");
8094 }
8095 String vvmPackage = componentName.getPackageName();
8096 if (!callingPackage.equals(vvmPackage)) {
8097 throw new SecurityException("Caller not current active visual voicemail package["
8098 + vvmPackage + "]");
8099 }
8100 } finally {
8101 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008102 }
8103 }
8104
8105 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008106 * Return the application ID for the app type.
8107 *
8108 * @param subId the subscription ID that this request applies to.
8109 * @param appType the uicc app type.
8110 * @return Application ID for specificied app type, or null if no uicc.
8111 */
8112 @Override
8113 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008114 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008115 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008116
8117 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008118 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119 if (phone == null) {
8120 return null;
8121 }
8122 String aid = null;
8123 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008124 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 .getApplicationByType(appType).getAid();
8126 } catch (Exception e) {
8127 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8128 }
8129 return aid;
8130 } finally {
8131 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008132 }
Youhan Wange64578a2016-05-02 15:32:42 -07008133 }
8134
Youhan Wang4001d252016-05-11 10:29:41 -07008135 /**
8136 * Return the Electronic Serial Number.
8137 *
8138 * @param subId the subscription ID that this request applies to.
8139 * @return ESN or null if error.
8140 */
8141 @Override
8142 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008143 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008144 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008145
8146 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008147 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148 if (phone == null) {
8149 return null;
8150 }
8151 String esn = null;
8152 try {
8153 esn = phone.getEsn();
8154 } catch (Exception e) {
8155 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8156 }
8157 return esn;
8158 } finally {
8159 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008160 }
Youhan Wang4001d252016-05-11 10:29:41 -07008161 }
8162
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008163 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008164 * Return the Preferred Roaming List Version.
8165 *
8166 * @param subId the subscription ID that this request applies to.
8167 * @return PRLVersion or null if error.
8168 */
8169 @Override
8170 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008171 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008172 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173
8174 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008175 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008176 if (phone == null) {
8177 return null;
8178 }
8179 String cdmaPrlVersion = null;
8180 try {
8181 cdmaPrlVersion = phone.getCdmaPrlVersion();
8182 } catch (Exception e) {
8183 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8184 }
8185 return cdmaPrlVersion;
8186 } finally {
8187 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008188 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008189 }
8190
8191 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008192 * Get snapshot of Telephony histograms
8193 * @return List of Telephony histograms
8194 * @hide
8195 */
8196 @Override
8197 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8199 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200
8201 final long identity = Binder.clearCallingIdentity();
8202 try {
8203 return RIL.getTelephonyRILTimingHistograms();
8204 } finally {
8205 Binder.restoreCallingIdentity(identity);
8206 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008207 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008208
8209 /**
8210 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008211 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8212 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008213 * Require system privileges. In the future we may add this to carrier APIs.
8214 *
Michele Berionne482f8202018-11-27 18:57:59 -08008215 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008216 */
8217 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008218 @TelephonyManager.SetCarrierRestrictionResult
8219 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008220 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008221 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008222
Michele Berionne482f8202018-11-27 18:57:59 -08008223 if (carrierRestrictionRules == null) {
8224 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008225 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008227 final long identity = Binder.clearCallingIdentity();
8228 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008229 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008230 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008231 } finally {
8232 Binder.restoreCallingIdentity(identity);
8233 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008234 }
8235
8236 /**
8237 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008238 * Get the allowed carrier list and the excluded carrier list, including the priority between
8239 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008240 * Require system privileges. In the future we may add this to carrier APIs.
8241 *
Michele Berionne482f8202018-11-27 18:57:59 -08008242 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008243 */
8244 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008245 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008246 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008247 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248
8249 final long identity = Binder.clearCallingIdentity();
8250 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008251 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8252 if (response instanceof CarrierRestrictionRules) {
8253 return (CarrierRestrictionRules) response;
8254 }
8255 // Response is an Exception of some kind,
8256 // which is signalled to the user as a NULL retval
8257 return null;
8258 } catch (Exception e) {
8259 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8260 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 } finally {
8262 Binder.restoreCallingIdentity(identity);
8263 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008264 }
8265
fionaxu59545b42016-05-25 15:53:37 -07008266 /**
fionaxu59545b42016-05-25 15:53:37 -07008267 * Action set from carrier signalling broadcast receivers to enable/disable radio
8268 * @param subId the subscription ID that this action applies to.
8269 * @param enabled control enable or disable radio.
8270 * {@hide}
8271 */
8272 @Override
8273 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8274 enforceModifyPermission();
8275 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276
8277 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008278 if (phone == null) {
8279 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8280 return;
8281 }
8282 try {
8283 phone.carrierActionSetRadioEnabled(enabled);
8284 } catch (Exception e) {
8285 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 } finally {
8287 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008288 }
8289 }
8290
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008291 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008292 * Enable or disable Voice over NR (VoNR)
8293 * @param subId the subscription ID that this action applies to.
8294 * @param enabled enable or disable VoNR.
8295 * @return operation result.
8296 */
8297 @Override
8298 public int setVoNrEnabled(int subId, boolean enabled) {
8299 enforceModifyPermission();
8300 final Phone phone = getPhone(subId);
8301
8302 final long identity = Binder.clearCallingIdentity();
8303 if (phone == null) {
8304 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8305 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8306 }
8307
8308 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8309 try {
8310 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8311 workSource);
8312 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008313
8314 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8315 if (DBG) {
8316 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8317 }
8318 SubscriptionManager.setSubscriptionProperty(
8319 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8320 (enabled ? "1" : "0"));
8321 }
8322
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008323 return result;
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
8327 }
8328
8329 /**
8330 * Is voice over NR enabled
8331 * @return true if VoNR is enabled else false
8332 */
8333 @Override
8334 public boolean isVoNrEnabled(int subId) {
8335 enforceReadPrivilegedPermission("isVoNrEnabled");
8336 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8337 final long identity = Binder.clearCallingIdentity();
8338 try {
8339 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8340 null, subId, workSource);
8341 if (DBG) log("isVoNrEnabled: " + isEnabled);
8342 return isEnabled;
8343 } finally {
8344 Binder.restoreCallingIdentity(identity);
8345 }
8346 }
8347
8348 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008349 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8350 * network status based on which carrier apps could apply actions accordingly,
8351 * enable/disable default url handler for example.
8352 *
8353 * @param subId the subscription ID that this action applies to.
8354 * @param report control start/stop reporting the default network status.
8355 * {@hide}
8356 */
8357 @Override
8358 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8359 enforceModifyPermission();
8360 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361
8362 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008363 if (phone == null) {
8364 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8365 return;
8366 }
8367 try {
8368 phone.carrierActionReportDefaultNetworkStatus(report);
8369 } catch (Exception e) {
8370 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371 } finally {
8372 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008373 }
8374 }
8375
8376 /**
fionaxud9622282017-07-17 17:51:30 -07008377 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8378 * @param subId the subscription ID that this action applies to.
8379 * {@hide}
8380 */
8381 @Override
8382 public void carrierActionResetAll(int subId) {
8383 enforceModifyPermission();
8384 final Phone phone = getPhone(subId);
8385 if (phone == null) {
8386 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8387 return;
8388 }
8389 try {
8390 phone.carrierActionResetAll();
8391 } catch (Exception e) {
8392 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8393 }
8394 }
8395
8396 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008397 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8398 * bug report is being generated.
8399 */
8400 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008401 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008402 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8403 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008404 writer.println("Permission Denial: can't dump Phone from pid="
8405 + Binder.getCallingPid()
8406 + ", uid=" + Binder.getCallingUid()
8407 + "without permission "
8408 + android.Manifest.permission.DUMP);
8409 return;
8410 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008411 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008412 }
Jack Yueb89b242016-06-22 13:27:47 -07008413
Brad Ebingerdac2f002018-04-03 15:17:52 -07008414 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008415 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8416 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8417 @NonNull String[] args) {
8418 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8419 this, in.getFileDescriptor(), out.getFileDescriptor(),
8420 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008421 }
8422
Jack Yueb89b242016-06-22 13:27:47 -07008423 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008424 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008425 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008426 * @param reason the reason the data enable change is taking place
8427 * @param enabled True if enabling the data, otherwise disabling.
8428 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008429 */
8430 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008431 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008432 boolean enabled) {
8433 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8434 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8435 try {
8436 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008437 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008438 } catch (SecurityException se) {
8439 enforceModifyPermission();
8440 }
8441 } else {
8442 enforceModifyPermission();
8443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444
8445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 Phone phone = getPhone(subId);
8448 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008449 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8450 phone.carrierActionSetMeteredApnsEnabled(enabled);
8451 } else {
8452 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008454 }
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008457 }
8458 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008459
8460 /**
8461 * Get Client request stats
8462 * @return List of Client Request Stats
8463 * @hide
8464 */
8465 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008466 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8467 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008469 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008470 return null;
8471 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008472 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008474 final long identity = Binder.clearCallingIdentity();
8475 try {
8476 if (phone != null) {
8477 return phone.getClientRequestStats();
8478 }
8479
8480 return null;
8481 } finally {
8482 Binder.restoreCallingIdentity(identity);
8483 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008484 }
8485
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008486 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008487 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008488 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008489 }
Jack Yueb4124c2017-02-16 15:32:43 -08008490
8491 /**
Grace Chen70990072017-03-24 17:21:30 -07008492 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008493 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008494 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008495 * @param state State of SIM (power down, power up, pass through)
8496 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8497 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8498 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008499 *
8500 **/
8501 @Override
Grace Chen70990072017-03-24 17:21:30 -07008502 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008503 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008504 Phone phone = PhoneFactory.getPhone(slotIndex);
8505
vagdeviaf9a5b92018-08-15 16:01:53 -07008506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508 final long identity = Binder.clearCallingIdentity();
8509 try {
8510 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008511 phone.setSimPowerState(state, null, workSource);
8512 }
8513 } finally {
8514 Binder.restoreCallingIdentity(identity);
8515 }
8516 }
8517
8518 /**
8519 * Set SIM card power state.
8520 *
8521 * @param slotIndex SIM slot id.
8522 * @param state State of SIM (power down, power up, pass through)
8523 * @param callback callback to trigger after success or failure
8524 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8525 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8526 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8527 *
8528 **/
8529 @Override
8530 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8531 IIntegerConsumer callback) {
8532 enforceModifyPermission();
8533 Phone phone = PhoneFactory.getPhone(slotIndex);
8534
8535 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8536
8537 final long identity = Binder.clearCallingIdentity();
8538 try {
8539 if (phone != null) {
8540 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8541 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008542 }
8543 } finally {
8544 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008545 }
8546 }
Shuo Qiandd210312017-04-12 22:11:33 +00008547
Tyler Gunn65d45c22017-06-05 11:22:26 -07008548 private boolean isUssdApiAllowed(int subId) {
8549 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008550 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008551 if (configManager == null) {
8552 return false;
8553 }
8554 PersistableBundle pb = configManager.getConfigForSubId(subId);
8555 if (pb == null) {
8556 return false;
8557 }
8558 return pb.getBoolean(
8559 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8560 }
8561
Shuo Qiandd210312017-04-12 22:11:33 +00008562 /**
8563 * Check if phone is in emergency callback mode
8564 * @return true if phone is in emergency callback mode
8565 * @param subId sub id
8566 */
goneil9c5f4872017-12-05 14:07:56 -08008567 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008568 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008569 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008570 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571
8572 final long identity = Binder.clearCallingIdentity();
8573 try {
8574 if (phone != null) {
8575 return phone.isInEcm();
8576 } else {
8577 return false;
8578 }
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008581 }
8582 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008583
8584 /**
8585 * Get the current signal strength information for the given subscription.
8586 * Because this information is not updated when the device is in a low power state
8587 * it should not be relied-upon to be current.
8588 * @param subId Subscription index
8589 * @return the most recent cached signal strength info from the modem
8590 */
8591 @Override
8592 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 final long identity = Binder.clearCallingIdentity();
8594 try {
8595 Phone p = getPhone(subId);
8596 if (p == null) {
8597 return null;
8598 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600 return p.getSignalStrength();
8601 } finally {
8602 Binder.restoreCallingIdentity(identity);
8603 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008604 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008605
Pengquan Meng77b7f132018-08-22 14:49:57 -07008606 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008607 * Get the current modem radio state for the given slot.
8608 * @param slotIndex slot index.
8609 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008610 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008611 * @return the current radio power state from the modem
8612 */
8613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008614 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008615 Phone phone = PhoneFactory.getPhone(slotIndex);
8616 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8618 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008619 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8620 }
8621
8622 final long identity = Binder.clearCallingIdentity();
8623 try {
8624 return phone.getRadioPowerState();
8625 } finally {
8626 Binder.restoreCallingIdentity(identity);
8627 }
8628 }
8629 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8630 }
8631
8632 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008633 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8634 *
8635 * <p>Requires one of the following permissions:
8636 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8637 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8638 * privileges.
8639 *
8640 * @param subId subscription id
8641 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8642 * {@code false}.
8643 */
8644 @Override
8645 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008646 try {
8647 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8648 null);
8649 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008650 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008651 mApp, subId, "isDataRoamingEnabled");
8652 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008653
Pengquan Menga1bb6272018-09-06 09:59:22 -07008654 boolean isEnabled = false;
8655 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008656 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008657 Phone phone = getPhone(subId);
8658 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008659 } finally {
8660 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008661 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008662 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008663 }
8664
8665
8666 /**
8667 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8668 *
8669 * <p> Requires permission:
8670 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8671 * privileges.
8672 *
8673 * @param subId subscription id
8674 * @param isEnabled {@code true} means enable, {@code false} means disable.
8675 */
8676 @Override
8677 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8679 mApp, subId, "setDataRoamingEnabled");
8680
Pengquan Menga1bb6272018-09-06 09:59:22 -07008681 final long identity = Binder.clearCallingIdentity();
8682 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008683 Phone phone = getPhone(subId);
8684 if (phone != null) {
8685 phone.setDataRoamingEnabled(isEnabled);
8686 }
8687 } finally {
8688 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008689 }
8690 }
8691
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008692 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008693 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008694 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008695 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008696 mApp, subId, "isManualNetworkSelectionAllowed");
8697
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008698 boolean isAllowed = true;
8699 final long identity = Binder.clearCallingIdentity();
8700 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008701 Phone phone = getPhone(subId);
8702 if (phone != null) {
8703 isAllowed = phone.isCspPlmnEnabled();
8704 }
8705 } finally {
8706 Binder.restoreCallingIdentity(identity);
8707 }
8708 return isAllowed;
8709 }
8710
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008711 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8712 UiccProfile profile = port.getUiccProfile();
8713 if (profile == null ||
8714 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8715 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8716 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008717 }
8718 return true;
8719 }
8720
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008721 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008722 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008723 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008724 mApp.getSystemService(AppOpsManager.class)
8725 .checkPackage(Binder.getCallingUid(), callingPackage);
8726
Jordan Liu1e142fc2019-04-22 15:10:43 -07008727 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008728 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008729 try {
8730 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008731 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008732 } catch (SecurityException e) {
8733 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8734 // has carrier privileges on an active UICC
8735 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8736 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008737 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008738 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008739 }
sandeepjsb6c87872021-09-27 15:34:44 +00008740 // checking compatibility, if calling app's target SDK is T and beyond.
8741 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8742 Binder.getCallingUid())) {
8743 isIccIdAccessRestricted = true;
8744 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008745 final long identity = Binder.clearCallingIdentity();
8746 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008747 UiccController uiccController = UiccController.getInstance();
8748 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008749 if (hasReadPermission) {
8750 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008751 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008752
8753 // Remove private info if the caller doesn't have access
8754 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8755 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008756 //setting the value after compatibility check
8757 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008758 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8759 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008760 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008761 if (card == null) {
8762 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008763 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008764 continue;
8765 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008766 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8767 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008768 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008769 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008770 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008771 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8772 for (UiccPortInfo portInfo : portInfos) {
8773 UiccPort port = uiccController.getUiccPortForSlot(
8774 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8775 if (port == null) {
8776 // assume no access if port is null
8777 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8778 continue;
8779 }
8780 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8781 uiccPortInfos.add(portInfo);
8782 } else {
8783 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8784 }
8785 }
8786 filteredInfos.add(new UiccCardInfo(
8787 cardInfo.isEuicc(),
8788 cardInfo.getCardId(),
8789 null,
8790 cardInfo.getPhysicalSlotIndex(),
8791 cardInfo.isRemovable(),
8792 cardInfo.isMultipleEnabledProfilesSupported(),
8793 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008794 }
8795 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008796 } finally {
8797 Binder.restoreCallingIdentity(identity);
8798 }
8799 }
8800
sandeepjsb6c87872021-09-27 15:34:44 +00008801 /**
8802 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8803 * generally private and require carrier privileges to view.
8804 *
8805 * @hide
8806 */
8807 @NonNull
8808 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8809 List<UiccPortInfo> portinfo = new ArrayList<>();
8810 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8811 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8812 }
8813 return new UiccCardInfo(
8814 cardInfo.isEuicc(),
8815 cardInfo.getCardId(),
8816 null,
8817 cardInfo.getPhysicalSlotIndex(),
8818 cardInfo.isRemovable(),
8819 cardInfo.isMultipleEnabledProfilesSupported(),
8820 portinfo
8821 );
8822 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008823
sandeepjsb6c87872021-09-27 15:34:44 +00008824 /**
8825 * @hide
8826 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8827 * These values are generally private and require carrier privileges to view.
8828 */
8829 @NonNull
8830 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8831 return new UiccPortInfo(
8832 UiccPortInfo.ICCID_REDACTED,
8833 portInfo.getPortIndex(),
8834 portInfo.getLogicalSlotIndex(),
8835 portInfo.isActive()
8836 );
8837 }
8838 @Override
8839 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008840 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008841 mApp.getSystemService(AppOpsManager.class)
8842 .checkPackage(Binder.getCallingUid(), callingPackage);
8843
8844 boolean hasReadPermission = false;
8845 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008846
8847 try {
8848 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8849 hasReadPermission = true;
8850 } catch (SecurityException e) {
8851 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8852 // has carrier privileges on an active UICC
8853 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8854 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8855 hasReadPermission = true;
8856 }
8857 }
8858
8859 // checking compatibility, if calling app's target SDK is T and beyond.
8860 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8861 Binder.getCallingUid())) {
8862 isLogicalSlotAccessRestricted = true;
8863 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008864 final long identity = Binder.clearCallingIdentity();
8865 try {
8866 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8867 if (slots == null) {
8868 Rlog.i(LOG_TAG, "slots is null.");
8869 return null;
8870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008871 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8872 for (int i = 0; i < slots.length; i++) {
8873 UiccSlot slot = slots[i];
8874 if (slot == null) {
8875 continue;
8876 }
8877
Jordan Liu7be7e652019-05-06 18:55:02 +00008878 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008879 UiccCard card = slot.getUiccCard();
8880 if (card != null) {
8881 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008882 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008883 cardId = slot.getEid();
8884 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008885 // If cardId is null, use iccId of default port as cardId. Check if has
8886 // read permission otherwise set to null.(card is null which means no
8887 // carrier permission)
8888 cardId = hasReadPermission ? slot.getIccId(
8889 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008891 }
8892
Jordan Liu857451f2019-05-09 16:35:35 -07008893 if (cardId != null) {
8894 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8895 // if cardId is an EID, it's all digits so this is fine
8896 cardId = IccUtils.stripTrailingFs(cardId);
8897 }
8898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 int cardState = 0;
8900 switch (slot.getCardState()) {
8901 case CARDSTATE_ABSENT:
8902 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8903 break;
8904 case CARDSTATE_PRESENT:
8905 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8906 break;
8907 case CARDSTATE_ERROR:
8908 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8909 break;
8910 case CARDSTATE_RESTRICTED:
8911 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8912 break;
8913 default:
8914 break;
8915
8916 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008917 List<UiccPortInfo> portInfos = new ArrayList<>();
8918 int[] portIndexes = slot.getPortList();
8919 for (int portIdx : portIndexes) {
8920 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8921 callingPackage, hasReadPermission));
8922 if (slot.isPortActive(portIdx)) {
8923 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8924 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8925 port.getPhoneId(), true));
8926 } else {
8927 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8928 }
8929 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008930 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008931 slot.isEuicc(),
8932 cardId,
8933 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008934 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008935 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008936 //setting the value after compatibility check
8937 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008938 }
8939 return infos;
8940 } finally {
8941 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008942 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008943 }
8944
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008945 /* Returns null if doesn't have read permission or carrier privilege access. */
8946 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8947 boolean hasReadPermission) {
8948 String iccId = slot.getIccId(portIndex);
8949 if (hasReadPermission) { // if has read permission
8950 return iccId;
8951 } else {
8952 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8953 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8954 // if no read permission, checking carrier privilege access
8955 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8956 return iccId;
8957 }
8958 }
8959 }
8960 // No read permission or carrier privilege access.
8961 return UiccPortInfo.ICCID_REDACTED;
8962 }
8963
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008964 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008965 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008966 public boolean switchSlots(int[] physicalSlots) {
8967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008968
8969 final long identity = Binder.clearCallingIdentity();
8970 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008971 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8972 for (int i = 0; i < physicalSlots.length; i++) {
8973 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8974 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8975 physicalSlots[i], i));
8976 }
8977 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978 } finally {
8979 Binder.restoreCallingIdentity(identity);
8980 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008981 }
Jack Yu4c988042018-02-27 15:30:01 -08008982
8983 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008984 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8985 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8986 enforceModifyPermission();
8987
8988 final long identity = Binder.clearCallingIdentity();
8989 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008990 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00008991 } finally {
8992 Binder.restoreCallingIdentity(identity);
8993 }
8994 }
8995
8996 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008997 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008998 final long identity = Binder.clearCallingIdentity();
8999 try {
9000 return UiccController.getInstance().getCardIdForDefaultEuicc();
9001 } finally {
9002 Binder.restoreCallingIdentity(identity);
9003 }
9004 }
9005
Pengquan Meng85728fb2018-03-12 16:31:21 -07009006 /**
goneil47ffb6e2018-04-06 15:40:58 -07009007 * A test API to reload the UICC profile.
9008 *
9009 * <p>Requires that the calling app has permission
9010 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9011 * @hide
9012 */
9013 @Override
9014 public void refreshUiccProfile(int subId) {
9015 enforceModifyPermission();
9016
9017 final long identity = Binder.clearCallingIdentity();
9018 try {
9019 Phone phone = getPhone(subId);
9020 if (phone == null) {
9021 return;
9022 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009023 UiccPort uiccPort = phone.getUiccPort();
9024 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009025 return;
9026 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009027 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009028 if (uiccProfile == null) {
9029 return;
9030 }
9031 uiccProfile.refresh();
9032 } finally {
9033 Binder.restoreCallingIdentity(identity);
9034 }
9035 }
9036
9037 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009038 * Returns false if the mobile data is disabled by default, otherwise return true.
9039 */
9040 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009041 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009042 }
9043
9044 /**
9045 * Returns true if the data roaming is enabled by default, i.e the system property
9046 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9047 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9048 */
9049 private boolean getDefaultDataRoamingEnabled(int subId) {
9050 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009051 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009052 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009053 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9054 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9055 return isDataRoamingEnabled;
9056 }
9057
9058 /**
9059 * Returns the default network type for the given {@code subId}, if the default network type is
9060 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9061 */
9062 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009063 List<Integer> list = TelephonyProperties.default_network();
9064 int phoneId = mSubscriptionController.getPhoneId(subId);
9065 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9066 return list.get(phoneId);
9067 }
9068 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009069 }
fionaxua13278b2018-03-21 00:08:13 -07009070
9071 @Override
9072 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009073 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009074 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009075
9076 final long identity = Binder.clearCallingIdentity();
9077 try {
9078 final Phone phone = getPhone(subId);
9079 if (phone == null) {
9080 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9081 return;
9082 }
chen xueaba88a2019-03-15 13:15:10 -07009083 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9084 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009085 if (carrierPrivilegeRules == null) {
9086 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9087 } else {
9088 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9089 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009090 } finally {
9091 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009092 }
fionaxua13278b2018-03-21 00:08:13 -07009093 }
9094
9095 @Override
9096 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009097 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009098
9099 final long identity = Binder.clearCallingIdentity();
9100 try {
9101 final Phone phone = getPhone(subId);
9102 if (phone == null) {
9103 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9104 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9105 }
9106 return phone.getCarrierIdListVersion();
9107 } finally {
9108 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009109 }
fionaxua13278b2018-03-21 00:08:13 -07009110 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009111
9112 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009113 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9114 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009116 mApp, subId, callingPackage, callingFeatureId,
9117 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009118 return -1;
9119 }
9120
9121 final long identity = Binder.clearCallingIdentity();
9122 try {
9123 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
9126 }
9127 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009128
9129 @Override
9130 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009131 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009132 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009133 mApp, subId, "getCdmaRoamingMode");
9134
9135 final long identity = Binder.clearCallingIdentity();
9136 try {
9137 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9138 } finally {
9139 Binder.restoreCallingIdentity(identity);
9140 }
9141 }
9142
9143 @Override
9144 public boolean setCdmaRoamingMode(int subId, int mode) {
9145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9146 mApp, subId, "setCdmaRoamingMode");
9147
9148 final long identity = Binder.clearCallingIdentity();
9149 try {
9150 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9151 } finally {
9152 Binder.restoreCallingIdentity(identity);
9153 }
9154 }
9155
9156 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009157 public int getCdmaSubscriptionMode(int subId) {
9158 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009159 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009160 mApp, subId, "getCdmaSubscriptionMode");
9161
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
9164 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
9168 }
9169
9170 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009171 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9173 mApp, subId, "setCdmaSubscriptionMode");
9174
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
9177 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9178 } finally {
9179 Binder.restoreCallingIdentity(identity);
9180 }
9181 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009182
sqianc5eccab2018-10-19 18:46:41 -07009183 @Override
sqian8c685422019-02-22 15:55:18 -08009184 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009185 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009187 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9188 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009189 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9190 }
9191 final long identity = Binder.clearCallingIdentity();
9192 try {
sqian854d44b2018-12-12 16:48:18 -08009193 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9194 for (Phone phone: PhoneFactory.getPhones()) {
9195 if (phone.getEmergencyNumberTracker() != null
9196 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9197 emergencyNumberListInternal.put(
9198 phone.getSubId(),
9199 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9200 }
sqian11b7a0e2018-12-05 18:48:28 -08009201 }
sqian854d44b2018-12-12 16:48:18 -08009202 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009203 } finally {
9204 Binder.restoreCallingIdentity(identity);
9205 }
sqianc5eccab2018-10-19 18:46:41 -07009206 }
9207
9208 @Override
sqian8c685422019-02-22 15:55:18 -08009209 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009210 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009211 if (!exactMatch) {
9212 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009213 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009214 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009215 }
9216 final long identity = Binder.clearCallingIdentity();
9217 try {
sqian854d44b2018-12-12 16:48:18 -08009218 for (Phone phone: PhoneFactory.getPhones()) {
9219 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009220 && phone.getEmergencyNumberTracker()
9221 .isEmergencyNumber(number, exactMatch)) {
9222 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009223 }
sqian11b7a0e2018-12-05 18:48:28 -08009224 }
9225 return false;
9226 } finally {
9227 Binder.restoreCallingIdentity(identity);
9228 }
9229 }
9230
sqianf4ca7ed2019-01-15 18:32:07 -08009231 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009232 * Start emergency callback mode for GsmCdmaPhone for testing.
9233 */
9234 @Override
9235 public void startEmergencyCallbackMode() {
9236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9237 "startEmergencyCallbackMode");
9238 enforceModifyPermission();
9239 final long identity = Binder.clearCallingIdentity();
9240 try {
9241 for (Phone phone : PhoneFactory.getPhones()) {
9242 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9243 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9244 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9245 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9246 gsmCdmaPhone.obtainMessage(
9247 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9248 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9249 }
9250 }
9251 } finally {
9252 Binder.restoreCallingIdentity(identity);
9253 }
9254 }
9255
9256 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009257 * Update emergency number list for test mode.
9258 */
9259 @Override
9260 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9262 "updateEmergencyNumberListTestMode");
9263
9264 final long identity = Binder.clearCallingIdentity();
9265 try {
9266 for (Phone phone: PhoneFactory.getPhones()) {
9267 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9268 if (tracker != null) {
9269 tracker.executeEmergencyNumberTestModeCommand(action, num);
9270 }
9271 }
9272 } finally {
9273 Binder.restoreCallingIdentity(identity);
9274 }
9275 }
9276
9277 /**
9278 * Get the full emergency number list for test mode.
9279 */
9280 @Override
9281 public List<String> getEmergencyNumberListTestMode() {
9282 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9283 "getEmergencyNumberListTestMode");
9284
9285 final long identity = Binder.clearCallingIdentity();
9286 try {
9287 Set<String> emergencyNumbers = new HashSet<>();
9288 for (Phone phone: PhoneFactory.getPhones()) {
9289 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9290 if (tracker != null) {
9291 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9292 emergencyNumbers.add(num.getNumber());
9293 }
9294 }
9295 }
9296 return new ArrayList<>(emergencyNumbers);
9297 } finally {
9298 Binder.restoreCallingIdentity(identity);
9299 }
9300 }
9301
chen xud6b45bd2018-10-30 22:27:10 -07009302 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009303 public int getEmergencyNumberDbVersion(int subId) {
9304 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9305
9306 final long identity = Binder.clearCallingIdentity();
9307 try {
9308 final Phone phone = getPhone(subId);
9309 if (phone == null) {
9310 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9311 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9312 }
9313 return phone.getEmergencyNumberDbVersion();
9314 } finally {
9315 Binder.restoreCallingIdentity(identity);
9316 }
9317 }
9318
9319 @Override
9320 public void notifyOtaEmergencyNumberDbInstalled() {
9321 enforceModifyPermission();
9322
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 for (Phone phone: PhoneFactory.getPhones()) {
9326 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9327 if (tracker != null) {
9328 tracker.updateOtaEmergencyNumberDatabase();
9329 }
9330 }
9331 } finally {
9332 Binder.restoreCallingIdentity(identity);
9333 }
9334 }
9335
9336 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009337 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009338 enforceActiveEmergencySessionPermission();
9339
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 for (Phone phone: PhoneFactory.getPhones()) {
9343 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9344 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009345 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9346 }
9347 }
9348 } finally {
9349 Binder.restoreCallingIdentity(identity);
9350 }
9351 }
9352
9353 @Override
9354 public void resetOtaEmergencyNumberDbFilePath() {
9355 enforceActiveEmergencySessionPermission();
9356
9357 final long identity = Binder.clearCallingIdentity();
9358 try {
9359 for (Phone phone: PhoneFactory.getPhones()) {
9360 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9361 if (tracker != null) {
9362 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009363 }
9364 }
9365 } finally {
9366 Binder.restoreCallingIdentity(identity);
9367 }
9368 }
9369
9370 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009371 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9372 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9373 Phone phone = getPhone(subId);
9374 if (phone == null) {
9375 return null;
9376 }
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
9379 UiccProfile profile = UiccController.getInstance()
9380 .getUiccProfileForPhone(phone.getPhoneId());
9381 if (profile != null) {
9382 return profile.getCertsFromCarrierPrivilegeAccessRules();
9383 }
9384 } finally {
9385 Binder.restoreCallingIdentity(identity);
9386 }
9387 return null;
9388 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009389
9390 /**
9391 * Enable or disable a modem stack.
9392 */
9393 @Override
9394 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9395 enforceModifyPermission();
9396
9397 final long identity = Binder.clearCallingIdentity();
9398 try {
9399 Phone phone = PhoneFactory.getPhone(slotIndex);
9400 if (phone == null) {
9401 return false;
9402 } else {
9403 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9404 }
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408 }
Michelecea4cf22018-12-21 15:00:11 -08009409
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009410 /**
9411 * Whether a modem stack is enabled or not.
9412 */
9413 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009414 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9415 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009416 Phone phone = PhoneFactory.getPhone(slotIndex);
9417 if (phone == null) return false;
9418
9419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009420 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9421 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009422 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9423 }
9424
9425 final long identity = Binder.clearCallingIdentity();
9426 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009427 try {
9428 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9429 } catch (NoSuchElementException ex) {
9430 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9431 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 }
9436
Michelecea4cf22018-12-21 15:00:11 -08009437 @Override
Michele0ea7d782019-03-19 14:58:42 -07009438 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009439 enforceModifyPermission();
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009444 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009445 .commit();
9446 } finally {
9447 Binder.restoreCallingIdentity(identity);
9448 }
9449 }
9450
9451 @Override
Michele0ea7d782019-03-19 14:58:42 -07009452 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009453 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009454 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009455 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9456 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009457 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009458 }
Michelecea4cf22018-12-21 15:00:11 -08009459
9460 final long identity = Binder.clearCallingIdentity();
9461 try {
Michele0ea7d782019-03-19 14:58:42 -07009462 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009463 } finally {
9464 Binder.restoreCallingIdentity(identity);
9465 }
9466 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009467
Michele0ea7d782019-03-19 14:58:42 -07009468 @TelephonyManager.IsMultiSimSupportedResult
9469 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009470 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9471 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9472 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009473 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9474 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009475 }
9476 // Check if the hardware supports multisim functionality. If usage of multisim is not
9477 // supported by the modem, indicate that it is restricted.
9478 PhoneCapability staticCapability =
9479 mPhoneConfigurationManager.getStaticPhoneCapability();
9480 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009481 loge("isMultiSimSupportedInternal: no static configuration available");
9482 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009483 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009484 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009485 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9486 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009487 }
9488 // Check if support of multiple SIMs is restricted by carrier
9489 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009490 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009491 }
9492
Michele0ea7d782019-03-19 14:58:42 -07009493 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009494 }
9495
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009496 /**
9497 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009498 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9499 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9500 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009501 * @param numOfSims number of active sims we want to switch to
9502 */
9503 @Override
9504 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009505 if (numOfSims == 1) {
9506 enforceModifyPermission();
9507 } else {
9508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9509 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9510 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009511 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009512
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009513 try {
Michele30b57b22019-03-01 12:01:14 -08009514 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009515 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009516 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9517 return;
9518 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009519 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9520 } finally {
9521 Binder.restoreCallingIdentity(identity);
9522 }
9523 }
9524
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009525 @Override
9526 public boolean isApplicationOnUicc(int subId, int appType) {
9527 enforceReadPrivilegedPermission("isApplicationOnUicc");
9528 Phone phone = getPhone(subId);
9529 if (phone == null) {
9530 return false;
9531 }
9532 final long identity = Binder.clearCallingIdentity();
9533 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009534 UiccPort uiccPort = phone.getUiccPort();
9535 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009536 return false;
9537 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009538 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009539 if (uiccProfile == null) {
9540 return false;
9541 }
9542 if (TelephonyManager.APPTYPE_SIM <= appType
9543 && appType <= TelephonyManager.APPTYPE_ISIM) {
9544 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9545 }
9546 return false;
9547 } finally {
9548 Binder.restoreCallingIdentity(identity);
9549 }
9550 }
9551
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009552 /**
chen xub4baa772019-04-03 10:23:41 -07009553 * Get whether making changes to modem configurations will trigger reboot.
9554 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009555 */
9556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009557 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9558 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009560 mApp, subId, callingPackage, callingFeatureId,
9561 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009562 return false;
9563 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009564 final long identity = Binder.clearCallingIdentity();
9565 try {
9566 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9567 } finally {
9568 Binder.restoreCallingIdentity(identity);
9569 }
9570 }
9571
Nathan Harold29f5f052019-02-15 13:41:57 -08009572 private void updateModemStateMetrics() {
9573 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9574 // TODO: check the state for each modem if the api is ready.
9575 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9576 }
9577
Pengquan Meng3889a572019-01-23 11:16:29 -08009578 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009579 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009580 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009581 // Verify that the callingPackage belongs to the calling UID
9582 mApp.getSystemService(AppOpsManager.class)
9583 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009584 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009585 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009586 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009587 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9588 if (slotInfos != null) {
9589 for (int i = 0; i < slotInfos.length; i++) {
9590 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9591 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9592 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9593 portInfo.getLogicalSlotIndex()));
9594 }
9595 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009596 }
9597 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009598 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009603
9604 /**
9605 * Get the IRadio HAL Version
9606 */
9607 @Override
9608 public int getRadioHalVersion() {
9609 Phone phone = getDefaultPhone();
9610 if (phone == null) return -1;
9611 HalVersion hv = phone.getHalVersion();
9612 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9613 return hv.major * 100 + hv.minor;
9614 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009615
9616 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009617 * Get the current calling package name.
9618 * @return the current calling package name
9619 */
9620 @Override
9621 public String getCurrentPackageName() {
9622 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9623 }
9624
9625 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009626 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9627 * corresponding network requests on a subId.
9628 *
9629 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009630 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009631 * 2) APN is un-metered for this subscription, or
9632 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009633 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009634 *
9635 * @return whether data is allowed for a apn type.
9636 *
9637 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009638 */
9639 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009640 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009641 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9642 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009643
9644 // Now that all security checks passes, perform the operation as ourselves.
9645 final long identity = Binder.clearCallingIdentity();
9646 try {
9647 Phone phone = getPhone(subId);
9648 if (phone == null) return false;
9649
Jack Yu41407ee2019-05-13 16:54:09 -07009650 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009651 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9652 } finally {
9653 Binder.restoreCallingIdentity(identity);
9654 }
9655 }
9656
9657 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009658 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009659 enforceReadPrivilegedPermission("isApnMetered");
9660
9661 // Now that all security checks passes, perform the operation as ourselves.
9662 final long identity = Binder.clearCallingIdentity();
9663 try {
9664 Phone phone = getPhone(subId);
9665 if (phone == null) return true; // By default return true.
9666
Jack Yu41407ee2019-05-13 16:54:09 -07009667 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009668 } finally {
9669 Binder.restoreCallingIdentity(identity);
9670 }
9671 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009672
9673 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009674 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9675 int subscriptionId, IBooleanConsumer resultCallback) {
9676 enforceModifyPermission();
9677 long token = Binder.clearCallingIdentity();
9678 try {
9679 Phone phone = getPhone(subscriptionId);
9680 if (phone == null) {
9681 try {
9682 if (resultCallback != null) {
9683 resultCallback.accept(false);
9684 }
9685 } catch (RemoteException e) {
9686 // ignore
9687 }
9688 return;
9689 }
9690 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9691 Pair.create(specifiers, (x) -> {
9692 try {
9693 if (resultCallback != null) {
9694 resultCallback.accept(x);
9695 }
9696 } catch (RemoteException e) {
9697 // ignore
9698 }
9699 });
9700 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9701 } finally {
9702 Binder.restoreCallingIdentity(token);
9703 }
9704 }
9705
9706 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009707 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9708 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009709 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009710 mApp, subId, "getSystemSelectionChannels");
9711 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9712 final long identity = Binder.clearCallingIdentity();
9713 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009714 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9715 if (result instanceof IllegalStateException) {
9716 throw (IllegalStateException) result;
9717 }
9718 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009719 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9720 return specifiers;
9721 } finally {
9722 Binder.restoreCallingIdentity(identity);
9723 }
9724 }
9725
9726 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009727 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009728 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009729 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9730 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9731 if (iccRecords == null) {
9732 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9733 return false;
9734 }
9735 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9736 }
9737
9738 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009739 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9740 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009741 if (callingPackage == null) {
9742 callingPackage = getCurrentPackageName();
9743 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009744 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9745 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009746 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9747 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009748 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9749 }
9750 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9751 Intent intent = new Intent();
9752 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9753 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9754 // Bring up choose default SMS subscription dialog right now
9755 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9756 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9757 mApp.startActivity(intent);
9758 }
chen xud5ca2d52019-05-28 15:20:57 -07009759
9760 @Override
9761 public String getMmsUAProfUrl(int subId) {
9762 //TODO investigate if this API should require proper permission check in R b/133791609
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009765 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9766 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9767 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9768 return carrierUAProfUrl;
9769 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009770 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9771 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009772 } finally {
9773 Binder.restoreCallingIdentity(identity);
9774 }
9775 }
9776
9777 @Override
9778 public String getMmsUserAgent(int subId) {
9779 //TODO investigate if this API should require proper permission check in R b/133791609
9780 final long identity = Binder.clearCallingIdentity();
9781 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009782 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9783 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9784 if (!TextUtils.isEmpty(carrierUserAgent)) {
9785 return carrierUserAgent;
9786 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009787 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9788 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009789 } finally {
9790 Binder.restoreCallingIdentity(identity);
9791 }
9792 }
Jack Yub07d4972019-05-28 16:12:25 -07009793
9794 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009795 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9796 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009797
Jack Yub07d4972019-05-28 16:12:25 -07009798 final long identity = Binder.clearCallingIdentity();
9799 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009800 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009801 if (phone == null) return false;
9802
Hall Liua62f5da2020-09-25 10:42:19 -07009803 switch (policy) {
9804 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9805 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9806 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9807 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9808 default:
9809 throw new IllegalArgumentException(policy + " is not a valid policy");
9810 }
Jack Yub07d4972019-05-28 16:12:25 -07009811 } finally {
9812 Binder.restoreCallingIdentity(identity);
9813 }
9814 }
9815
9816 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009817 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009818 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009819 enforceModifyPermission();
9820
changbettyd5c246e2019-12-24 15:40:37 +08009821 final long identity = Binder.clearCallingIdentity();
9822 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009823 Phone phone = getPhone(subscriptionId);
9824 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009825
Hall Liua62f5da2020-09-25 10:42:19 -07009826 switch (policy) {
9827 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9828 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9829 break;
9830 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9831 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9832 break;
9833 default:
9834 throw new IllegalArgumentException(policy + " is not a valid policy");
9835 }
changbettyd5c246e2019-12-24 15:40:37 +08009836 } finally {
9837 Binder.restoreCallingIdentity(identity);
9838 }
9839 }
9840
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009841 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009842 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009843 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9844 * otherwise.
9845 */
9846 @Override
9847 public void setCepEnabled(boolean isCepEnabled) {
9848 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9849
9850 final long identity = Binder.clearCallingIdentity();
9851 try {
9852 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9853 for (Phone phone : PhoneFactory.getPhones()) {
9854 Phone defaultPhone = phone.getImsPhone();
9855 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9856 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9857 ImsPhoneCallTracker imsPhoneCallTracker =
9858 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9859 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9860 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9861 + imsPhone.getMsisdn());
9862 }
9863 }
9864 } finally {
9865 Binder.restoreCallingIdentity(identity);
9866 }
9867 }
allenwtsu46dcc572020-01-08 18:24:03 +08009868
9869 /**
9870 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9871 *
9872 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9873 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9874 * before being read.
9875 */
9876 @Override
9877 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9878 isCompressed) {
9879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9880 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009881 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9882 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9883 }
9884 if (!isImsAvailableOnDevice()) {
9885 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9886 "IMS not available on device.");
9887 }
9888
9889 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009890 try {
Hui Wang761a6682020-10-31 05:12:53 +00009891 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9892 } finally {
9893 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009894 }
9895 }
zoey chene02881a2019-12-30 16:11:23 +08009896
9897 @Override
9898 public boolean isIccLockEnabled(int subId) {
9899 enforceReadPrivilegedPermission("isIccLockEnabled");
9900
9901 // Now that all security checks passes, perform the operation as ourselves.
9902 final long identity = Binder.clearCallingIdentity();
9903 try {
9904 Phone phone = getPhone(subId);
9905 if (phone != null && phone.getIccCard() != null) {
9906 return phone.getIccCard().getIccLockEnabled();
9907 } else {
9908 return false;
9909 }
9910 } finally {
9911 Binder.restoreCallingIdentity(identity);
9912 }
9913 }
9914
9915 /**
9916 * Set the ICC pin lock enabled or disabled.
9917 *
9918 * @return an integer representing the status of IccLock enabled or disabled in the following
9919 * three cases:
9920 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9921 * successfully.
9922 * - Positive number and zero for remaining password attempts.
9923 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9924 *
9925 */
9926 @Override
9927 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9928 enforceModifyPermission();
9929
9930 Phone phone = getPhone(subId);
9931 if (phone == null) {
9932 return 0;
9933 }
9934 // Now that all security checks passes, perform the operation as ourselves.
9935 final long identity = Binder.clearCallingIdentity();
9936 try {
9937 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9938 new Pair<Boolean, String>(enabled, password), phone, null);
9939 return attemptsRemaining;
9940
9941 } catch (Exception e) {
9942 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9943 } finally {
9944 Binder.restoreCallingIdentity(identity);
9945 }
9946 return 0;
9947 }
9948
9949 /**
9950 * Change the ICC password used in ICC pin lock.
9951 *
9952 * @return an integer representing the status of IccLock changed in the following three cases:
9953 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9954 * - Positive number and zero for remaining password attempts.
9955 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9956 *
9957 */
9958 @Override
9959 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9960 enforceModifyPermission();
9961
9962 Phone phone = getPhone(subId);
9963 if (phone == null) {
9964 return 0;
9965 }
9966 // Now that all security checks passes, perform the operation as ourselves.
9967 final long identity = Binder.clearCallingIdentity();
9968 try {
9969 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9970 new Pair<String, String>(oldPassword, newPassword), phone, null);
9971 return attemptsRemaining;
9972
9973 } catch (Exception e) {
9974 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9975 } finally {
9976 Binder.restoreCallingIdentity(identity);
9977 }
9978 return 0;
9979 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009980
9981 /**
9982 * Request for receiving user activity notification
9983 */
9984 @Override
9985 public void requestUserActivityNotification() {
9986 if (!mNotifyUserActivity.get()
9987 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9988 mNotifyUserActivity.set(true);
9989 }
9990 }
9991
9992 /**
9993 * Called when userActivity is signalled in the power manager.
9994 * This is safe to call from any thread, with any window manager locks held or not.
9995 */
9996 @Override
9997 public void userActivity() {
9998 // ***************************************
9999 // * Inherited from PhoneWindowManager *
10000 // ***************************************
10001 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10002 // WITH ITS LOCKS HELD.
10003 //
10004 // This code must be VERY careful about the locks
10005 // it acquires.
10006 // In fact, the current code acquires way too many,
10007 // and probably has lurking deadlocks.
10008
10009 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10010 throw new SecurityException("Only the OS may call notifyUserActivity()");
10011 }
10012
10013 if (mNotifyUserActivity.getAndSet(false)) {
10014 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10015 USER_ACTIVITY_NOTIFICATION_DELAY);
10016 }
10017 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010018
10019 @Override
10020 public boolean canConnectTo5GInDsdsMode() {
10021 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10022 }
Jack Yud10cdd42020-09-28 20:28:01 -070010023
10024 @Override
10025 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10026 String callingFeatureId) {
10027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10028 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10029 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10030 }
10031
10032 Phone phone = getPhone(subId);
10033 if (phone == null) {
10034 throw new RuntimeException("phone is not available");
10035 }
10036 // Now that all security checks passes, perform the operation as ourselves.
10037 final long identity = Binder.clearCallingIdentity();
10038 try {
10039 return phone.getEquivalentHomePlmns();
10040 } finally {
10041 Binder.restoreCallingIdentity(identity);
10042 }
10043 }
Daniel Bright59e67312020-11-13 11:49:37 -080010044
10045 @Override
10046 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010047 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10048 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010049 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010050 if (radioInterfaceCapabilities == null) {
10051 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010052 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010053 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010054 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010055
Hui Wang641e81c2020-10-12 12:14:23 -070010056 @Override
10057 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10058 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010059 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10060 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10061 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10062 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10063 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010064 if (DBG) {
10065 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10066 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10067 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10068 }
10069
10070 if (!SubscriptionManager.isValidSubscriptionId(subId)
10071 || appType < TelephonyManager.APPTYPE_UNKNOWN
10072 || appType > TelephonyManager.APPTYPE_ISIM
10073 || nafUrl == null || securityProtocol == null || callback == null) {
10074 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10075 if (callback != null) {
10076 try {
10077 callback.onAuthenticationFailure(
10078 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10079 } catch (RemoteException exception) {
10080 log("Fail to notify onAuthenticationFailure due to " + exception);
10081 }
10082 return;
10083 }
10084 }
10085
10086 final long token = Binder.clearCallingIdentity();
10087 try {
10088 getGbaManager(subId).bootstrapAuthenticationRequest(
10089 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10090 forceBootStrapping, callback));
10091 } finally {
10092 Binder.restoreCallingIdentity(token);
10093 }
10094 }
10095
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010096 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010097 * Attempts to set the radio power state for all phones for thermal reason.
10098 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010099 * requested radio power state will actually be set. See {@link
10100 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10101 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010102 * @param enable {@code true} if trying to turn radio on.
10103 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10104 * false}.
10105 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010106 private boolean setRadioPowerForThermal(boolean enable) {
10107 boolean isPhoneAvailable = false;
10108 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10109 Phone phone = PhoneFactory.getPhone(i);
10110 if (phone != null) {
10111 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10112 isPhoneAvailable = true;
10113 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010114 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010115
10116 // return true if successfully informed the phone object about the thermal radio power
10117 // request.
10118 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010119 }
10120
10121 private int handleDataThrottlingRequest(int subId,
10122 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010123 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10124 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10125 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10126 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10127 throw new IllegalArgumentException("modem does not support data throttling");
10128 }
10129
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010130 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10131 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010132 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010133 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10134 }
10135
10136 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10137
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010138 if (isDataThrottlingSupported) {
10139 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010140 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010141 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10142 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10143 } else if (thermalMitigationResult
10144 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010145 log("Modem likely does not support data throttling on secondary carrier. Data " +
10146 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10147 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010148 }
10149 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010150 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010151
10152 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010153 }
10154
Jack Nudelman644b91a2021-03-12 14:09:48 -080010155 private static List<String> getThermalMitigationAllowlist(Context context) {
10156 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10157 for (String pckg : context.getResources()
10158 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10159 sThermalMitigationAllowlistedPackages.add(pckg);
10160 }
10161 }
10162
10163 return sThermalMitigationAllowlistedPackages;
10164 }
10165
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010166 private boolean isAnyPhoneInEmergencyState() {
10167 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10168 if (tm.isInEmergencyCall()) {
10169 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10170 return true;
10171 }
10172 for (Phone phone : PhoneFactory.getPhones()) {
10173 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10174 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10175 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10176 + phone.isInEcm());
10177 return true;
10178 }
10179 }
10180
10181 return false;
10182 }
10183
Jack Nudelman644b91a2021-03-12 14:09:48 -080010184 /**
10185 * Used by shell commands to add an authorized package name for thermal mitigation.
10186 * @param packageName name of package to be allowlisted
10187 * @param context
10188 */
10189 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10190 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10191 sThermalMitigationAllowlistedPackages.add(packageName);
10192 }
10193
10194 /**
10195 * Used by shell commands to remove an authorized package name for thermal mitigation.
10196 * @param packageName name of package to remove from allowlist
10197 * @param context
10198 */
10199 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10200 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10201 sThermalMitigationAllowlistedPackages.remove(packageName);
10202 }
10203
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010204 /**
10205 * Thermal mitigation request to control functionalities at modem.
10206 *
10207 * @param subId the id of the subscription.
10208 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010209 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010210 *
10211 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10212 */
10213 @Override
10214 @ThermalMitigationResult
10215 public int sendThermalMitigationRequest(
10216 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010217 ThermalMitigationRequest thermalMitigationRequest,
10218 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010219 enforceModifyPermission();
10220
Jack Nudelman644b91a2021-03-12 14:09:48 -080010221 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10222 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10223 .contains(callingPackage)) {
10224 throw new SecurityException("Calling package must be configured in the device config. "
10225 + "calling package: " + callingPackage);
10226 }
10227
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010228 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10229 final long identity = Binder.clearCallingIdentity();
10230
10231 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10232 try {
10233 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10234 switch (thermalMitigationAction) {
10235 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10236 thermalMitigationResult =
10237 handleDataThrottlingRequest(subId,
10238 thermalMitigationRequest.getDataThrottlingRequest());
10239 break;
10240 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10241 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10242 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10243 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10244 }
10245
10246 // Ensure that radio is on. If not able to power on due to phone being
10247 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010248 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010249 thermalMitigationResult =
10250 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10251 break;
10252 }
10253
10254 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10255 false);
10256 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10257 break;
10258 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10259 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10260 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10261 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10262 }
10263
10264 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10265 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 Phone phone = getPhone(subId);
10267 if (phone == null) {
10268 thermalMitigationResult =
10269 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10270 break;
10271 }
10272
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010273 TelephonyConnectionService service =
10274 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010275 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010276 Log.e(LOG_TAG, "An emergency call is pending");
10277 thermalMitigationResult =
10278 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10279 break;
10280 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010281 thermalMitigationResult =
10282 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10283 break;
10284 }
10285 } else {
10286 thermalMitigationResult =
10287 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10288 break;
10289 }
10290
10291 // Turn radio off. If not able to power off due to phone being unavailable,
10292 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010293 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010294 thermalMitigationResult =
10295 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10296 break;
10297 }
10298 thermalMitigationResult =
10299 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10300 break;
10301 default:
10302 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10303 + "not exist. Requested action: " + thermalMitigationAction);
10304 }
10305 } catch (IllegalArgumentException e) {
10306 throw e;
10307 } catch (Exception e) {
10308 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10309 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10310 } finally {
10311 Binder.restoreCallingIdentity(identity);
10312 }
10313
10314 if (DBG) {
10315 log("thermalMitigationRequest returning with thermalMitigationResult: "
10316 + thermalMitigationResult);
10317 }
10318
10319 return thermalMitigationResult;
10320 }
Hui Wang641e81c2020-10-12 12:14:23 -070010321
10322 /**
10323 * Set the GbaService Package Name that Telephony will bind to.
10324 *
10325 * @param subId The sim that the GbaService is associated with.
10326 * @param packageName The name of the package to be replaced with.
10327 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10328 */
10329 @Override
10330 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10331 enforceModifyPermission();
10332
10333 final long identity = Binder.clearCallingIdentity();
10334 try {
10335 return getGbaManager(subId).overrideServicePackage(packageName);
10336 } finally {
10337 Binder.restoreCallingIdentity(identity);
10338 }
10339 }
10340
10341 /**
10342 * Return the package name of the currently bound GbaService.
10343 *
10344 * @param subId The sim that the GbaService is associated with.
10345 * @return the package name of the GbaService configuration, null if GBA is not supported.
10346 */
10347 @Override
10348 public String getBoundGbaService(int subId) {
10349 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10350
10351 final long identity = Binder.clearCallingIdentity();
10352 try {
10353 return getGbaManager(subId).getServicePackage();
10354 } finally {
10355 Binder.restoreCallingIdentity(identity);
10356 }
10357 }
10358
10359 /**
10360 * Set the release time for telephony to unbind GbaService.
10361 *
10362 * @param subId The sim that the GbaService is associated with.
10363 * @param interval The release time to unbind GbaService by millisecond.
10364 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10365 */
10366 @Override
10367 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10368 enforceModifyPermission();
10369
10370 final long identity = Binder.clearCallingIdentity();
10371 try {
10372 return getGbaManager(subId).overrideReleaseTime(interval);
10373 } finally {
10374 Binder.restoreCallingIdentity(identity);
10375 }
10376 }
10377
10378 /**
10379 * Return the release time for telephony to unbind GbaService.
10380 *
10381 * @param subId The sim that the GbaService is associated with.
10382 * @return The release time to unbind GbaService by millisecond.
10383 */
10384 @Override
10385 public int getGbaReleaseTime(int subId) {
10386 enforceReadPrivilegedPermission("getGbaReleaseTime");
10387
10388 final long identity = Binder.clearCallingIdentity();
10389 try {
10390 return getGbaManager(subId).getReleaseTime();
10391 } finally {
10392 Binder.restoreCallingIdentity(identity);
10393 }
10394 }
10395
10396 private GbaManager getGbaManager(int subId) {
10397 GbaManager instance = GbaManager.getInstance(subId);
10398 if (instance == null) {
10399 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10400 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10401 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10402 }
10403 return instance;
10404 }
Hui Wang761a6682020-10-31 05:12:53 +000010405
10406 /**
10407 * indicate whether the device and the carrier can support
10408 * RCS VoLTE single registration.
10409 */
10410 @Override
10411 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010412 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10413 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10414 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10415 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010416
10417 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10418 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10419 }
10420
10421 final long identity = Binder.clearCallingIdentity();
10422 try {
10423 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10424 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010425 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10426 if (isCapable != null) {
10427 return isCapable;
10428 }
Hui Wang761a6682020-10-31 05:12:53 +000010429 }
Hui Wang67af90e2021-06-04 16:57:15 -070010430 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10431 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010432 } finally {
10433 Binder.restoreCallingIdentity(identity);
10434 }
10435 }
10436
10437 /**
10438 * Register RCS provisioning callback.
10439 */
10440 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010441 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010442 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010443 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010444 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010445 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10446 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010447
10448 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10449 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10450 }
10451 if (!isImsAvailableOnDevice()) {
10452 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10453 "IMS not available on device.");
10454 }
10455
10456 final long identity = Binder.clearCallingIdentity();
10457 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010458 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010459 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010460 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10461 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010462 }
Hui Wang761a6682020-10-31 05:12:53 +000010463 } finally {
10464 Binder.restoreCallingIdentity(identity);
10465 }
10466 }
10467
10468 /**
10469 * Unregister RCS provisioning callback.
10470 */
10471 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010472 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010473 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010474 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010475 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010476 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10477 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010478
10479 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10480 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10481 }
10482 if (!isImsAvailableOnDevice()) {
10483 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10484 "IMS not available on device.");
10485 }
10486
10487 final long identity = Binder.clearCallingIdentity();
10488 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010489 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010490 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
10496 /**
10497 * trigger RCS reconfiguration.
10498 */
10499 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010500 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10501 "triggerRcsReconfiguration",
10502 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010503
10504 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10505 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10506 }
10507 if (!isImsAvailableOnDevice()) {
10508 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10509 "IMS not available on device.");
10510 }
10511
10512 final long identity = Binder.clearCallingIdentity();
10513 try {
10514 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10515 } finally {
10516 Binder.restoreCallingIdentity(identity);
10517 }
10518 }
10519
10520 /**
10521 * Provide the client configuration parameters of the RCS application.
10522 */
10523 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010524 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10525 "setRcsClientConfiguration",
10526 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010527
10528 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10529 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10530 }
10531 if (!isImsAvailableOnDevice()) {
10532 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10533 "IMS not available on device.");
10534 }
10535
10536 final long identity = Binder.clearCallingIdentity();
10537
10538 try {
10539 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10540 if (configBinder == null) {
10541 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010542 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10543 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010544 } else {
10545 configBinder.setRcsClientConfiguration(rcc);
10546 }
joonhunshin3e154242021-09-17 06:33:39 +000010547
10548 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10549 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010550 } catch (RemoteException e) {
10551 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010552 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10553 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010554 } finally {
10555 Binder.restoreCallingIdentity(identity);
10556 }
10557 }
10558
10559 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010560 * Enables or disables the test mode for RCS VoLTE single registration.
10561 */
10562 @Override
10563 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10564 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10565 "setRcsSingleRegistrationTestModeEnabled");
10566
10567 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10568 }
10569
10570 /**
10571 * Gets the test mode for RCS VoLTE single registration.
10572 */
10573 @Override
10574 public boolean getRcsSingleRegistrationTestModeEnabled() {
10575 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10576 "getRcsSingleRegistrationTestModeEnabled");
10577
10578 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10579 }
10580
10581 /**
Hui Wang761a6682020-10-31 05:12:53 +000010582 * Overrides the config of RCS VoLTE single registration enabled for the device.
10583 */
10584 @Override
10585 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10586 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10587 "setDeviceSingleRegistrationEnabledOverride");
10588 enforceModifyPermission();
10589
10590 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10591 : Boolean.parseBoolean(enabledStr);
10592 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010593 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010594 }
10595
10596 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010597 * Sends a device to device communication message. Only usable via shell.
10598 * @param message message to send.
10599 * @param value message value.
10600 */
10601 @Override
10602 public void sendDeviceToDeviceMessage(int message, int value) {
10603 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010604 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010605 enforceModifyPermission();
10606
10607 final long identity = Binder.clearCallingIdentity();
10608 try {
10609 TelephonyConnectionService service =
10610 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10611 if (service == null) {
10612 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10613 return;
10614 }
10615 service.sendTestDeviceToDeviceMessage(message, value);
10616 } finally {
10617 Binder.restoreCallingIdentity(identity);
10618 }
10619 }
10620
Tyler Gunnbabbda02021-02-10 11:05:02 -080010621 /**
10622 * Sets the specified device to device transport active.
10623 * @param transport The transport to set active.
10624 */
10625 @Override
10626 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10628 "setActiveDeviceToDeviceTransport");
10629 enforceModifyPermission();
10630
10631 final long identity = Binder.clearCallingIdentity();
10632 try {
10633 TelephonyConnectionService service =
10634 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10635 if (service == null) {
10636 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10637 return;
10638 }
10639 service.setActiveDeviceToDeviceTransport(transport);
10640 } finally {
10641 Binder.restoreCallingIdentity(identity);
10642 }
10643 }
Tyler Gunn92479152021-01-20 16:30:10 -080010644
Tyler Gunnd4339262021-05-03 14:46:49 -070010645 @Override
10646 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10647 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10648 "setDeviceToDeviceForceEnabled");
10649
10650 final long identity = Binder.clearCallingIdentity();
10651 try {
10652 Arrays.stream(PhoneFactory.getPhones()).forEach(
10653 p -> {
10654 Phone thePhone = p.getImsPhone();
10655 if (thePhone != null && thePhone instanceof ImsPhone) {
10656 ImsPhone imsPhone = (ImsPhone) thePhone;
10657 CallTracker tracker = imsPhone.getCallTracker();
10658 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10659 ImsPhoneCallTracker imsPhoneCallTracker =
10660 (ImsPhoneCallTracker) tracker;
10661 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10662 }
10663 }
10664 }
10665 );
10666 } finally {
10667 Binder.restoreCallingIdentity(identity);
10668 }
10669 }
10670
Tyler Gunn92479152021-01-20 16:30:10 -080010671 /**
Hui Wang761a6682020-10-31 05:12:53 +000010672 * Gets the config of RCS VoLTE single registration enabled for the device.
10673 */
10674 @Override
10675 public boolean getDeviceSingleRegistrationEnabled() {
10676 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10677 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10678 }
10679
10680 /**
10681 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10682 */
10683 @Override
10684 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10685 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10686 "setCarrierSingleRegistrationEnabledOverride");
10687 enforceModifyPermission();
10688
10689 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10690 : Boolean.parseBoolean(enabledStr);
10691 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10692 subId, enabled);
10693 }
10694
10695 /**
10696 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10697 */
10698 @Override
10699 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10700 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10701 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10702 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010703
10704 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010705 * Overrides the ims feature validation result
10706 */
10707 @Override
10708 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10709 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10710 "setImsFeatureValidationOverride");
10711
10712 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10713 : Boolean.parseBoolean(enabledStr);
10714 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10715 subId, enabled);
10716 }
10717
10718 /**
10719 * Gets the ims feature validation override value
10720 */
10721 @Override
10722 public boolean getImsFeatureValidationOverride(int subId) {
10723 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10724 "getImsFeatureValidationOverride");
10725 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10726 }
10727
10728 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010729 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10730 * their mobile plan.
10731 */
10732 @Override
10733 public String getMobileProvisioningUrl() {
10734 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10735 final long identity = Binder.clearCallingIdentity();
10736 try {
10737 return getDefaultPhone().getMobileProvisioningUrl();
10738 } finally {
10739 Binder.restoreCallingIdentity(identity);
10740 }
10741 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010742
James.cf Linbcdf8b32021-01-14 16:44:13 +080010743 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010744 * Get the EAB contact from the EAB database.
10745 */
10746 @Override
10747 public String getContactFromEab(String contact) {
10748 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10749 enforceModifyPermission();
10750 final long identity = Binder.clearCallingIdentity();
10751 try {
10752 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10753 } finally {
10754 Binder.restoreCallingIdentity(identity);
10755 }
10756 }
10757
10758 /**
Calvin Pana1434322021-07-01 19:27:01 +080010759 * Get the EAB capability from the EAB database.
10760 */
10761 @Override
10762 public String getCapabilityFromEab(String contact) {
10763 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10764 enforceModifyPermission();
10765 final long identity = Binder.clearCallingIdentity();
10766 try {
10767 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10768 } finally {
10769 Binder.restoreCallingIdentity(identity);
10770 }
10771 }
10772
10773 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010774 * Remove the EAB contacts from the EAB database.
10775 */
10776 @Override
10777 public int removeContactFromEab(int subId, String contacts) {
10778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10779 enforceModifyPermission();
10780 final long identity = Binder.clearCallingIdentity();
10781 try {
10782 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10783 } finally {
10784 Binder.restoreCallingIdentity(identity);
10785 }
10786 }
10787
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010788 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010789 public boolean getDeviceUceEnabled() {
10790 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10791 final long identity = Binder.clearCallingIdentity();
10792 try {
10793 return mApp.getDeviceUceEnabled();
10794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
10798
10799 @Override
10800 public void setDeviceUceEnabled(boolean isEnabled) {
10801 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10802 final long identity = Binder.clearCallingIdentity();
10803 try {
10804 mApp.setDeviceUceEnabled(isEnabled);
10805 } finally {
10806 Binder.restoreCallingIdentity(identity);
10807 }
10808 }
10809
Brad Ebinger14d467f2021-02-12 06:18:28 +000010810 /**
10811 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10812 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10813 */
10814 // Used for SHELL command only right now.
10815 @Override
10816 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10817 List<String> featureTags) {
10818 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10819 "addUceRegistrationOverrideShell");
10820 final long identity = Binder.clearCallingIdentity();
10821 try {
10822 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10823 new ArraySet<>(featureTags));
10824 } catch (ImsException e) {
10825 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10826 } finally {
10827 Binder.restoreCallingIdentity(identity);
10828 }
10829 }
10830
10831 /**
10832 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10833 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10834 */
10835 // Used for SHELL command only right now.
10836 @Override
10837 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10838 List<String> featureTags) {
10839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10840 "removeUceRegistrationOverrideShell");
10841 final long identity = Binder.clearCallingIdentity();
10842 try {
10843 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10844 new ArraySet<>(featureTags));
10845 } catch (ImsException e) {
10846 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10847 } finally {
10848 Binder.restoreCallingIdentity(identity);
10849 }
10850 }
10851
10852 /**
10853 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10854 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10855 */
10856 // Used for SHELL command only right now.
10857 @Override
10858 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10859 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10860 "clearUceRegistrationOverrideShell");
10861 final long identity = Binder.clearCallingIdentity();
10862 try {
10863 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10864 } catch (ImsException e) {
10865 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10866 } finally {
10867 Binder.restoreCallingIdentity(identity);
10868 }
10869 }
10870
10871 /**
10872 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10873 */
10874 // Used for SHELL command only right now.
10875 @Override
10876 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10878 "getLatestRcsContactUceCapabilityShell");
10879 final long identity = Binder.clearCallingIdentity();
10880 try {
10881 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10882 } catch (ImsException e) {
10883 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10884 } finally {
10885 Binder.restoreCallingIdentity(identity);
10886 }
10887 }
10888
10889 /**
10890 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10891 * device does not have an active PUBLISH.
10892 */
10893 // Used for SHELL command only right now.
10894 @Override
10895 public String getLastUcePidfXmlShell(int subId) {
10896 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10897 final long identity = Binder.clearCallingIdentity();
10898 try {
10899 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10900 } catch (ImsException e) {
10901 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10902 } finally {
10903 Binder.restoreCallingIdentity(identity);
10904 }
10905 }
10906
James.cf Line8713a42021-04-29 16:04:26 +080010907 /**
10908 * Remove UCE requests cannot be sent to the network status.
10909 */
10910 // Used for SHELL command only right now.
10911 @Override
10912 public boolean removeUceRequestDisallowedStatus(int subId) {
10913 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10914 final long identity = Binder.clearCallingIdentity();
10915 try {
10916 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10917 } catch (ImsException e) {
10918 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10919 } finally {
10920 Binder.restoreCallingIdentity(identity);
10921 }
10922 }
10923
James.cf Lin18bb9002021-05-25 01:37:38 +080010924 /**
10925 * Remove UCE requests cannot be sent to the network status.
10926 */
10927 // Used for SHELL command only.
10928 @Override
10929 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10930 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10931 final long identity = Binder.clearCallingIdentity();
10932 try {
10933 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10934 } catch (ImsException e) {
10935 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10936 } finally {
10937 Binder.restoreCallingIdentity(identity);
10938 }
10939 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010940
James.cf Lin4b784aa2021-01-31 03:25:15 +080010941 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010942 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10943 String callingPackage) {
10944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10945 mApp, subId, "setSignalStrengthUpdateRequest");
10946
10947 final int callingUid = Binder.getCallingUid();
10948 // Verify that tha callingPackage belongs to the calling UID
10949 mApp.getSystemService(AppOpsManager.class)
10950 .checkPackage(callingUid, callingPackage);
10951
Rambo Wang3607f502021-02-01 21:51:40 -080010952 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010953
10954 final long identity = Binder.clearCallingIdentity();
10955 try {
10956 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10957 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10958
10959 if (result instanceof IllegalStateException) {
10960 throw (IllegalStateException) result;
10961 }
10962 } finally {
10963 Binder.restoreCallingIdentity(identity);
10964 }
10965 }
10966
10967 @Override
10968 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10969 String callingPackage) {
10970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10971 mApp, subId, "clearSignalStrengthUpdateRequest");
10972
10973 final int callingUid = Binder.getCallingUid();
10974 // Verify that tha callingPackage belongs to the calling UID
10975 mApp.getSystemService(AppOpsManager.class)
10976 .checkPackage(callingUid, callingPackage);
10977
10978 final long identity = Binder.clearCallingIdentity();
10979 try {
10980 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10981 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10982
10983 if (result instanceof IllegalStateException) {
10984 throw (IllegalStateException) result;
10985 }
10986 } finally {
10987 Binder.restoreCallingIdentity(identity);
10988 }
10989 }
10990
Rambo Wang3607f502021-02-01 21:51:40 -080010991 private static void validateSignalStrengthUpdateRequest(Context context,
10992 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010993 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10994 // phone/system process do not have further restriction on request
10995 return;
10996 }
10997
10998 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010999 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011000 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011001 context.enforceCallingOrSelfPermission(
11002 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11003 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011004 }
11005
11006 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11007 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11008 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11009 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11010 || info.isEnabled()) {
11011 throw new IllegalArgumentException(
11012 "Only system can set hide fields in SignalThresholdInfo");
11013 }
11014
11015 // Thresholds length for each RAN need in range. This has been validated in
11016 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11017 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11018 final int[] thresholds = info.getThresholds();
11019 Objects.requireNonNull(thresholds);
11020 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11021 || thresholds.length
11022 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11023 throw new IllegalArgumentException(
11024 "thresholds length is out of range: " + thresholds.length);
11025 }
11026 }
11027 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011028
11029 /**
11030 * Gets the current phone capability.
11031 *
11032 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11033 * @return the PhoneCapability which describes the data connection capability of modem.
11034 * It's used to evaluate possible phone config change, for example from single
11035 * SIM device to multi-SIM device.
11036 */
11037 @Override
11038 public PhoneCapability getPhoneCapability() {
11039 enforceReadPrivilegedPermission("getPhoneCapability");
11040 final long identity = Binder.clearCallingIdentity();
11041 try {
11042 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11043 } finally {
11044 Binder.restoreCallingIdentity(identity);
11045 }
11046 }
Michele Berionne5e411512020-11-13 02:36:59 +000011047
11048 /**
11049 * Prepare TelephonyManager for an unattended reboot. The reboot is
11050 * required to be done shortly after the API is invoked.
11051 */
11052 @Override
11053 @TelephonyManager.PrepareUnattendedRebootResult
11054 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011055 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011056 enforceRebootPermission();
11057
11058 final long identity = Binder.clearCallingIdentity();
11059 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011060 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011061 } finally {
11062 Binder.restoreCallingIdentity(identity);
11063 }
11064 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011065
11066 /**
11067 * Request to get the current slicing configuration including URSP rules and
11068 * NSSAIs (configured, allowed and rejected).
11069 *
11070 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11071 */
11072 @Override
11073 public void getSlicingConfig(ResultReceiver callback) {
11074 enforceReadPrivilegedPermission("getSlicingConfig");
11075
11076 final long identity = Binder.clearCallingIdentity();
11077 try {
11078 Phone phone = getDefaultPhone();
11079 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11080 } finally {
11081 Binder.restoreCallingIdentity(identity);
11082 }
11083 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011084
11085 /**
11086 * Register an IMS connection state callback
11087 */
11088 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011089 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11090 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011091 if (feature == ImsFeature.FEATURE_MMTEL) {
11092 // ImsMmTelManager
11093 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11094 TelephonyPermissions
11095 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11096 mApp, subId, "registerImsStateCallback");
11097 } else if (feature == ImsFeature.FEATURE_RCS) {
11098 // ImsRcsManager or SipDelegateManager
11099 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11100 Binder.getCallingUid(), "registerImsStateCallback",
11101 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11102 Manifest.permission.READ_PRECISE_PHONE_STATE,
11103 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11104 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11105 }
11106
11107 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11108 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11109 "IMS not available on device.");
11110 }
11111
11112 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11113 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11114 }
11115
11116 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11117 if (controller == null) {
11118 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11119 "IMS not available on device.");
11120 }
11121
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011122 if (callingPackage == null) {
11123 callingPackage = getCurrentPackageName();
11124 }
11125
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011126 final long token = Binder.clearCallingIdentity();
11127 try {
11128 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011129 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011130 } catch (ImsException e) {
11131 throw new ServiceSpecificException(e.getCode());
11132 } finally {
11133 Binder.restoreCallingIdentity(token);
11134 }
11135 }
11136
11137 /**
11138 * Unregister an IMS connection state callback
11139 */
11140 @Override
11141 public void unregisterImsStateCallback(IImsStateCallback cb) {
11142 final long token = Binder.clearCallingIdentity();
11143 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11144 if (controller == null) {
11145 return;
11146 }
11147 try {
11148 controller.unregisterImsStateCallback(cb);
11149 } finally {
11150 Binder.restoreCallingIdentity(token);
11151 }
11152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011153}