blob: 37d71df691166f11a37bb4fd0a2c1c7444769905 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
sandeepjs0a502c42021-09-27 15:34:44 +000030import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080032import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000033import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080034import android.app.role.RoleManager;
sandeepjs0a502c42021-09-27 15:34:44 +000035import android.compat.annotation.ChangeId;
36import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070037import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070038import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.content.Context;
40import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070041import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070042import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080043import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070044import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.net.Uri;
46import android.os.AsyncResult;
47import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080048import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Bundle;
50import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Looper;
53import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080055import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070056import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070057import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080058import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080059import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070060import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070061import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080062import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070064import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070066import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070067import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080068import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070069import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090070import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080071import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080072import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070073import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070074import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080075import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080076import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070077import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080078import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070079import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080080import android.telephony.CellIdentityCdma;
81import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070083import android.telephony.CellInfoGsm;
84import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070085import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070087import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070088import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070089import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080090import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070091import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080092import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070093import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080094import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080095import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070096import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080097import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080099import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800100import android.telephony.SignalStrengthUpdateRequest;
101import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800102import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800104import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700105import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800107import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800109import android.telephony.UiccCardInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000110import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000111import android.telephony.UiccSlotInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000112import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700113import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700114import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800115import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800116import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800117import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700118import android.telephony.gba.GbaAuthRequest;
119import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700120import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000122import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000123import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700124import android.telephony.ims.RegistrationManager;
joonhunshin2c3e4232021-11-28 07:32:01 +0000125import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700126import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800127import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700128import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000131import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700132import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800133import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800134import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800136import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700139import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800141import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142
Andrew Lee312e8172014-10-23 17:01:36 -0700143import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800144import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800145import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800146import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800147import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700149import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700150import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800151import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700152import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800154import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700156import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800157import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800158import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800159import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700160import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +0000161import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800163import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800165import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700166import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700167import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700168import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700170import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800171import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700172import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700173import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700174import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700175import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800176import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800177import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700178import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700179import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700180import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800181import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800182import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700184import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700186import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800187import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700188import com.android.internal.telephony.imsphone.ImsPhone;
189import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800190import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700191import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700192import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800193import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700194import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800195import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700196import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000199import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800200import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000201import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800202import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700203import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700204import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800205import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800206import com.android.phone.callcomposer.CallComposerPictureManager;
207import com.android.phone.callcomposer.CallComposerPictureTransfer;
208import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700209import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700210import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800211import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700212import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700213import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800214import com.android.services.telephony.TelecomAccountRegistry;
215import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800216import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800217
Hall Liu82694d52020-12-11 18:22:04 -0800218import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700219import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800220import java.io.IOException;
221import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700222import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800224import java.util.Arrays;
sandeepjs0a502c42021-09-27 15:34:44 +0000225import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800226import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800227import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800228import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100229import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800230import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700231import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800232import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800233import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800235import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800236import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238/**
239 * Implementation of the ITelephony interface.
240 */
Santos Cordon117fee72014-05-16 17:56:12 -0700241public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242 private static final String LOG_TAG = "PhoneInterfaceManager";
243 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
244 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800245 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246
247 // Message codes used with mMainThreadHandler
248 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700249 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
250 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700251 private static final int CMD_OPEN_CHANNEL = 9;
252 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
253 private static final int CMD_CLOSE_CHANNEL = 11;
254 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800255 private static final int CMD_NV_READ_ITEM = 13;
256 private static final int EVENT_NV_READ_ITEM_DONE = 14;
257 private static final int CMD_NV_WRITE_ITEM = 15;
258 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
259 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
260 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700261 private static final int CMD_RESET_MODEM_CONFIG = 19;
262 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800263 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
264 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800265 private static final int CMD_SEND_ENVELOPE = 25;
266 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000267 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
268 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700269 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
270 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
271 private static final int CMD_EXCHANGE_SIM_IO = 31;
272 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800273 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
274 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700275 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
276 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700277 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
278 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700279 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
280 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
281 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
282 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700283 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
284 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
285 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
286 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700287 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800288 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
289 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000290 private static final int CMD_SWITCH_SLOTS = 50;
291 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700292 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
293 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
294 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
295 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
296 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
297 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
298 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
299 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700300 private static final int CMD_GET_ALL_CELL_INFO = 60;
301 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
302 private static final int CMD_GET_CELL_LOCATION = 62;
303 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700304 private static final int CMD_MODEM_REBOOT = 64;
305 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700306 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
307 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800308 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
309 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700310 private static final int CMD_GET_MODEM_STATUS = 70;
311 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700312 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
313 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700314 private static final int CMD_ERASE_MODEM_CONFIG = 74;
315 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800316 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
317 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
318 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
319 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800320 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
321 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800322 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800323 private static final int CMD_GET_CALL_FORWARDING = 83;
324 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
325 private static final int CMD_SET_CALL_FORWARDING = 85;
326 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
327 private static final int CMD_GET_CALL_WAITING = 87;
328 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
329 private static final int CMD_SET_CALL_WAITING = 89;
330 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700331 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
332 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
333 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
334 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700335 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
336 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800337 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
338 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800339 private static final int CMD_SET_DATA_THROTTLING = 99;
340 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800341 private static final int CMD_SET_SIM_POWER = 101;
342 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800343 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
344 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
345 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
346 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800347 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
348 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000349 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800350 private static final int CMD_GET_SLICING_CONFIG = 110;
351 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800352 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700353 private static final int CMD_ENABLE_VONR = 113;
354 private static final int EVENT_ENABLE_VONR_DONE = 114;
355 private static final int CMD_IS_VONR_ENABLED = 115;
356 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800358 // Parameters of select command.
359 private static final int SELECT_COMMAND = 0xA4;
360 private static final int SELECT_P1 = 0x04;
361 private static final int SELECT_P2 = 0;
362 private static final int SELECT_P3 = 0x10;
363
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 /** The singleton instance. */
365 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800366 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367
Wink Saville3ab207e2014-11-20 13:07:20 -0800368 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800370 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700371 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700373 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800375 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700377 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800378 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379
Peter Wangdafb9ac2020-01-15 14:13:38 -0800380 /** User Activity */
381 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800382 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
383
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700384 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
385
Derek Tan97ebb422014-09-05 16:55:38 -0700386 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
387 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800388 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800389 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700390
Michelecea4cf22018-12-21 15:00:11 -0800391 // String to store multi SIM allowed
392 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
393
Derek Tan740e1672017-06-27 14:56:27 -0700394 // The AID of ISD-R.
395 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
396
yinxub1bed742017-04-17 11:45:04 -0700397 private NetworkScanRequestTracker mNetworkScanRequestTracker;
398
David Kelly5e06a7f2018-03-12 14:10:59 +0000399 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
400 private static final int MANUFACTURER_CODE_LENGTH = 8;
401
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800402 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800403 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800404
Derek Tan89e89d42014-07-08 17:00:10 -0700405 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700406 * Experiment flag to enable erase modem config on reset network, default value is false
407 */
408 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
409 "reset_network_erase_modem_config_enabled";
410
Rambo Wang0f050d82021-02-12 11:43:36 -0800411 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjs0a502c42021-09-27 15:34:44 +0000412 /**
413 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
414 * one ICCID active at the same time.
415 * Apps should use below API signatures if targeting SDK is T and beyond.
416 *
417 * @hide
418 */
419 @ChangeId
420 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
421 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800422
Naina Nallurid63128d2019-09-17 14:10:30 -0700423 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 * A request object to use for transmitting data to an ICC.
425 */
426 private static final class IccAPDUArgument {
427 public int channel, cla, command, p1, p2, p3;
428 public String data;
429
430 public IccAPDUArgument(int channel, int cla, int command,
431 int p1, int p2, int p3, String data) {
432 this.channel = channel;
433 this.cla = cla;
434 this.command = command;
435 this.p1 = p1;
436 this.p2 = p2;
437 this.p3 = p3;
438 this.data = data;
439 }
440 }
441
442 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700443 * A request object to use for transmitting data to an ICC.
444 */
445 private static final class ManualNetworkSelectionArgument {
446 public OperatorInfo operatorInfo;
447 public boolean persistSelection;
448
449 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
450 this.operatorInfo = operatorInfo;
451 this.persistSelection = persistSelection;
452 }
453 }
454
455 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
457 * request after sending. The main thread will notify the request when it is complete.
458 */
459 private static final class MainThreadRequest {
460 /** The argument to use for the request */
461 public Object argument;
462 /** The result of the request that is run on the main thread */
463 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800464 // The subscriber id that this request applies to. Defaults to
465 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
466 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467
Nathan Harold92bed182018-10-12 18:16:49 -0700468 // In cases where subId is unavailable, the caller needs to specify the phone.
469 public Phone phone;
470
vagdeviaf9a5b92018-08-15 16:01:53 -0700471 public WorkSource workSource;
472
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 public MainThreadRequest(Object argument) {
474 this.argument = argument;
475 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800476
Nathan Harold92bed182018-10-12 18:16:49 -0700477 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
478 this.argument = argument;
479 if (phone != null) {
480 this.phone = phone;
481 }
482 this.workSource = workSource;
483 }
484
vagdeviaf9a5b92018-08-15 16:01:53 -0700485 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800486 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800487 if (subId != null) {
488 this.subId = subId;
489 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700490 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 }
493
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800494 private static final class IncomingThirdPartyCallArgs {
495 public final ComponentName component;
496 public final String callId;
497 public final String callerDisplayName;
498
499 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
500 String callerDisplayName) {
501 this.component = component;
502 this.callId = callId;
503 this.callerDisplayName = callerDisplayName;
504 }
505 }
506
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 /**
508 * A handler that processes messages on the main thread in the phone process. Since many
509 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
510 * inbound binder threads to the main thread in the phone process. The Binder thread
511 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
512 * on, which will be notified when the operation completes and will contain the result of the
513 * request.
514 *
515 * <p>If a MainThreadRequest object is provided in the msg.obj field,
516 * note that request.result must be set to something non-null for the calling thread to
517 * unblock.
518 */
519 private final class MainThreadHandler extends Handler {
520 @Override
521 public void handleMessage(Message msg) {
522 MainThreadRequest request;
523 Message onCompleted;
524 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000525 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800527 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528
529 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 case CMD_HANDLE_USSD_REQUEST: {
531 request = (MainThreadRequest) msg.obj;
532 final Phone phone = getPhoneFromRequest(request);
533 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
534 String ussdRequest = ussdObject.first;
535 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700536
Pengquan Menga1bb6272018-09-06 09:59:22 -0700537 if (!isUssdApiAllowed(request.subId)) {
538 // Carrier does not support use of this API, return failure.
539 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
540 UssdResponse response = new UssdResponse(ussdRequest, null);
541 Bundle returnData = new Bundle();
542 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
543 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700544
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 request.result = true;
546 notifyRequester(request);
547 return;
548 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700549
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 try {
551 request.result = phone != null
552 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
553 } catch (CallStateException cse) {
554 request.result = false;
555 }
556 // Wake up the requesting thread
557 notifyRequester(request);
558 break;
pkanwar32d516d2016-10-14 19:37:38 -0700559 }
560
Yorke Lee716f67e2015-06-17 15:39:16 -0700561 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700563 final Phone phone = getPhoneFromRequest(request);
564 request.result = phone != null ?
565 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
566 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000575 uiccPort = getUiccPortFromRequest(request);
576 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 loge("iccTransmitApduLogicalChannel: No UICC");
578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
582 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000583 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 iccArgument.channel, iccArgument.cla, iccArgument.command,
585 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 ar = (AsyncResult) msg.obj;
592 request = (MainThreadRequest) ar.userObj;
593 if (ar.exception == null && ar.result != null) {
594 request.result = ar.result;
595 } else {
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
597 if (ar.result == null) {
598 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800599 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800601 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 } else {
603 loge("iccTransmitApduLogicalChannel: Unknown exception");
604 }
605 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 break;
608
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
610 request = (MainThreadRequest) msg.obj;
611 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000612 uiccPort = getUiccPortFromRequest(request);
613 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 loge("iccTransmitApduBasicChannel: No UICC");
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 } else {
618 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
619 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000620 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
622 iccArgument.p3, iccArgument.data, onCompleted);
623 }
624 break;
625
626 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
627 ar = (AsyncResult) msg.obj;
628 request = (MainThreadRequest) ar.userObj;
629 if (ar.exception == null && ar.result != null) {
630 request.result = ar.result;
631 } else {
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
633 if (ar.result == null) {
634 loge("iccTransmitApduBasicChannel: Empty response");
635 } else if (ar.exception instanceof CommandException) {
636 loge("iccTransmitApduBasicChannel: CommandException: " +
637 ar.exception);
638 } else {
639 loge("iccTransmitApduBasicChannel: Unknown exception");
640 }
641 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 break;
644
645 case CMD_EXCHANGE_SIM_IO:
646 request = (MainThreadRequest) msg.obj;
647 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000648 uiccPort = getUiccPortFromRequest(request);
649 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 loge("iccExchangeSimIO: No UICC");
651 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 } else {
654 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
655 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000656 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
658 iccArgument.data, onCompleted);
659 }
660 break;
661
662 case EVENT_EXCHANGE_SIM_IO_DONE:
663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result;
667 } else {
668 request.result = new IccIoResult(0x6f, 0, (byte[])null);
669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 break;
672
Derek Tan4d5e5c12014-02-04 11:54:58 -0800673 case CMD_SEND_ENVELOPE:
674 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000675 uiccPort = getUiccPortFromRequest(request);
676 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 loge("sendEnvelopeWithStatus: No UICC");
678 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 } else {
681 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000682 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 break;
685
686 case EVENT_SEND_ENVELOPE_DONE:
687 ar = (AsyncResult) msg.obj;
688 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700689 if (ar.exception == null && ar.result != null) {
690 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800691 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700692 request.result = new IccIoResult(0x6F, 0, (byte[])null);
693 if (ar.result == null) {
694 loge("sendEnvelopeWithStatus: Empty response");
695 } else if (ar.exception instanceof CommandException) {
696 loge("sendEnvelopeWithStatus: CommandException: " +
697 ar.exception);
698 } else {
699 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
700 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800701 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700702 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 break;
704
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 case CMD_OPEN_CHANNEL:
706 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000707 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800708 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000709 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700710 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800711 request.result = new IccOpenLogicalChannelResponse(-1,
712 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700714 } else {
715 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000716 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800717 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 break;
720
721 case EVENT_OPEN_CHANNEL_DONE:
722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 int[] result = (int[]) ar.result;
727 int channelId = result[0];
728 byte[] selectResponse = null;
729 if (result.length > 1) {
730 selectResponse = new byte[result.length - 1];
731 for (int i = 1; i < result.length; ++i) {
732 selectResponse[i - 1] = (byte) result[i];
733 }
734 }
735 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700736 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 if (ar.result == null) {
739 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 if (ar.exception != null) {
742 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
743 }
744
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700745 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700746 if (ar.exception instanceof CommandException) {
747 CommandException.Error error =
748 ((CommandException) (ar.exception)).getCommandError();
749 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700750 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700751 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700752 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700753 }
754 }
755 openChannelResp = new IccOpenLogicalChannelResponse(
756 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700758 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 break;
761
762 case CMD_CLOSE_CHANNEL:
763 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000764 uiccPort = getUiccPortFromRequest(request);
765 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700766 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900767 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700768 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 } else {
770 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000771 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 break;
774
775 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800776 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
777 break;
778
779 case CMD_NV_READ_ITEM:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
783 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800784 break;
785
786 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800789 if (ar.exception == null && ar.result != null) {
790 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800792 request.result = "";
793 if (ar.result == null) {
794 loge("nvReadItem: Empty response");
795 } else if (ar.exception instanceof CommandException) {
796 loge("nvReadItem: CommandException: " +
797 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800799 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 }
801 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700802 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 break;
804
Jake Hambye994d462014-02-03 13:10:13 -0800805 case CMD_NV_WRITE_ITEM:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
808 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800809 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700810 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800811 break;
812
813 case EVENT_NV_WRITE_ITEM_DONE:
814 handleNullReturnEvent(msg, "nvWriteItem");
815 break;
816
817 case CMD_NV_WRITE_CDMA_PRL:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800820 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800821 break;
822
823 case EVENT_NV_WRITE_CDMA_PRL_DONE:
824 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
825 break;
826
chen xu6dac5ab2018-10-26 17:39:23 -0700827 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800828 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700829 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800830 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800831 break;
832
chen xu6dac5ab2018-10-26 17:39:23 -0700833 case EVENT_RESET_MODEM_CONFIG_DONE:
834 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800835 break;
836
Sooraj Sasindran37444802020-08-11 10:40:43 -0700837 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
838 request = (MainThreadRequest) msg.obj;
839 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
840 request);
841 Phone phone = getPhoneFromRequest(request);
842 if (phone != null) {
843 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
844 } else {
845 loge("isNRDualConnectivityEnabled: No phone object");
846 request.result = false;
847 notifyRequester(request);
848 }
849 break;
850 }
851
852 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 // request.result must be set to something non-null
859 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700860 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700861 request.result = ar.result;
862 } else {
863 request.result = false;
864 }
865 if (ar.result == null) {
866 loge("isNRDualConnectivityEnabled: Empty response");
867 } else if (ar.exception instanceof CommandException) {
868 loge("isNRDualConnectivityEnabled: CommandException: "
869 + ar.exception);
870 } else {
871 loge("isNRDualConnectivityEnabled: Unknown exception");
872 }
873 }
874 notifyRequester(request);
875 break;
876
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700877 case CMD_IS_VONR_ENABLED: {
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
880 request);
881 Phone phone = getPhoneFromRequest(request);
882 if (phone != null) {
883 phone.isVoNrEnabled(onCompleted, request.workSource);
884 } else {
885 loge("isVoNrEnabled: No phone object");
886 request.result = false;
887 notifyRequester(request);
888 }
889 break;
890 }
891
892 case EVENT_IS_VONR_ENABLED_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result;
897 } else {
898 // request.result must be set to something non-null
899 // for the calling thread to unblock
900 if (ar.result != null) {
901 request.result = ar.result;
902 } else {
903 request.result = false;
904 }
905 if (ar.result == null) {
906 loge("isVoNrEnabled: Empty response");
907 } else if (ar.exception instanceof CommandException) {
908 loge("isVoNrEnabled: CommandException: "
909 + ar.exception);
910 } else {
911 loge("isVoNrEnabled: Unknown exception");
912 }
913 }
914 notifyRequester(request);
915 break;
916
Sooraj Sasindran37444802020-08-11 10:40:43 -0700917 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
920 Phone phone = getPhoneFromRequest(request);
921 if (phone != null) {
922 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
923 request.workSource);
924 } else {
925 loge("enableNrDualConnectivity: No phone object");
926 request.result =
927 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
928 notifyRequester(request);
929 }
930 break;
931 }
932
933 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 if (ar.exception == null) {
937 request.result =
938 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
939 } else {
940 request.result =
941 TelephonyManager
942 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
943 if (ar.exception instanceof CommandException) {
944 CommandException.Error error =
945 ((CommandException) (ar.exception)).getCommandError();
946 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
947 request.result =
948 TelephonyManager
949 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000950 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
951 request.result =
952 TelephonyManager
953 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700954 }
955 loge("enableNrDualConnectivity" + ": CommandException: "
956 + ar.exception);
957 } else {
958 loge("enableNrDualConnectivity" + ": Unknown exception");
959 }
960 }
961 notifyRequester(request);
962 break;
963 }
964
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700965 case CMD_ENABLE_VONR: {
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
971 request.workSource);
972 } else {
973 loge("setVoNrEnabled: No phone object");
974 request.result =
975 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
976 notifyRequester(request);
977 }
978 break;
979 }
980
981 case EVENT_ENABLE_VONR_DONE: {
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception == null) {
985 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
986 } else {
987 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
988 if (ar.exception instanceof CommandException) {
989 CommandException.Error error =
990 ((CommandException) (ar.exception)).getCommandError();
991 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
992 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
993 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
994 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
995 } else {
996 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
997 }
998 loge("setVoNrEnabled" + ": CommandException: "
999 + ar.exception);
1000 } else {
1001 loge("setVoNrEnabled" + ": Unknown exception");
1002 }
1003 }
1004 notifyRequester(request);
1005 break;
1006 }
1007
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001009 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1011 request);
1012 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001013 break;
1014
SongFerngWang3ef3e072020-12-21 16:41:52 +08001015 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception == null && ar.result != null) {
1019 request.result = ar.result; // Integer
1020 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301021 // request.result must be set to something non-null
1022 // for the calling thread to unblock
1023 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001024 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001025 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001026 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001027 loge("getAllowedNetworkTypesBitmask: CommandException: "
1028 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 }
1032 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001033 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001034 break;
1035
SongFerngWang3ef3e072020-12-21 16:41:52 +08001036 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001037 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001038 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1039 request);
1040 Pair<Integer, Long> reasonWithNetworkTypes =
1041 (Pair<Integer, Long>) request.argument;
1042 getPhoneFromRequest(request).setAllowedNetworkTypes(
1043 reasonWithNetworkTypes.first,
1044 reasonWithNetworkTypes.second,
1045 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001046 break;
1047
SongFerngWang3ef3e072020-12-21 16:41:52 +08001048 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1049 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001050 break;
1051
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001052 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1053 request = (MainThreadRequest)msg.obj;
1054 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001055 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001056 break;
1057
1058 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1059 ar = (AsyncResult)msg.obj;
1060 request = (MainThreadRequest)ar.userObj;
1061 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001062 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001063 break;
1064
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001065 case CMD_SET_VOICEMAIL_NUMBER:
1066 request = (MainThreadRequest) msg.obj;
1067 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1068 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001069 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1070 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001071 break;
1072
1073 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1074 handleNullReturnEvent(msg, "setVoicemailNumber");
1075 break;
1076
Stuart Scott54788802015-03-30 13:18:01 -07001077 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1080 request);
1081 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1082 break;
1083
1084 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1085 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1086 break;
1087
Shishir Agrawal302c8692015-06-19 13:49:39 -07001088 case CMD_PERFORM_NETWORK_SCAN:
1089 request = (MainThreadRequest) msg.obj;
1090 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1091 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1092 break;
1093
Hall Liu27d24262020-09-18 19:04:59 -07001094 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001095 request = (MainThreadRequest) msg.obj;
1096 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001097 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1098 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1099 request.argument;
1100 int callForwardingReason = args.first;
1101 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001102 break;
Hall Liu27d24262020-09-18 19:04:59 -07001103 }
1104 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001107 TelephonyManager.CallForwardingInfoCallback callback =
1108 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1109 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001110 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001111 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001112 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1113 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1114 // Service Class is a bit mask per 3gpp 27.007. Search for
1115 // any service for voice call.
1116 if ((callForwardInfo.serviceClass
1117 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001118 callForwardingInfo = new CallForwardingInfo(
1119 callForwardInfo.status
1120 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001121 callForwardInfo.reason,
1122 callForwardInfo.number,
1123 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001124 break;
1125 }
1126 }
1127 // Didn't find a call forward info for voice call.
1128 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001129 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1130 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001131 }
Hall Liu27d24262020-09-18 19:04:59 -07001132 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 } else {
1134 if (ar.result == null) {
1135 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1136 }
1137 if (ar.exception != null) {
1138 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1139 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001140 int errorCode = TelephonyManager
1141 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001142 if (ar.exception instanceof CommandException) {
1143 CommandException.Error error =
1144 ((CommandException) (ar.exception)).getCommandError();
1145 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001146 errorCode = TelephonyManager
1147 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001148 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001149 errorCode = TelephonyManager
1150 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001151 }
1152 }
Hall Liu27d24262020-09-18 19:04:59 -07001153 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001154 }
Shuo Qian4a594052020-01-23 11:59:30 -08001155 break;
Hall Liu27d24262020-09-18 19:04:59 -07001156 }
Shuo Qian4a594052020-01-23 11:59:30 -08001157
Hall Liu27d24262020-09-18 19:04:59 -07001158 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001161 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001162 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001163 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1164 request.argument).first;
1165 request.phone.setCallForwardingOption(
1166 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001167 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001168 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001169 callForwardingInfoToSet.getReason(),
1170 callForwardingInfoToSet.getNumber(),
1171 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1172 break;
Hall Liu27d24262020-09-18 19:04:59 -07001173 }
Shuo Qian4a594052020-01-23 11:59:30 -08001174
Hall Liu27d24262020-09-18 19:04:59 -07001175 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001176 ar = (AsyncResult) msg.obj;
1177 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001178 Consumer<Integer> callback =
1179 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1180 request.argument).second;
1181 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001182 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001183 int errorCode = TelephonyManager.CallForwardingInfoCallback
1184 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001185 if (ar.exception instanceof CommandException) {
1186 CommandException.Error error =
1187 ((CommandException) (ar.exception)).getCommandError();
1188 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001189 errorCode = TelephonyManager.CallForwardingInfoCallback
1190 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001191 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001192 errorCode = TelephonyManager.CallForwardingInfoCallback
1193 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001194 }
1195 }
1196 callback.accept(errorCode);
1197 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001198 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001199 }
Shuo Qian4a594052020-01-23 11:59:30 -08001200 break;
Hall Liu27d24262020-09-18 19:04:59 -07001201 }
Shuo Qian4a594052020-01-23 11:59:30 -08001202
Hall Liu27d24262020-09-18 19:04:59 -07001203 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1206 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1207 break;
Hall Liu27d24262020-09-18 19:04:59 -07001208 }
Shuo Qian4a594052020-01-23 11:59:30 -08001209
Hall Liu27d24262020-09-18 19:04:59 -07001210 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001213 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001214 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1215 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001216 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001217 // Service Class is a bit mask per 3gpp 27.007.
1218 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001219 if (callForwardResults.length > 1
1220 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001221 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001222 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001223 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1224 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001226 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 }
1228 } else {
1229 if (ar.result == null) {
1230 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1231 }
1232 if (ar.exception != null) {
1233 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1234 }
1235 if (ar.exception instanceof CommandException) {
1236 CommandException.Error error =
1237 ((CommandException) (ar.exception)).getCommandError();
1238 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1239 callForwardingStatus =
1240 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1241 }
1242 }
1243 }
Hall Liu27d24262020-09-18 19:04:59 -07001244 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 break;
Hall Liu27d24262020-09-18 19:04:59 -07001246 }
Shuo Qian4a594052020-01-23 11:59:30 -08001247
Hall Liu27d24262020-09-18 19:04:59 -07001248 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001249 request = (MainThreadRequest) msg.obj;
1250 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001251 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1252 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001253 break;
Hall Liu27d24262020-09-18 19:04:59 -07001254 }
Shuo Qian4a594052020-01-23 11:59:30 -08001255
Hall Liu27d24262020-09-18 19:04:59 -07001256 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001257 ar = (AsyncResult) msg.obj;
1258 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001259 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1260 Consumer<Integer> callback =
1261 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1262 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001263 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001264 if (ar.exception instanceof CommandException) {
1265 CommandException.Error error =
1266 ((CommandException) (ar.exception)).getCommandError();
1267 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1268 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1269 } else {
1270 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1271 }
1272 } else {
1273 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1274 }
1275 } else {
1276 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1277 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279 break;
Hall Liu27d24262020-09-18 19:04:59 -07001280 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001281 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 CellNetworkScanResult cellScanResult;
1285 if (ar.exception == null && ar.result != null) {
1286 cellScanResult = new CellNetworkScanResult(
1287 CellNetworkScanResult.STATUS_SUCCESS,
1288 (List<OperatorInfo>) ar.result);
1289 } else {
1290 if (ar.result == null) {
1291 loge("getCellNetworkScanResults: Empty response");
1292 }
1293 if (ar.exception != null) {
1294 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1295 }
1296 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1297 if (ar.exception instanceof CommandException) {
1298 CommandException.Error error =
1299 ((CommandException) (ar.exception)).getCommandError();
1300 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1301 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1302 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1303 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1304 }
1305 }
1306 cellScanResult = new CellNetworkScanResult(errorCode, null);
1307 }
1308 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001309 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001310 break;
1311
1312 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1313 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001314 ManualNetworkSelectionArgument selArg =
1315 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001316 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1317 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001318 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1319 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001320 break;
1321
1322 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001323 ar = (AsyncResult) msg.obj;
1324 request = (MainThreadRequest) ar.userObj;
1325 if (ar.exception == null) {
1326 request.result = true;
1327 } else {
1328 request.result = false;
1329 loge("setNetworkSelectionModeManual " + ar.exception);
1330 }
1331 notifyRequester(request);
1332 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001333 break;
1334
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001335 case CMD_GET_MODEM_ACTIVITY_INFO:
1336 request = (MainThreadRequest) msg.obj;
1337 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001338 if (defaultPhone != null) {
1339 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001340 } else {
1341 ResultReceiver result = (ResultReceiver) request.argument;
1342 Bundle bundle = new Bundle();
1343 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001344 new ModemActivityInfo(0, 0, 0,
1345 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001346 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001347 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001348 break;
1349
Hall Liud0f208c2020-10-14 16:54:44 -07001350 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001351 ar = (AsyncResult) msg.obj;
1352 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001353 ResultReceiver result = (ResultReceiver) request.argument;
1354
Hall Liud0f208c2020-10-14 16:54:44 -07001355 ModemActivityInfo ret = null;
1356 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001357 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001358 // Update the last modem activity info and the result of the request.
1359 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1360 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001361 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001362 int[] txTimeMs = info.getTransmitTimeMillis();
1363 int[] lastModemTxTimeMs = mLastModemActivityInfo
1364 .getTransmitTimeMillis();
1365 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1366 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1367 }
Hall Liu49656c02020-10-09 19:00:11 -07001368 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001369 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1370 + mLastModemActivityInfo.getSleepTimeMillis());
1371 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1372 + mLastModemActivityInfo.getIdleTimeMillis());
1373 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1374 mLastModemActivityInfo.setReceiveTimeMillis(
1375 info.getReceiveTimeMillis()
1376 + mLastModemActivityInfo.getReceiveTimeMillis());
1377 }
Hall Liu49656c02020-10-09 19:00:11 -07001378 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001379 mLastModemActivityInfo.getSleepTimeMillis(),
1380 mLastModemActivityInfo.getIdleTimeMillis(),
1381 mLastModemActivityInfo.getTransmitTimeMillis(),
1382 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001383 } else {
1384 if (ar.result == null) {
1385 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001386 error = TelephonyManager.ModemActivityInfoException
1387 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388 } else if (ar.exception instanceof CommandException) {
1389 loge("queryModemActivityInfo: CommandException: " +
1390 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001391 error = TelephonyManager.ModemActivityInfoException
1392 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001393 } else {
1394 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001395 error = TelephonyManager.ModemActivityInfoException
1396 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001397 }
1398 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001399 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001400 if (ret != null) {
1401 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1402 } else {
1403 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1404 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001405 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001406 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001407 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001408 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001409
Meng Wang1a7c35a2016-05-05 20:56:15 -07001410 case CMD_SET_ALLOWED_CARRIERS:
1411 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001412 CarrierRestrictionRules argument =
1413 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001414 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001415 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001416 break;
1417
1418 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception == null && ar.result != null) {
1422 request.result = ar.result;
1423 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001424 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1425 if (ar.exception instanceof CommandException) {
1426 loge("setAllowedCarriers: CommandException: " + ar.exception);
1427 CommandException.Error error =
1428 ((CommandException) (ar.exception)).getCommandError();
1429 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1430 request.result =
1431 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1432 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001433 } else {
1434 loge("setAllowedCarriers: Unknown exception");
1435 }
1436 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001437 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001438 break;
1439
1440 case CMD_GET_ALLOWED_CARRIERS:
1441 request = (MainThreadRequest) msg.obj;
1442 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001443 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001444 break;
1445
1446 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 if (ar.exception == null && ar.result != null) {
1450 request.result = ar.result;
1451 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001452 request.result = new IllegalStateException(
1453 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001454 if (ar.result == null) {
1455 loge("getAllowedCarriers: Empty response");
1456 } else if (ar.exception instanceof CommandException) {
1457 loge("getAllowedCarriers: CommandException: " +
1458 ar.exception);
1459 } else {
1460 loge("getAllowedCarriers: Unknown exception");
1461 }
1462 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001463 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001464 break;
1465
Nathan Haroldb3014052017-01-25 15:57:32 -08001466 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 if (ar.exception == null && ar.result != null) {
1470 request.result = ar.result;
1471 } else {
1472 request.result = new IllegalArgumentException(
1473 "Failed to retrieve Forbidden Plmns");
1474 if (ar.result == null) {
1475 loge("getForbiddenPlmns: Empty response");
1476 } else {
1477 loge("getForbiddenPlmns: Unknown exception");
1478 }
1479 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001481 break;
1482
1483 case CMD_GET_FORBIDDEN_PLMNS:
1484 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001485 uiccPort = getUiccPortFromRequest(request);
1486 if (uiccPort == null) {
1487 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001488 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001489 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001490 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001491 break;
1492 }
1493 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001494 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001495 if (uiccApp == null) {
1496 loge("getForbiddenPlmns() no app with specified type -- "
1497 + appType);
1498 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001499 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001500 break;
1501 } else {
1502 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1503 + " specified type -- " + appType);
1504 }
1505 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1506 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1507 onCompleted);
1508 break;
1509
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001510 case CMD_SWITCH_SLOTS:
1511 request = (MainThreadRequest) msg.obj;
1512 int[] physicalSlots = (int[]) request.argument;
1513 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1514 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1515 break;
1516
1517 case EVENT_SWITCH_SLOTS_DONE:
1518 ar = (AsyncResult) msg.obj;
1519 request = (MainThreadRequest) ar.userObj;
1520 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
1522 break;
1523 case CMD_GET_NETWORK_SELECTION_MODE:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1526 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1527 break;
1528
1529 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 if (ar.exception != null) {
1533 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1534 } else {
1535 int mode = ((int[]) ar.result)[0];
1536 if (mode == 0) {
1537 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1538 } else {
1539 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1540 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001541 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001542 notifyRequester(request);
1543 break;
1544 case CMD_GET_CDMA_ROAMING_MODE:
1545 request = (MainThreadRequest) msg.obj;
1546 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1547 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1548 break;
1549 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception != null) {
1553 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1554 } else {
1555 request.result = ((int[]) ar.result)[0];
1556 }
1557 notifyRequester(request);
1558 break;
1559 case CMD_SET_CDMA_ROAMING_MODE:
1560 request = (MainThreadRequest) msg.obj;
1561 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1562 int mode = (int) request.argument;
1563 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1564 break;
1565 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 request.result = ar.exception == null;
1569 notifyRequester(request);
1570 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001571 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1574 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1575 break;
1576 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 if (ar.exception != null) {
1580 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1581 } else {
1582 request.result = ((int[]) ar.result)[0];
1583 }
1584 notifyRequester(request);
1585 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001586 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1587 request = (MainThreadRequest) msg.obj;
1588 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1589 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001590 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1591 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001592 break;
1593 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1594 ar = (AsyncResult) msg.obj;
1595 request = (MainThreadRequest) ar.userObj;
1596 request.result = ar.exception == null;
1597 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001598 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001599 case CMD_GET_ALL_CELL_INFO:
1600 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001601 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001602 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001603 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 case EVENT_GET_ALL_CELL_INFO_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001607 // If a timeout occurs, the response will be null
1608 request.result = (ar.exception == null && ar.result != null)
1609 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001610 synchronized (request) {
1611 request.notifyAll();
1612 }
1613 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001614 case CMD_REQUEST_CELL_INFO_UPDATE:
1615 request = (MainThreadRequest) msg.obj;
1616 request.phone.requestCellInfoUpdate(request.workSource,
1617 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1618 break;
1619 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1623 try {
1624 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001625 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001626 cb.onError(
1627 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1628 ar.exception.getClass().getName(),
1629 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001630 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001631 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001632 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001633 } else {
1634 // use the result as returned
1635 cb.onCellInfo((List<CellInfo>) ar.result);
1636 }
1637 } catch (RemoteException re) {
1638 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1639 }
1640 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001641 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001642 request = (MainThreadRequest) msg.obj;
1643 WorkSource ws = (WorkSource) request.argument;
1644 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001645 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001646 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001647 }
1648 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 ar = (AsyncResult) msg.obj;
1650 request = (MainThreadRequest) ar.userObj;
1651 if (ar.exception == null) {
1652 request.result = ar.result;
1653 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001654 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001655 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001656 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001657 }
1658
1659 synchronized (request) {
1660 request.notifyAll();
1661 }
1662 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001663 }
chen xu6dac5ab2018-10-26 17:39:23 -07001664 case CMD_MODEM_REBOOT:
1665 request = (MainThreadRequest) msg.obj;
1666 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001667 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001668 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001669 case EVENT_CMD_MODEM_REBOOT_DONE:
1670 handleNullReturnEvent(msg, "rebootModem");
1671 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001672 case CMD_REQUEST_ENABLE_MODEM:
1673 request = (MainThreadRequest) msg.obj;
1674 boolean enable = (boolean) request.argument;
1675 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001676 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001677 PhoneConfigurationManager.getInstance()
1678 .enablePhone(request.phone, enable, onCompleted);
1679 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001680 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001684 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001685 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001686 if ((boolean) request.result) {
1687 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1688 updateModemStateMetrics();
1689 } else {
1690 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1691 + ar.exception);
1692 }
1693 notifyRequester(request);
1694 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001695 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001696 case CMD_GET_MODEM_STATUS:
1697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1699 PhoneConfigurationManager.getInstance()
1700 .getPhoneStatusFromModem(request.phone, onCompleted);
1701 break;
1702 case EVENT_GET_MODEM_STATUS_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 int id = request.phone.getPhoneId();
1706 if (ar.exception == null && ar.result != null) {
1707 request.result = ar.result;
1708 //update the cache as modem status has changed
1709 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1710 (boolean) request.result);
1711 } else {
1712 // Return true if modem status cannot be retrieved. For most cases,
1713 // modem status is on. And for older version modems, GET_MODEM_STATUS
1714 // and disable modem are not supported. Modem is always on.
1715 // TODO: this should be fixed in R to support a third
1716 // status UNKNOWN b/131631629
1717 request.result = true;
1718 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1719 + ar.exception);
1720 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001721 notifyRequester(request);
1722 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001723 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1726 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1727 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1728 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1729 break;
1730 }
1731 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1732 ar = (AsyncResult) msg.obj;
1733 request = (MainThreadRequest) ar.userObj;
1734 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1735 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1736 args.second.accept(ar.exception == null);
1737 notifyRequester(request);
1738 break;
1739 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001740 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1741 request = (MainThreadRequest) msg.obj;
1742 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1743 Phone phone = getPhoneFromRequest(request);
1744 if (phone != null) {
1745 phone.getSystemSelectionChannels(onCompleted);
1746 } else {
1747 loge("getSystemSelectionChannels: No phone object");
1748 request.result = new ArrayList<RadioAccessSpecifier>();
1749 notifyRequester(request);
1750 }
1751 break;
1752 }
1753 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756 if (ar.exception == null && ar.result != null) {
1757 request.result = ar.result;
1758 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001759 request.result = new IllegalStateException(
1760 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001761 if (ar.result == null) {
1762 loge("getSystemSelectionChannels: Empty response");
1763 } else {
1764 loge("getSystemSelectionChannels: Unknown exception");
1765 }
1766 }
1767 notifyRequester(request);
1768 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001769 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1770 ar = (AsyncResult) msg.obj;
1771 request = (MainThreadRequest) ar.userObj;
1772 if (ar.exception == null && ar.result != null) {
1773 request.result = ar.result;
1774 } else {
1775 request.result = -1;
1776 loge("Failed to set Forbidden Plmns");
1777 if (ar.result == null) {
1778 loge("setForbidenPlmns: Empty response");
1779 } else if (ar.exception != null) {
1780 loge("setForbiddenPlmns: Exception: " + ar.exception);
1781 request.result = -1;
1782 } else {
1783 loge("setForbiddenPlmns: Unknown exception");
1784 }
1785 }
1786 notifyRequester(request);
1787 break;
1788 case CMD_SET_FORBIDDEN_PLMNS:
1789 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001790 uiccPort = getUiccPortFromRequest(request);
1791 if (uiccPort == null) {
1792 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001793 request.result = -1;
1794 notifyRequester(request);
1795 break;
1796 }
1797 Pair<Integer, List<String>> setFplmnsArgs =
1798 (Pair<Integer, List<String>>) request.argument;
1799 appType = setFplmnsArgs.first;
1800 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001801 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001802 if (uiccApp == null) {
1803 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1804 request.result = -1;
1805 loge("Failed to get UICC App");
1806 notifyRequester(request);
1807 } else {
1808 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1809 ((SIMRecords) uiccApp.getIccRecords())
1810 .setForbiddenPlmns(onCompleted, fplmns);
1811 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001812 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001813 case CMD_ERASE_MODEM_CONFIG:
1814 request = (MainThreadRequest) msg.obj;
1815 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1816 defaultPhone.eraseModemConfig(onCompleted);
1817 break;
1818 case EVENT_ERASE_MODEM_CONFIG_DONE:
1819 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001820 break;
zoey chene02881a2019-12-30 16:11:23 +08001821
Kai Shif70f46f2021-03-03 13:59:46 -08001822 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1823 request = (MainThreadRequest) msg.obj;
1824 request.result = defaultPhone.eraseDataInSharedPreferences();
1825 notifyRequester(request);
1826 break;
1827
zoey chene02881a2019-12-30 16:11:23 +08001828 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1829 request = (MainThreadRequest) msg.obj;
1830 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1831 Pair<String, String> changed = (Pair<String, String>) request.argument;
1832 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1833 changed.first, changed.second, onCompleted);
1834 break;
1835 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 if (ar.exception == null) {
1839 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001840 // If the operation is successful, update the PIN storage
1841 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1842 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001843 UiccController.getInstance().getPinStorage()
1844 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001845 } else {
1846 request.result = msg.arg1;
1847 }
1848 notifyRequester(request);
1849 break;
1850
Michele Berionne5e411512020-11-13 02:36:59 +00001851 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001852 request = (MainThreadRequest) msg.obj;
1853 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1854 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1855 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1856 enabled.first, enabled.second, onCompleted);
1857 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001858 }
zoey chene02881a2019-12-30 16:11:23 +08001859 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1860 ar = (AsyncResult) msg.obj;
1861 request = (MainThreadRequest) ar.userObj;
1862 if (ar.exception == null) {
1863 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001864 // If the operation is successful, update the PIN storage
1865 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1866 int phoneId = getPhoneFromRequest(request).getPhoneId();
1867 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001868 UiccController.getInstance().getPinStorage()
1869 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001870 } else {
1871 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1872 }
zoey chene02881a2019-12-30 16:11:23 +08001873 } else {
1874 request.result = msg.arg1;
1875 }
Michele Berionne5e411512020-11-13 02:36:59 +00001876
1877
zoey chene02881a2019-12-30 16:11:23 +08001878 notifyRequester(request);
1879 break;
1880
Peter Wangdafb9ac2020-01-15 14:13:38 -08001881 case MSG_NOTIFY_USER_ACTIVITY:
1882 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001883 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001884 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1885 getDefaultPhone().getContext().sendBroadcastAsUser(
1886 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1887 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001888
1889 case CMD_SET_DATA_THROTTLING: {
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1892 DataThrottlingRequest dataThrottlingRequest =
1893 (DataThrottlingRequest) request.argument;
1894 Phone phone = getPhoneFromRequest(request);
1895 if (phone != null) {
1896 phone.setDataThrottling(onCompleted,
1897 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1898 dataThrottlingRequest.getCompletionDurationMillis());
1899 } else {
1900 loge("setDataThrottling: No phone object");
1901 request.result =
1902 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1903 notifyRequester(request);
1904 }
1905
1906 break;
1907 }
1908 case EVENT_SET_DATA_THROTTLING_DONE:
1909 ar = (AsyncResult) msg.obj;
1910 request = (MainThreadRequest) ar.userObj;
1911
1912 if (ar.exception == null) {
1913 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1914 } else if (ar.exception instanceof CommandException) {
1915 loge("setDataThrottling: CommandException: " + ar.exception);
1916 CommandException.Error error =
1917 ((CommandException) (ar.exception)).getCommandError();
1918
1919 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1920 request.result = TelephonyManager
1921 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1922 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1923 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001924 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1925 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001926 } else {
1927 request.result =
1928 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1929 }
1930 } else {
1931 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1932 }
1933 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1934 notifyRequester(request);
1935 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001936
1937 case CMD_SET_SIM_POWER: {
1938 request = (MainThreadRequest) msg.obj;
1939 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1940 request = (MainThreadRequest) msg.obj;
1941 int stateToSet =
1942 ((Pair<Integer, IIntegerConsumer>)
1943 request.argument).first;
1944 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1945 break;
1946 }
1947 case EVENT_SET_SIM_POWER_DONE: {
1948 ar = (AsyncResult) msg.obj;
1949 request = (MainThreadRequest) ar.userObj;
1950 IIntegerConsumer callback =
1951 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1952 if (ar.exception != null) {
1953 loge("setSimPower exception: " + ar.exception);
1954 int errorCode = TelephonyManager.CallForwardingInfoCallback
1955 .RESULT_ERROR_UNKNOWN;
1956 if (ar.exception instanceof CommandException) {
1957 CommandException.Error error =
1958 ((CommandException) (ar.exception)).getCommandError();
1959 if (error == CommandException.Error.SIM_ERR) {
1960 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1961 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1962 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1963 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1964 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1965 } else {
1966 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1967 }
1968 }
1969 try {
1970 callback.accept(errorCode);
1971 } catch (RemoteException e) {
1972 // Ignore if the remote process is no longer available to call back.
1973 Log.w(LOG_TAG, "setSimPower: callback not available.");
1974 }
1975 } else {
1976 try {
1977 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1978 } catch (RemoteException e) {
1979 // Ignore if the remote process is no longer available to call back.
1980 Log.w(LOG_TAG, "setSimPower: callback not available.");
1981 }
1982 }
1983 break;
1984 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001985 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1986 request = (MainThreadRequest) msg.obj;
1987
1988 final Phone phone = getPhoneFromRequest(request);
1989 if (phone == null || phone.getServiceStateTracker() == null) {
1990 request.result = new IllegalStateException("Phone or SST is null");
1991 notifyRequester(request);
1992 break;
1993 }
1994
1995 Pair<Integer, SignalStrengthUpdateRequest> pair =
1996 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1997 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1998 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001999 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002000 request.subId, pair.first /*callingUid*/,
2001 pair.second /*request*/, onCompleted);
2002 break;
2003 }
2004 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2005 ar = (AsyncResult) msg.obj;
2006 request = (MainThreadRequest) ar.userObj;
2007 // request.result will be the exception of ar if present, true otherwise.
2008 // Be cautious not to leave result null which will wait() forever
2009 request.result = ar.exception != null ? ar.exception : true;
2010 notifyRequester(request);
2011 break;
2012 }
2013 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2014 request = (MainThreadRequest) msg.obj;
2015
2016 Phone phone = getPhoneFromRequest(request);
2017 if (phone == null || phone.getServiceStateTracker() == null) {
2018 request.result = new IllegalStateException("Phone or SST is null");
2019 notifyRequester(request);
2020 break;
2021 }
2022
2023 Pair<Integer, SignalStrengthUpdateRequest> pair =
2024 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2025 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2026 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002027 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002028 request.subId, pair.first /*callingUid*/,
2029 pair.second /*request*/, onCompleted);
2030 break;
2031 }
2032 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2033 ar = (AsyncResult) msg.obj;
2034 request = (MainThreadRequest) ar.userObj;
2035 request.result = ar.exception != null ? ar.exception : true;
2036 notifyRequester(request);
2037 break;
2038 }
Jordan Liu109698e2020-11-24 14:50:34 -08002039
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002040 case CMD_GET_SLICING_CONFIG: {
2041 request = (MainThreadRequest) msg.obj;
2042 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2043 request.phone.getSlicingConfig(onCompleted);
2044 break;
2045 }
2046 case EVENT_GET_SLICING_CONFIG_DONE: {
2047 ar = (AsyncResult) msg.obj;
2048 request = (MainThreadRequest) ar.userObj;
2049 ResultReceiver result = (ResultReceiver) request.argument;
2050
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002051 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002052 Bundle bundle = new Bundle();
2053 int resultCode = 0;
2054 if (ar.exception != null) {
2055 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2056 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002057 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002058 } else if (ar.result == null) {
2059 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002060 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002061 } else {
2062 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002063 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2064 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002065 }
2066
2067 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002068 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002069 }
2070 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2071 result.send(resultCode, bundle);
2072 notifyRequester(request);
2073 break;
2074 }
2075
Michele Berionne5e411512020-11-13 02:36:59 +00002076 case CMD_PREPARE_UNATTENDED_REBOOT:
2077 request = (MainThreadRequest) msg.obj;
2078 request.result =
2079 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2080 notifyRequester(request);
2081 break;
2082
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 default:
2084 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2085 break;
2086 }
2087 }
Jake Hambye994d462014-02-03 13:10:13 -08002088
Pengquan Menga1bb6272018-09-06 09:59:22 -07002089 private void notifyRequester(MainThreadRequest request) {
2090 synchronized (request) {
2091 request.notifyAll();
2092 }
2093 }
2094
Jake Hambye994d462014-02-03 13:10:13 -08002095 private void handleNullReturnEvent(Message msg, String command) {
2096 AsyncResult ar = (AsyncResult) msg.obj;
2097 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2098 if (ar.exception == null) {
2099 request.result = true;
2100 } else {
2101 request.result = false;
2102 if (ar.exception instanceof CommandException) {
2103 loge(command + ": CommandException: " + ar.exception);
2104 } else {
2105 loge(command + ": Unknown exception");
2106 }
2107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002108 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111
2112 /**
2113 * Posts the specified command to be executed on the main thread,
2114 * waits for the request to complete, and returns the result.
2115 * @see #sendRequestAsync
2116 */
2117 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002118 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2119 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002120 }
2121
2122 /**
2123 * Posts the specified command to be executed on the main thread,
2124 * waits for the request to complete, and returns the result.
2125 * @see #sendRequestAsync
2126 */
2127 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2128 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002129 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002130 }
2131
2132 /**
2133 * Posts the specified command to be executed on the main thread,
2134 * waits for the request to complete, and returns the result.
2135 * @see #sendRequestAsync
2136 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002137 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002138 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2139 }
2140
2141 /**
2142 * Posts the specified command to be executed on the main thread,
2143 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2144 * if not timeout or null otherwise.
2145 * @see #sendRequestAsync
2146 */
2147 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2148 long timeoutInMs) {
2149 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002150 }
2151
2152 /**
2153 * Posts the specified command to be executed on the main thread,
2154 * waits for the request to complete, and returns the result.
2155 * @see #sendRequestAsync
2156 */
Nathan Harold92bed182018-10-12 18:16:49 -07002157 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002158 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002159 }
2160
2161 /**
2162 * Posts the specified command to be executed on the main thread,
2163 * waits for the request to complete, and returns the result.
2164 * @see #sendRequestAsync
2165 */
2166 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002167 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2168 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002169 }
2170
2171 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002172 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2173 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2174 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002175 * @see #sendRequestAsync
2176 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002177 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2178 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2180 throw new RuntimeException("This method will deadlock if called from the main thread.");
2181 }
2182
Nathan Harold92bed182018-10-12 18:16:49 -07002183 MainThreadRequest request = null;
2184 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2185 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2186 } else if (phone != null) {
2187 request = new MainThreadRequest(argument, phone, workSource);
2188 } else {
2189 request = new MainThreadRequest(argument, subId, workSource);
2190 }
2191
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 Message msg = mMainThreadHandler.obtainMessage(command, request);
2193 msg.sendToTarget();
2194
Rambo Wang0f050d82021-02-12 11:43:36 -08002195
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002197 if (timeoutInMs >= 0) {
2198 // Wait for at least timeoutInMs before returning null request result
2199 long now = SystemClock.elapsedRealtime();
2200 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002201 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002202 try {
2203 request.wait(deadline - now);
2204 } catch (InterruptedException e) {
2205 // Do nothing, go back and check if request is completed or timeout
2206 } finally {
2207 now = SystemClock.elapsedRealtime();
2208 }
2209 }
2210 } else {
2211 // Wait for the request to complete
2212 while (request.result == null) {
2213 try {
2214 request.wait();
2215 } catch (InterruptedException e) {
2216 // Do nothing, go back and wait until the request is complete
2217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219 }
2220 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002221 if (request.result == null) {
2222 Log.wtf(LOG_TAG,
2223 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 return request.result;
2226 }
2227
2228 /**
2229 * Asynchronous ("fire and forget") version of sendRequest():
2230 * Posts the specified command to be executed on the main thread, and
2231 * returns immediately.
2232 * @see #sendRequest
2233 */
2234 private void sendRequestAsync(int command) {
2235 mMainThreadHandler.sendEmptyMessage(command);
2236 }
2237
2238 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002239 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002240 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002241 */
2242 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 sendRequestAsync(command, argument, null, null);
2244 }
2245
2246 /**
2247 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2248 * @see {@link #sendRequest(int,Object)}
2249 */
2250 private void sendRequestAsync(
2251 int command, Object argument, Phone phone, WorkSource workSource) {
2252 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002253 Message msg = mMainThreadHandler.obtainMessage(command, request);
2254 msg.sendToTarget();
2255 }
2256
2257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 * Initialize the singleton PhoneInterfaceManager instance.
2259 * This is only done once, at startup, from PhoneApp.onCreate().
2260 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002261 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 synchronized (PhoneInterfaceManager.class) {
2263 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002264 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 } else {
2266 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2267 }
2268 return sInstance;
2269 }
2270 }
2271
2272 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002273 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002276 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002277 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002279 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002281 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002282 mTelephonySharedPreferences =
2283 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002284 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002285 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002286 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002287 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002288
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 publish();
2290 }
2291
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002292 private Phone getDefaultPhone() {
2293 Phone thePhone = getPhone(getDefaultSubscription());
2294 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2295 }
2296
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 private void publish() {
2298 if (DBG) log("publish: " + this);
2299
Peter Wangc035ce42020-01-08 21:00:22 -08002300 TelephonyFrameworkInitializer
2301 .getTelephonyServiceManager()
2302 .getTelephonyServiceRegisterer()
2303 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 }
2305
Stuart Scott584921c2015-01-15 17:10:34 -08002306 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002307 if (request.phone != null) {
2308 return request.phone;
2309 } else {
2310 return getPhoneFromSubId(request.subId);
2311 }
2312 }
2313
2314 private Phone getPhoneFromSubId(int subId) {
2315 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2316 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002317 }
2318
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002319 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002320 Phone phone = getPhoneFromRequest(request);
2321 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002322 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002323 }
2324
Wink Saville36469e72014-06-11 15:17:00 -07002325 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002326 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002327 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329
Kai Shif70f46f2021-03-03 13:59:46 -08002330 private void sendEraseModemConfig(@NonNull Phone phone) {
2331 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2332 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2333 }
2334
2335 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2336 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2337 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002338 }
2339
Peter Wang44b186e2020-01-13 23:33:09 -08002340 private boolean isImsAvailableOnDevice() {
2341 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2342 if (pm == null) {
2343 // For some reason package manger is not available.. This will fail internally anyway,
2344 // so do not throw error and allow.
2345 return true;
2346 }
2347 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2348 }
2349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002351 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002352 }
2353
Wink Savilleb564aae2014-10-23 10:18:09 -07002354 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 if (DBG) log("dial: " + number);
2356 // No permission check needed here: This is just a wrapper around the
2357 // ACTION_DIAL intent, which is available to any app since it puts up
2358 // the UI before it does anything.
2359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 String url = createTelUrl(number);
2363 if (url == null) {
2364 return;
2365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367 // PENDING: should we just silently fail if phone is offhook or ringing?
2368 PhoneConstants.State state = mCM.getState(subId);
2369 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2370 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2371 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2372 mApp.startActivity(intent);
2373 }
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 }
2377 }
2378
2379 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002380 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
2382
Wink Savilleb564aae2014-10-23 10:18:09 -07002383 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 if (DBG) log("call: " + number);
2385
2386 // This is just a wrapper around the ACTION_CALL intent, but we still
2387 // need to do a permission check since we're calling startActivity()
2388 // from the context of the phone app.
2389 enforceCallPermission();
2390
Jordan Liu1617b712019-07-10 15:06:26 -07002391 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 != AppOpsManager.MODE_ALLOWED) {
2393 return;
2394 }
2395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 String url = createTelUrl(number);
2399 if (url == null) {
2400 return;
2401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002403 boolean isValid = false;
2404 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2405 if (slist != null) {
2406 for (SubscriptionInfo subInfoRecord : slist) {
2407 if (subInfoRecord.getSubscriptionId() == subId) {
2408 isValid = true;
2409 break;
2410 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002411 }
Wink Saville08874612014-08-31 19:19:58 -07002412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002413 if (!isValid) {
2414 return;
2415 }
Wink Saville08874612014-08-31 19:19:58 -07002416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2418 intent.putExtra(SUBSCRIPTION_KEY, subId);
2419 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2420 mApp.startActivity(intent);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
2423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
2425
Wink Savilleb564aae2014-10-23 10:18:09 -07002426 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002427 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002428 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2429 }
2430
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002432 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002433 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2434 }
2435
Wink Savilleb564aae2014-10-23 10:18:09 -07002436 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438
2439 final long identity = Binder.clearCallingIdentity();
2440 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002441 Phone phone = getPhone(subId);
2442 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443 checkSimPin.start();
2444 return checkSimPin.unlockSim(null, pin);
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
2447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
2449
Wink Savilleb564aae2014-10-23 10:18:09 -07002450 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002455 Phone phone = getPhone(subId);
2456 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 checkSimPuk.start();
2458 return checkSimPuk.unlockSim(puk, pin);
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
2461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463
2464 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002465 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 * a synchronous one.
2467 */
2468 private static class UnlockSim extends Thread {
2469
2470 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002471 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472
2473 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002474 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2475 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476
2477 // For replies from SimCard interface
2478 private Handler mHandler;
2479
2480 // For async handler to identify request type
2481 private static final int SUPPLY_PIN_COMPLETE = 100;
2482
Michele Berionne5e411512020-11-13 02:36:59 +00002483 UnlockSim(int phoneId, IccCard simCard) {
2484 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 mSimCard = simCard;
2486 }
2487
2488 @Override
2489 public void run() {
2490 Looper.prepare();
2491 synchronized (UnlockSim.this) {
2492 mHandler = new Handler() {
2493 @Override
2494 public void handleMessage(Message msg) {
2495 AsyncResult ar = (AsyncResult) msg.obj;
2496 switch (msg.what) {
2497 case SUPPLY_PIN_COMPLETE:
2498 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2499 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002500 mRetryCount = msg.arg1;
2501 if (ar.exception != null) {
2502 if (ar.exception instanceof CommandException &&
2503 ((CommandException)(ar.exception)).getCommandError()
2504 == CommandException.Error.PASSWORD_INCORRECT) {
2505 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002506 } //When UiccCardApp dispose,handle message and return exception
2507 else if (ar.exception instanceof CommandException &&
2508 ((CommandException) (ar.exception)).getCommandError()
2509 == CommandException.Error.ABORTED) {
2510 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002511 } else {
2512 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2513 }
2514 } else {
2515 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 mDone = true;
2518 UnlockSim.this.notifyAll();
2519 }
2520 break;
2521 }
2522 }
2523 };
2524 UnlockSim.this.notifyAll();
2525 }
2526 Looper.loop();
2527 }
2528
2529 /*
2530 * Use PIN or PUK to unlock SIM card
2531 *
2532 * If PUK is null, unlock SIM card with PIN
2533 *
2534 * If PUK is not null, unlock SIM card with PUK and set PIN code
2535 */
Wink Saville9de0f752013-10-22 19:04:03 -07002536 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537
2538 while (mHandler == null) {
2539 try {
2540 wait();
2541 } catch (InterruptedException e) {
2542 Thread.currentThread().interrupt();
2543 }
2544 }
2545 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2546
2547 if (puk == null) {
2548 mSimCard.supplyPin(pin, callback);
2549 } else {
2550 mSimCard.supplyPuk(puk, pin, callback);
2551 }
2552
2553 while (!mDone) {
2554 try {
2555 Log.d(LOG_TAG, "wait for done");
2556 wait();
2557 } catch (InterruptedException e) {
2558 // Restore the interrupted status
2559 Thread.currentThread().interrupt();
2560 }
2561 }
2562 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002563 int[] resultArray = new int[2];
2564 resultArray[0] = mResult;
2565 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002566
2567 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002568 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002569 }
2570
Wink Saville9de0f752013-10-22 19:04:03 -07002571 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
2573 }
2574
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002575 /**
2576 * This method has been removed due to privacy and stability concerns.
2577 */
2578 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002580 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2581 return;
Wink Saville36469e72014-06-11 15:17:00 -07002582 }
2583
Nathan Harold1f889d82020-06-04 17:05:26 -07002584 @Override
2585 public void updateServiceLocationWithPackageName(String callingPackage) {
2586 mApp.getSystemService(AppOpsManager.class)
2587 .checkPackage(Binder.getCallingUid(), callingPackage);
2588
Nathan Haroldf096d982020-11-18 17:18:06 -08002589 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002590 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2591 // Callers targeting S have no business invoking this method.
2592 return;
2593 }
2594
2595 LocationAccessPolicy.LocationPermissionResult locationResult =
2596 LocationAccessPolicy.checkLocationPermission(mApp,
2597 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2598 .setCallingPackage(callingPackage)
2599 .setCallingFeatureId(null)
2600 .setCallingPid(Binder.getCallingPid())
2601 .setCallingUid(Binder.getCallingUid())
2602 .setMethod("updateServiceLocation")
2603 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2604 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2605 .build());
2606 // Apps that lack location permission have no business calling this method;
2607 // however, because no permission was declared in the public API, denials must
2608 // all be "soft".
2609 switch (locationResult) {
2610 case DENIED_HARD: /* fall through */
2611 case DENIED_SOFT:
2612 return;
2613 }
2614
2615 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002618 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002620 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002627 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 @Override
2629 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002630 return isRadioOnWithFeature(callingPackage, null);
2631 }
2632
2633
2634 @Override
2635 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2636 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2637 callingFeatureId);
2638 }
2639
2640 @Deprecated
2641 @Override
2642 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2643 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002644 }
2645
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002646 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002647 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2648 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002650 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002651 return false;
2652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 return isRadioOnForSubscriber(subId);
2657 } finally {
2658 Binder.restoreCallingIdentity(identity);
2659 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002660 }
2661
2662 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 if (phone != null) {
2667 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2668 } else {
2669 return false;
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
Wink Saville36469e72014-06-11 15:17:00 -07002679
Wink Savilleb564aae2014-10-23 10:18:09 -07002680 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 final Phone phone = getPhone(subId);
2686 if (phone != null) {
2687 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002691 }
Wink Saville36469e72014-06-11 15:17:00 -07002692 }
2693
2694 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002695 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002696 }
2697
Wink Savilleb564aae2014-10-23 10:18:09 -07002698 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 final Phone phone = getPhone(subId);
2704 if (phone == null) {
2705 return false;
2706 }
2707 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2708 toggleRadioOnOffForSubscriber(subId);
2709 }
2710 return true;
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
Wink Saville36469e72014-06-11 15:17:00 -07002715
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002716 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002717 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 /*
2719 * If any of the Radios are available, it will need to be
2720 * shutdown. So return true if any Radio is available.
2721 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2725 Phone phone = PhoneFactory.getPhone(i);
2726 if (phone != null && phone.isRadioAvailable()) return true;
2727 }
2728 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2729 return false;
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002733 }
2734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 enforceModifyPermission();
2738
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2742 logv("Shutting down Phone " + i);
2743 shutdownRadioUsingPhoneId(i);
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002747 }
2748 }
2749
2750 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002751 Phone phone = PhoneFactory.getPhone(phoneId);
2752 if (phone != null && phone.isRadioAvailable()) {
2753 phone.shutdownRadio();
2754 }
2755 }
2756
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759
2760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2763 if (defaultPhone != null) {
2764 defaultPhone.setRadioPower(turnOn);
2765 return true;
2766 } else {
2767 loge("There's no default phone.");
2768 return false;
2769 }
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002772 }
Wink Saville36469e72014-06-11 15:17:00 -07002773 }
2774
Wink Savilleb564aae2014-10-23 10:18:09 -07002775 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 final Phone phone = getPhone(subId);
2781 if (phone != null) {
2782 phone.setRadioPower(turnOn);
2783 return true;
2784 } else {
2785 return false;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
Wink Saville36469e72014-06-11 15:17:00 -07002792 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 public boolean enableDataConnectivity() {
2795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 int subId = mSubscriptionController.getDefaultDataSubId();
2800 final Phone phone = getPhone(subId);
2801 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002802 phone.getDataEnabledSettings().setDataEnabled(
2803 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 return true;
2805 } else {
2806 return false;
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
Wink Saville36469e72014-06-11 15:17:00 -07002813 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 public boolean disableDataConnectivity() {
2816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817
2818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 int subId = mSubscriptionController.getDefaultDataSubId();
2821 final Phone phone = getPhone(subId);
2822 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002823 phone.getDataEnabledSettings().setDataEnabled(
2824 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 return true;
2826 } else {
2827 return false;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 }
2833
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002835 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 final Phone phone = getPhone(subId);
2839 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002840 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002841 } else {
2842 return false;
2843 }
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
2849 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002850 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002851 }
2852
pkanwarae03a6b2016-11-06 20:37:09 -08002853 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 enforceCallPermission();
2855
2856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2859 return;
2860 }
2861 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2862 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
2865 }
pkanwar32d516d2016-10-14 19:37:38 -07002866 };
2867
Wink Savilleb564aae2014-10-23 10:18:09 -07002868 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 return false;
2875 }
2876 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2877 } finally {
2878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002882 /**
2883 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2884 * tag on getCallState Binder call.
2885 */
2886 @Deprecated
2887 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002889 if (CompatChanges.isChangeEnabled(
2890 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2891 Binder.getCallingUid())) {
2892 // Do not allow this API to be called on API version 31+, it should only be
2893 // called on old apps using this Binder call directly.
2894 throw new SecurityException("This method can only be used for applications "
2895 + "targeting API version 30 or less.");
2896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 final long identity = Binder.clearCallingIdentity();
2898 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002899 Phone phone = getPhone(getDefaultSubscription());
2900 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2901 PhoneConstantConversions.convertCallState(phone.getState());
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
2904 }
2905 }
2906
2907 @Override
2908 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2909 if (CompatChanges.isChangeEnabled(
2910 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2911 Binder.getCallingUid())) {
2912 // Check READ_PHONE_STATE for API version 31+
2913 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2914 featureId, "getCallStateForSubscription")) {
2915 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2916 + "targeting API level 31+.");
2917 }
2918 }
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2923 PhoneConstantConversions.convertCallState(phone.getState());
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002930 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002931 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2932 }
2933
2934 @Override
2935 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002938 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 if (phone != null) {
Jack Yu4accbd92021-11-29 11:36:17 -08002940 if (phone.isUsingNewDataStack()) {
2941 return phone.getDataNetworkController().getInternetDataNetworkState();
2942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2944 } else {
2945 return PhoneConstantConversions.convertDataState(
2946 PhoneConstants.DataState.DISCONNECTED);
2947 }
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002951 }
2952
Sanket Padawe356d7632015-06-22 14:03:32 -07002953 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002954 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002955 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2956 }
2957
2958 @Override
2959 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 final long identity = Binder.clearCallingIdentity();
2961 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002962 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963 if (phone != null) {
2964 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2965 } else {
2966 return TelephonyManager.DATA_ACTIVITY_NONE;
2967 }
2968 } finally {
2969 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
2972
2973 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002974 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002975 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002976 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002977
2978 LocationAccessPolicy.LocationPermissionResult locationResult =
2979 LocationAccessPolicy.checkLocationPermission(mApp,
2980 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2981 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002982 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002983 .setCallingPid(Binder.getCallingPid())
2984 .setCallingUid(Binder.getCallingUid())
2985 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002986 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002987 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2988 .build());
2989 switch (locationResult) {
2990 case DENIED_HARD:
2991 throw new SecurityException("Not allowed to access cell location");
2992 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002993 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2994 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002995 }
2996
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002997 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003001 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003002 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 } finally {
3004 Binder.restoreCallingIdentity(identity);
3005 }
Svetoslav64fad262015-04-14 14:35:21 -07003006 }
3007
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003008 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003009 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003010 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3011 // registered cell info, so return a NULL country instead.
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003014 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3015 // Get default phone in this case.
3016 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3017 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003018 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003020 if (phone == null) return "";
3021 ServiceStateTracker sst = phone.getServiceStateTracker();
3022 if (sst == null) return "";
3023 LocaleTracker lt = sst.getLocaleTracker();
3024 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003025 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003026 } finally {
3027 Binder.restoreCallingIdentity(identity);
3028 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003029 }
3030
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003031 /**
3032 * This method was removed due to potential issues caused by performing partial
3033 * updates of service state, and lack of a credible use case.
3034 *
3035 * This has the ability to break the telephony implementation by disabling notification of
3036 * changes in device connectivity. DO NOT USE THIS!
3037 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003038 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003039 public void enableLocationUpdates() {
3040 mApp.enforceCallingOrSelfPermission(
3041 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 }
3043
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003044 /**
3045 * This method was removed due to potential issues caused by performing partial
3046 * updates of service state, and lack of a credible use case.
3047 *
3048 * This has the ability to break the telephony implementation by disabling notification of
3049 * changes in device connectivity. DO NOT USE THIS!
3050 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 @Override
3052 public void disableLocationUpdates() {
3053 mApp.enforceCallingOrSelfPermission(
3054 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055 }
3056
3057 @Override
3058 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003059 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3060 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003061 try {
3062 mApp.getSystemService(AppOpsManager.class)
3063 .checkPackage(Binder.getCallingUid(), callingPackage);
3064 } catch (SecurityException e) {
3065 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3066 throw e;
3067 }
3068
Nathan Haroldf096d982020-11-18 17:18:06 -08003069 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003070 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3071 throw new SecurityException(
3072 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3073 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003074
Jordan Liu1617b712019-07-10 15:06:26 -07003075 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003076 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3077 return null;
3078 }
Svetoslav64fad262015-04-14 14:35:21 -07003079
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003080 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003082 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003083 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084
Nathan Haroldf180aac2018-06-01 18:43:55 -07003085 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3086 for (CellInfo ci : info) {
3087 if (ci instanceof CellInfoGsm) {
3088 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3089 } else if (ci instanceof CellInfoWcdma) {
3090 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003092 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003093 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 }
3095
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003096 private List<CellInfo> getCachedCellInfo() {
3097 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3098 for (Phone phone : PhoneFactory.getPhones()) {
3099 List<CellInfo> info = phone.getAllCellInfo();
3100 if (info != null) cellInfos.addAll(info);
3101 }
3102 return cellInfos;
3103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104
3105 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003106 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003107 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003108 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003109
3110 LocationAccessPolicy.LocationPermissionResult locationResult =
3111 LocationAccessPolicy.checkLocationPermission(mApp,
3112 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3113 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003114 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003115 .setCallingPid(Binder.getCallingPid())
3116 .setCallingUid(Binder.getCallingUid())
3117 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003118 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003119 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3120 .build());
3121 switch (locationResult) {
3122 case DENIED_HARD:
3123 throw new SecurityException("Not allowed to access cell info");
3124 case DENIED_SOFT:
3125 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 }
3127
Nathan Haroldf096d982020-11-18 17:18:06 -08003128 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003129 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3130 return getCachedCellInfo();
3131 }
3132
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003133 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003134 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3138 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003139 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003140 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141 if (info != null) cellInfos.addAll(info);
3142 }
3143 return cellInfos;
3144 } finally {
3145 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146 }
3147 }
3148
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003149 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003150 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3151 String callingFeatureId) {
3152 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3153 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003154 }
3155
3156 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003157 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3158 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003159 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003160 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003161 }
3162
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003163 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3164 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003165 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003166 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003167
3168 LocationAccessPolicy.LocationPermissionResult locationResult =
3169 LocationAccessPolicy.checkLocationPermission(mApp,
3170 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3171 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003172 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003173 .setCallingPid(Binder.getCallingPid())
3174 .setCallingUid(Binder.getCallingUid())
3175 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003176 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3177 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003178 .build());
3179 switch (locationResult) {
3180 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003181 if (TelephonyPermissions
3182 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003183 // Safetynet logging for b/154934934
3184 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3185 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003186 throw new SecurityException("Not allowed to access cell info");
3187 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003188 if (TelephonyPermissions
3189 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003190 // Safetynet logging for b/154934934
3191 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3192 }
Nathan Harold5320c422019-05-09 10:26:08 -07003193 try {
3194 cb.onCellInfo(new ArrayList<CellInfo>());
3195 } catch (RemoteException re) {
3196 // Drop without consequences
3197 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003198 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003199 }
3200
Nathan Harolda939a962019-05-09 10:13:47 -07003201
3202 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003203 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3204
3205 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3206 }
3207
3208 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003210 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003211 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003215 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 }
3220
Shishir Agrawala9f32182016-04-12 12:00:16 -07003221 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003222 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003223 Phone phone = PhoneFactory.getPhone(slotIndex);
3224 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003225 return null;
3226 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003227 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003228 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003229 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003230 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003231 return null;
3232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233
3234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 return phone.getImei();
3237 } finally {
3238 Binder.restoreCallingIdentity(identity);
3239 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003240 }
3241
3242 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003243 public String getTypeAllocationCodeForSlot(int slotIndex) {
3244 Phone phone = PhoneFactory.getPhone(slotIndex);
3245 String tac = null;
3246 if (phone != null) {
3247 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003248 try {
3249 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3250 } catch (IndexOutOfBoundsException e) {
3251 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3252 return null;
3253 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003254 }
3255 return tac;
3256 }
3257
3258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003259 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003260 try {
3261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3262 } catch (SecurityException se) {
3263 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3264 throw new SecurityException("Package " + callingPackage + " does not belong to "
3265 + Binder.getCallingUid());
3266 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003267 Phone phone = PhoneFactory.getPhone(slotIndex);
3268 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003269 return null;
3270 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271
Jeff Davidson913390f2018-02-23 17:11:49 -08003272 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003273 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003274 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003275 return null;
3276 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 return phone.getMeid();
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
Jack Yu2af8d712017-03-15 17:14:14 -07003284 }
3285
3286 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003287 public String getManufacturerCodeForSlot(int slotIndex) {
3288 Phone phone = PhoneFactory.getPhone(slotIndex);
3289 String manufacturerCode = null;
3290 if (phone != null) {
3291 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003292 try {
3293 manufacturerCode =
3294 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3295 } catch (IndexOutOfBoundsException e) {
3296 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3297 return null;
3298 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003299 }
3300 return manufacturerCode;
3301 }
3302
3303 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003304 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3305 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003306 Phone phone = PhoneFactory.getPhone(slotIndex);
3307 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003308 return null;
3309 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003310 int subId = phone.getSubId();
3311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003312 mApp, subId, callingPackage, callingFeatureId,
3313 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003314 return null;
3315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316
3317 final long identity = Binder.clearCallingIdentity();
3318 try {
3319 return phone.getDeviceSvn();
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
3322 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003323 }
3324
fionaxu43304da2017-11-27 22:51:16 -08003325 @Override
3326 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 final Phone phone = getPhone(subId);
3330 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
fionaxu43304da2017-11-27 22:51:16 -08003334 }
3335
3336 @Override
3337 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 final long identity = Binder.clearCallingIdentity();
3339 try {
3340 final Phone phone = getPhone(subId);
3341 return phone == null ? null : phone.getCarrierName();
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
fionaxu43304da2017-11-27 22:51:16 -08003345 }
3346
calvinpanffe225e2018-11-01 19:43:06 +08003347 @Override
chen xu0026ca62019-03-06 15:28:50 -08003348 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 final Phone phone = getPhone(subId);
3352 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003353 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
3357 }
3358
3359 @Override
chen xu0026ca62019-03-06 15:28:50 -08003360 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003364 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
3368 }
3369
chen xu651eec72018-11-11 19:03:44 -08003370 @Override
chen xu864e11c2018-12-06 22:10:03 -08003371 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3372 if (!isSubscriptionMccMnc) {
3373 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3374 }
chen xu651eec72018-11-11 19:03:44 -08003375 final Phone phone = PhoneFactory.getPhone(slotIndex);
3376 if (phone == null) {
3377 return TelephonyManager.UNKNOWN_CARRIER_ID;
3378 }
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3382 } finally {
3383 Binder.restoreCallingIdentity(identity);
3384 }
3385 }
3386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387 //
3388 // Internal helper methods.
3389 //
3390
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003391 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003392 * Make sure the caller is the calling package itself
3393 *
3394 * @throws SecurityException if the caller is not the calling package
3395 */
3396 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3397 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003398 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3399 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003400 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003401 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003402 } catch (PackageManager.NameNotFoundException e) {
3403 // packageUid is -1
3404 }
3405 if (packageUid != callingUid) {
3406 throw new SecurityException(message + ": Package " + callingPackage
3407 + " does not belong to " + callingUid);
3408 }
3409 }
3410
3411 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003412 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3413 *
3414 * @throws SecurityException if the caller does not have the required permission
3415 */
3416 private void enforceModifyPermission() {
3417 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3418 }
3419
Shuo Qian3b6ee772019-11-13 17:43:31 -08003420 private void enforceActiveEmergencySessionPermission() {
3421 mApp.enforceCallingOrSelfPermission(
3422 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3423 }
3424
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003425 /**
3426 * Make sure the caller has the CALL_PHONE permission.
3427 *
3428 * @throws SecurityException if the caller does not have the required permission
3429 */
3430 private void enforceCallPermission() {
3431 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3432 }
3433
paulhu5a773602019-08-23 19:17:33 +08003434 private void enforceSettingsPermission() {
3435 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003436 }
3437
Michele Berionne5e411512020-11-13 02:36:59 +00003438 private void enforceRebootPermission() {
3439 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3440 }
3441
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003442 private String createTelUrl(String number) {
3443 if (TextUtils.isEmpty(number)) {
3444 return null;
3445 }
3446
Jake Hambye994d462014-02-03 13:10:13 -08003447 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 }
3449
Ihab Awadf9e92732013-12-05 18:02:52 -08003450 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3452 }
3453
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003454 private static void logv(String msg) {
3455 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3456 }
3457
Ihab Awadf9e92732013-12-05 18:02:52 -08003458 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003459 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3460 }
3461
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003462 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003464 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003465 }
3466
Sanket Padawe356d7632015-06-22 14:03:32 -07003467 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003468 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469 final long identity = Binder.clearCallingIdentity();
3470 try {
3471 final Phone phone = PhoneFactory.getPhone(slotIndex);
3472 if (phone == null) {
3473 return PhoneConstants.PHONE_TYPE_NONE;
3474 } else {
3475 return phone.getPhoneType();
3476 }
3477 } finally {
3478 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003480 }
3481
3482 /**
3483 * Returns the CDMA ERI icon index to display
3484 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003485 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003486 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3487 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3488 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003489 }
3490
Sanket Padawe356d7632015-06-22 14:03:32 -07003491 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003492 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3493 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003495 mApp, subId, callingPackage, callingFeatureId,
3496 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003497 return -1;
3498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003499
3500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 final Phone phone = getPhone(subId);
3503 if (phone != null) {
3504 return phone.getCdmaEriIconIndex();
3505 } else {
3506 return -1;
3507 }
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511 }
3512
3513 /**
3514 * Returns the CDMA ERI icon mode,
3515 * 0 - ON
3516 * 1 - FLASHING
3517 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003518 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003519 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3520 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3521 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003522 }
3523
Sanket Padawe356d7632015-06-22 14:03:32 -07003524 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003525 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3526 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003528 mApp, subId, callingPackage, callingFeatureId,
3529 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003530 return -1;
3531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532
3533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 final Phone phone = getPhone(subId);
3536 if (phone != null) {
3537 return phone.getCdmaEriIconMode();
3538 } else {
3539 return -1;
3540 }
3541 } finally {
3542 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003544 }
3545
3546 /**
3547 * Returns the CDMA ERI text,
3548 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003550 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3551 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3552 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003553 }
3554
Sanket Padawe356d7632015-06-22 14:03:32 -07003555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3557 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003559 mApp, subId, callingPackage, callingFeatureId,
3560 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003561 return null;
3562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003563
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 final Phone phone = getPhone(subId);
3567 if (phone != null) {
3568 return phone.getCdmaEriText();
3569 } else {
3570 return null;
3571 }
3572 } finally {
3573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003575 }
3576
3577 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003578 * Returns the CDMA MDN.
3579 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003580 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003581 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3583 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584
3585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003588 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589 return phone.getLine1Number();
3590 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592 return null;
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003596 }
3597 }
3598
3599 /**
3600 * Returns the CDMA MIN.
3601 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003602 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003603 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3605 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606
3607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 final Phone phone = getPhone(subId);
3610 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3611 return phone.getCdmaMin();
3612 } else {
3613 return null;
3614 }
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003617 }
3618 }
3619
Hall Liud892bec2018-11-30 14:51:45 -08003620 @Override
3621 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3622 INumberVerificationCallback callback, String callingPackage) {
3623 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3624 != PERMISSION_GRANTED) {
3625 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3626 }
3627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3628
3629 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3630 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003631 throw new SecurityException("Calling package must be configured in the device config: "
3632 + "calling package: " + callingPackage
3633 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003634 }
3635
3636 if (range == null) {
3637 throw new NullPointerException("Range must be non-null");
3638 }
3639
3640 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003641 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003642
3643 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3644 }
3645
Junda Liuca05d5d2014-08-14 22:36:34 -07003646 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003647 * Returns true if CDMA provisioning needs to run.
3648 */
3649 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650 final long identity = Binder.clearCallingIdentity();
3651 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003656 }
3657
3658 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003659 * Sets the voice mail number of a given subId.
3660 */
3661 @Override
3662 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003663 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3664 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3669 new Pair<String, String>(alphaTag, number), new Integer(subId));
3670 return success;
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
3673 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003674 }
3675
Ta-wei Yen87c49842016-05-13 21:19:52 -07003676 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003677 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003679 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3680 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003681 if (!TextUtils.equals(callingPackage, systemDialer)) {
3682 throw new SecurityException("caller must be system dialer");
3683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684
3685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3688 if (phoneAccountHandle == null) {
3689 return null;
3690 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003691 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003694 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003695 }
3696
3697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003698 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3699 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003700 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003702 mApp, subId, callingPackage, callingFeatureId,
3703 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003704 return null;
3705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003707 final long identity = Binder.clearCallingIdentity();
3708 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003709 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003713 }
3714
3715 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003716 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3717 VisualVoicemailSmsFilterSettings settings) {
3718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003727 }
3728
3729 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003730 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3731 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732
3733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003736 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003740 }
3741
3742 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003743 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3744 String callingPackage, int subId) {
3745 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
3747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003750 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 } finally {
3752 Binder.restoreCallingIdentity(identity);
3753 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003754 }
3755
3756 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003757 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759
3760 final long identity = Binder.clearCallingIdentity();
3761 try {
3762 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003763 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003767 }
3768
3769 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003770 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3771 String callingAttributionTag, int subId, String number, int port, String text,
3772 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003774 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003775 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003776 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003777 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3778 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003779 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003780
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003781 /**
fionaxu0152e512016-11-14 13:36:14 -08003782 * Sets the voice activation state of a given subId.
3783 */
3784 @Override
3785 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3787 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788
3789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 final Phone phone = getPhone(subId);
3792 if (phone != null) {
3793 phone.setVoiceActivationState(activationState);
3794 } else {
3795 loge("setVoiceActivationState fails with invalid subId: " + subId);
3796 }
3797 } finally {
3798 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003799 }
3800 }
3801
3802 /**
3803 * Sets the data activation state of a given subId.
3804 */
3805 @Override
3806 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3808 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809
3810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 final Phone phone = getPhone(subId);
3813 if (phone != null) {
3814 phone.setDataActivationState(activationState);
3815 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003816 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 }
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003820 }
3821 }
3822
3823 /**
3824 * Returns the voice activation state of a given subId.
3825 */
3826 @Override
3827 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829
fionaxu0152e512016-11-14 13:36:14 -08003830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 if (phone != null) {
3834 return phone.getVoiceActivationState();
3835 } else {
3836 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3837 }
3838 } finally {
3839 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003840 }
3841 }
3842
3843 /**
3844 * Returns the data activation state of a given subId.
3845 */
3846 @Override
3847 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003848 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849
fionaxu0152e512016-11-14 13:36:14 -08003850 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 if (phone != null) {
3854 return phone.getDataActivationState();
3855 } else {
3856 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3857 }
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003860 }
3861 }
3862
3863 /**
Wink Saville36469e72014-06-11 15:17:00 -07003864 * Returns the unread count of voicemails for a subId
3865 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003866 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003867 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3868 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003870 mApp, subId, callingPackage, callingFeatureId,
3871 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003872 return 0;
3873 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874 final long identity = Binder.clearCallingIdentity();
3875 try {
3876 final Phone phone = getPhone(subId);
3877 if (phone != null) {
3878 return phone.getVoiceMessageCount();
3879 } else {
3880 return 0;
3881 }
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003885 }
3886
3887 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003888 * returns true, if the device is in a state where both voice and data
3889 * are supported simultaneously. This can change based on location or network condition.
3890 */
3891 @Override
3892 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 final Phone phone = getPhone(subId);
3896 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
3899 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003900 }
3901
3902 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003903 * Send the dialer code if called from the current default dialer or the caller has
3904 * carrier privilege.
3905 * @param inputCode The dialer code to send
3906 */
3907 @Override
3908 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003911 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3912 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003913 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003914 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003915 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917
3918 final long identity = Binder.clearCallingIdentity();
3919 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003920 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
fionaxu235cc5e2017-03-06 22:25:57 -08003924 }
3925
Pengquan Menga1bb6272018-09-06 09:59:22 -07003926 @Override
3927 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003928 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003929 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003930 mApp, subId, "getNetworkSelectionMode");
3931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 if (!isActiveSubscription(subId)) {
3934 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3935 }
3936 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003939 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003940 }
3941
Brad Ebinger35c841c2018-10-01 10:40:55 -07003942 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003943 public boolean isInEmergencySmsMode() {
3944 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3945 final long identity = Binder.clearCallingIdentity();
3946 try {
3947 for (Phone phone : PhoneFactory.getPhones()) {
3948 if (phone.isInEmergencySmsMode()) {
3949 return true;
3950 }
3951 }
3952 } finally {
3953 Binder.restoreCallingIdentity(identity);
3954 }
3955 return false;
3956 }
3957
shilu366312e2019-12-17 09:28:10 -08003958 /**
3959 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3960 * @param subId The subscription to use to check the configuration.
3961 * @param c The callback that will be used to send the result.
3962 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003963 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003964 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3965 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003966 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003967 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003968
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003969 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3970 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3971 "IMS not available on device.");
3972 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 final long token = Binder.clearCallingIdentity();
3974 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003975 int slotId = getSlotIndexOrException(subId);
3976 verifyImsMmTelConfiguredOrThrow(slotId);
3977 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003978 } catch (ImsException e) {
3979 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 } finally {
3981 Binder.restoreCallingIdentity(token);
3982 }
3983 }
3984
shilu366312e2019-12-17 09:28:10 -08003985 /**
3986 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3987 * @param subId The subscription to use to check the configuration.
3988 * @param c The callback that will be used to send the result.
3989 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003991 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003992 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003993 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003994 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3995 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3996 }
Meng Wangafbc5852019-09-19 17:37:13 -07003997 final long token = Binder.clearCallingIdentity();
3998 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003999 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4000 .removeRegistrationCallbackForSubscription(c, subId);
4001 } catch (ImsException e) {
4002 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4003 + "is inactive, ignoring unregister.");
4004 // If the subscription is no longer active, just return, since the callback
4005 // will already have been removed internally.
4006 } finally {
4007 Binder.restoreCallingIdentity(token);
4008 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 }
4010
Brad Ebingera34a6c22019-10-22 17:36:18 -07004011 /**
4012 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4013 */
4014 @Override
4015 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4016 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4017 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4018 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4019 "IMS not available on device.");
4020 }
4021 final long token = Binder.clearCallingIdentity();
4022 try {
4023 Phone phone = getPhone(subId);
4024 if (phone == null) {
4025 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4026 + subId + "'");
4027 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4028 }
4029 phone.getImsRegistrationState(regState -> {
4030 try {
4031 consumer.accept((regState == null)
4032 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4033 } catch (RemoteException e) {
4034 // Ignore if the remote process is no longer available to call back.
4035 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4036 }
4037 });
4038 } finally {
4039 Binder.restoreCallingIdentity(token);
4040 }
4041 }
4042
4043 /**
4044 * Get the transport type for the IMS service registration state.
4045 */
4046 @Override
4047 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004048 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004049 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004050 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4051 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4052 "IMS not available on device.");
4053 }
4054 final long token = Binder.clearCallingIdentity();
4055 try {
4056 Phone phone = getPhone(subId);
4057 if (phone == null) {
4058 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4059 + subId + "'");
4060 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4061 }
4062 phone.getImsRegistrationTech(regTech -> {
4063 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4064 int regTechConverted = (regTech == null)
4065 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4066 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4067 regTechConverted);
4068 try {
4069 consumer.accept(regTechConverted);
4070 } catch (RemoteException e) {
4071 // Ignore if the remote process is no longer available to call back.
4072 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4073 }
4074 });
4075 } finally {
4076 Binder.restoreCallingIdentity(token);
4077 }
4078 }
4079
shilu366312e2019-12-17 09:28:10 -08004080 /**
4081 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4082 * @param subId The subscription to use to check the configuration.
4083 * @param c The callback that will be used to send the result.
4084 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004086 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4087 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004088 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004089 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004090 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4091 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4092 "IMS not available on device.");
4093 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 final long token = Binder.clearCallingIdentity();
4095 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004096 int slotId = getSlotIndexOrException(subId);
4097 verifyImsMmTelConfiguredOrThrow(slotId);
4098 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (ImsException e) {
4100 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 } finally {
4102 Binder.restoreCallingIdentity(token);
4103 }
4104 }
4105
shilu366312e2019-12-17 09:28:10 -08004106 /**
4107 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4108 * @param subId The subscription to use to check the configuration.
4109 * @param c The callback that will be used to send the result.
4110 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004112 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004113 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004114 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004115 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4116 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4117 }
Meng Wangafbc5852019-09-19 17:37:13 -07004118
4119 final long token = Binder.clearCallingIdentity();
4120 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004121 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004122 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004123 } catch (ImsException e) {
4124 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4125 + "is inactive, ignoring unregister.");
4126 // If the subscription is no longer active, just return, since the callback
4127 // will already have been removed internally.
4128 } finally {
4129 Binder.restoreCallingIdentity(token);
4130 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 }
4132
4133 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004134 public boolean isCapable(int subId, int capability, int regTech) {
4135 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 final long token = Binder.clearCallingIdentity();
4137 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004138 int slotId = getSlotIndexOrException(subId);
4139 verifyImsMmTelConfiguredOrThrow(slotId);
4140 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004141 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4143 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004144 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004145 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4146 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 } finally {
4148 Binder.restoreCallingIdentity(token);
4149 }
4150 }
4151
4152 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004153 public boolean isAvailable(int subId, int capability, int regTech) {
4154 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 final long token = Binder.clearCallingIdentity();
4156 try {
4157 Phone phone = getPhone(subId);
4158 if (phone == null) return false;
4159 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004160 } catch (com.android.ims.ImsException e) {
4161 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4162 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 } finally {
4164 Binder.restoreCallingIdentity(token);
4165 }
4166 }
4167
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004168 /**
4169 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4170 * subscription.
4171 * @param subId The subscription to use to check the configuration.
4172 * @param callback The callback that will be used to send the result.
4173 * @param capability The MmTelFeature capability that will be used to send the result.
4174 * @param transportType The transport type of the MmTelFeature capability.
4175 */
4176 @Override
4177 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4178 int transportType) {
4179 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4180 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4181 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4182 "IMS not available on device.");
4183 }
4184 final long token = Binder.clearCallingIdentity();
4185 try {
4186 int slotId = getSlotIndex(subId);
4187 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4188 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4189 + subId + "'");
4190 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4191 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004192 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004193 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4194 transportType, aBoolean -> {
4195 try {
4196 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4197 } catch (RemoteException e) {
4198 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4199 + "running. Ignore");
4200 }
4201 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004202 } catch (ImsException e) {
4203 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004204 } finally {
4205 Binder.restoreCallingIdentity(token);
4206 }
4207 }
4208
shilu366312e2019-12-17 09:28:10 -08004209 /**
4210 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4211 * @param subId The subscription to use to check the configuration.
4212 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 @Override
4214 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004215 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004216 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004217
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 final long token = Binder.clearCallingIdentity();
4219 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004220 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004221 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004222 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 } catch (ImsException e) {
4224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 } finally {
4226 Binder.restoreCallingIdentity(token);
4227 }
4228 }
4229
4230 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004231 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004233 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 final long identity = Binder.clearCallingIdentity();
4235 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004236 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004237 // This setting doesn't require an active ImsService connection, so do not verify. The
4238 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004239 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004240 } catch (ImsException e) {
4241 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
4245 }
4246
shilu366312e2019-12-17 09:28:10 -08004247 /**
4248 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4249 * @param subId The subscription to use to check the configuration.
4250 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004252 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004253 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004254 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 final long identity = Binder.clearCallingIdentity();
4256 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004257 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004258 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004260 } catch (ImsException e) {
4261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
4265 }
4266
4267 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004268 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004270 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 final long identity = Binder.clearCallingIdentity();
4272 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004273 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004274 // This setting doesn't require an active ImsService connection, so do not verify. The
4275 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004276 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004277 } catch (ImsException e) {
4278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
4282 }
4283
shilu366312e2019-12-17 09:28:10 -08004284 /**
4285 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4286 * @param subId The subscription to use to check the configuration.
4287 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 @Override
4289 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004290 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004291 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 final long identity = Binder.clearCallingIdentity();
4293 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004294 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004295 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004297 } catch (ImsException e) {
4298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
4302 }
4303
4304 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004305 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004307 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 final long identity = Binder.clearCallingIdentity();
4309 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004310 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004311 // This setting doesn't require an active ImsService connection, so do not verify. The
4312 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004313 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004314 } catch (ImsException e) {
4315 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
4319 }
4320
shilu366312e2019-12-17 09:28:10 -08004321 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004322 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4323 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4324 * @param subId The subscription to use to check the configuration.
4325 */
4326 @Override
4327 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004328 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004329 mApp, subId, "isCrossSimCallingEnabledByUser");
4330 final long identity = Binder.clearCallingIdentity();
4331 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004332 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004333 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004335 } catch (ImsException e) {
4336 throw new ServiceSpecificException(e.getCode());
4337 } finally {
4338 Binder.restoreCallingIdentity(identity);
4339 }
4340 }
4341
4342 /**
4343 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4344 * Requires MODIFY_PHONE_STATE permission.
4345 * @param subId The subscription to use to check the configuration.
4346 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4347 * false otherwise
4348 */
4349 @Override
4350 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4352 "setCrossSimCallingEnabled");
4353 final long identity = Binder.clearCallingIdentity();
4354 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004355 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004356 // This setting doesn't require an active ImsService connection, so do not verify. The
4357 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004359 } catch (ImsException e) {
4360 throw new ServiceSpecificException(e.getCode());
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
4364 }
4365
4366 /**
shilu366312e2019-12-17 09:28:10 -08004367 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4368 * @param subId The subscription to use to check the configuration.
4369 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004371
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004373 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004374 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 final long identity = Binder.clearCallingIdentity();
4376 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004377 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004378 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (ImsException e) {
4381 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
4385 }
4386
4387 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004388 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004390 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 final long identity = Binder.clearCallingIdentity();
4392 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004394 // This setting doesn't require an active ImsService connection, so do not verify. The
4395 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004396 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004397 } catch (ImsException e) {
4398 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004399 } finally {
4400 Binder.restoreCallingIdentity(identity);
4401 }
4402 }
4403
4404 @Override
4405 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4407 "setVoWiFiNonPersistent");
4408 final long identity = Binder.clearCallingIdentity();
4409 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004410 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004411 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004413 } catch (ImsException e) {
4414 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
4418 }
4419
shilu366312e2019-12-17 09:28:10 -08004420 /**
4421 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4422 * @param subId The subscription to use to check the configuration.
4423 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004424 @Override
4425 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004426 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004427 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004428 final long identity = Binder.clearCallingIdentity();
4429 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004430 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004431 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004432 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004433 } catch (ImsException e) {
4434 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
4438 }
4439
4440 @Override
4441 public void setVoWiFiModeSetting(int subId, int mode) {
4442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4443 "setVoWiFiModeSetting");
4444 final long identity = Binder.clearCallingIdentity();
4445 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004446 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004447 // This setting doesn't require an active ImsService connection, so do not verify. The
4448 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004449 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004450 } catch (ImsException e) {
4451 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
4455 }
4456
4457 @Override
4458 public int getVoWiFiRoamingModeSetting(int subId) {
4459 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4460 final long identity = Binder.clearCallingIdentity();
4461 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004462 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004463 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004465 } catch (ImsException e) {
4466 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 } finally {
4468 Binder.restoreCallingIdentity(identity);
4469 }
4470 }
4471
4472 @Override
4473 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4475 "setVoWiFiRoamingModeSetting");
4476 final long identity = Binder.clearCallingIdentity();
4477 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004479 // This setting doesn't require an active ImsService connection, so do not verify. The
4480 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004482 } catch (ImsException e) {
4483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
4487 }
4488
4489 @Override
4490 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4492 "setRttCapabilityEnabled");
4493 final long identity = Binder.clearCallingIdentity();
4494 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004496 // This setting doesn't require an active ImsService connection, so do not verify. The
4497 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004499 } catch (ImsException e) {
4500 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504 }
4505
shilu366312e2019-12-17 09:28:10 -08004506 /**
4507 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4508 * @param subId The subscription to use to check the configuration.
4509 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 @Override
4511 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004512 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004513 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004514 final long identity = Binder.clearCallingIdentity();
4515 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004516 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004517 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004519 } catch (ImsException e) {
4520 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
4524 }
4525
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004526 @Override
4527 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4528 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004529
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004530 final long identity = Binder.clearCallingIdentity();
4531 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004532 if (!isImsAvailableOnDevice()) {
4533 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4534 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004535 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004536 int slotId = getSlotIndexOrException(subId);
4537 verifyImsMmTelConfiguredOrThrow(slotId);
4538 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004539 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004540 } catch (ImsException e) {
4541 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004542 } finally {
4543 Binder.restoreCallingIdentity(identity);
4544 }
4545 }
4546
4547 @Override
4548 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4549 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004550
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004551 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4553 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4554 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004555 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004556 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004557 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004559 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4560 + "is inactive, ignoring unregister.");
4561 // If the subscription is no longer active, just return, since the callback will already
4562 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
4566 }
4567
joonhunshin2c3e4232021-11-28 07:32:01 +00004568 @Override
4569 public void registerFeatureProvisioningChangedCallback(int subId,
4570 IFeatureProvisioningCallback callback) {
4571 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4572 mApp, subId, "registerFeatureProvisioningChangedCallback");
4573
4574 final long identity = Binder.clearCallingIdentity();
4575 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4576 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4577 }
4578
4579 ImsProvisioningController.getInstance()
4580 .addFeatureProvisioningChangedCallback(subId, callback);
4581
4582 Binder.restoreCallingIdentity(identity);
4583 }
4584
4585 @Override
4586 public void unregisterFeatureProvisioningChangedCallback(int subId,
4587 IFeatureProvisioningCallback callback) {
4588 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4589 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4590
4591 final long identity = Binder.clearCallingIdentity();
4592 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4593 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4594 }
4595
4596 ImsProvisioningController.getInstance()
4597 .removeFeatureProvisioningChangedCallback(subId, callback);
4598
4599 Binder.restoreCallingIdentity(identity);
4600 }
allenwtsu99c623b2020-01-03 18:24:23 +08004601
4602 private void checkModifyPhoneStatePermission(int subId, String message) {
4603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4604 message);
4605 }
4606
4607 private boolean isImsProvisioningRequired(int subId, int capability,
4608 boolean isMmtelCapability) {
4609 Phone phone = getPhone(subId);
4610 if (phone == null) {
4611 loge("phone instance null for subid " + subId);
4612 return false;
4613 }
4614 if (isMmtelCapability) {
4615 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4616 return false;
4617 }
4618 } else {
4619 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4620 return false;
4621 }
4622 }
4623 return true;
4624 }
4625
4626 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004627 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004628 boolean isProvisioned) {
4629 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4630
4631 final long identity = Binder.clearCallingIdentity();
4632 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004633 ImsProvisioningController.getInstance()
4634 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4635 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004636 } finally {
4637 Binder.restoreCallingIdentity(identity);
4638 }
allenwtsu99c623b2020-01-03 18:24:23 +08004639 }
4640
4641
4642 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004643 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4644 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4645 mApp, subId, "getRcsProvisioningStatusForCapability");
4646
allenwtsu99c623b2020-01-03 18:24:23 +08004647 final long identity = Binder.clearCallingIdentity();
4648 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004649 return ImsProvisioningController.getInstance()
4650 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
4654 }
4655
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004656 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4658 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004659 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshin2c3e4232021-11-28 07:32:01 +00004660
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004661 final long identity = Binder.clearCallingIdentity();
4662 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004663 ImsProvisioningController.getInstance()
4664 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
4668 }
4669
4670 @Override
4671 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshin2c3e4232021-11-28 07:32:01 +00004672 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4673 mApp, subId, "getProvisioningStatusForCapability");
4674
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675 final long identity = Binder.clearCallingIdentity();
4676 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004677 return ImsProvisioningController.getInstance()
4678 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004679
4680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
4683 }
4684
4685 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004686 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4687 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4688 mApp, subId, "isProvisioningRequiredForCapability");
4689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 return ImsProvisioningController.getInstance()
4693 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4694 } finally {
4695 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004696 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004697 }
4698
4699 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004700 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4701 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4702 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004703
joonhunshin2c3e4232021-11-28 07:32:01 +00004704 final long identity = Binder.clearCallingIdentity();
4705 try {
4706 return ImsProvisioningController.getInstance()
4707 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4708 } finally {
4709 Binder.restoreCallingIdentity(identity);
4710 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004711 }
4712
4713 private static String getMmTelProvisioningKey(int subId, int tech) {
4714 // resulting key is provision_ims_mmtel_{subId}_{tech}
4715 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4716 }
4717
4718 /**
4719 * Query CarrierConfig to see if the specified capability requires provisioning for the
4720 * carrier associated with the subscription id.
4721 */
4722 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4723 int capability) {
4724 CarrierConfigManager configManager = new CarrierConfigManager(context);
4725 PersistableBundle c = configManager.getConfigForSubId(subId);
4726 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004727 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004728 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4729 false);
4730 boolean requireVoiceVtProvisioning = c.getBoolean(
4731 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4732
4733 // First check to make sure that the capability requires provisioning.
4734 switch (capability) {
4735 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4736 // intentional fallthrough
4737 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4738 if (requireVoiceVtProvisioning) {
4739 // Voice and Video requires provisioning
4740 return true;
4741 }
4742 break;
4743 }
4744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4745 if (requireUtProvisioning) {
4746 // UT requires provisioning
4747 return true;
4748 }
4749 break;
4750 }
4751 }
4752 return false;
4753 }
4754
allenwtsu99c623b2020-01-03 18:24:23 +08004755 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4756 int capability) {
4757 CarrierConfigManager configManager = new CarrierConfigManager(context);
4758 PersistableBundle c = configManager.getConfigForSubId(subId);
4759
4760 boolean requireRcsProvisioning = c.getBoolean(
4761 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4762
4763 // First check to make sure that the capability requires provisioning.
4764 switch (capability) {
4765 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4766 // intentional fallthrough
4767 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4768 if (requireRcsProvisioning) {
4769 // OPTION or PRESENCE requires provisioning
4770 return true;
4771 }
4772 break;
4773 }
4774 }
4775 return false;
4776 }
4777
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004778 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004779 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004780 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4781 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4782 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004783 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4784 mApp, subId, "getImsProvisioningInt");
4785
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004786 final long identity = Binder.clearCallingIdentity();
4787 try {
4788 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004789 int slotId = getSlotIndex(subId);
4790 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4791 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4792 + subId + "' for key:" + key);
4793 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4794 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004795
4796 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4797 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4798 return retVal;
4799 }
4800
calvinpanb5a34062021-02-08 19:59:36 +08004801 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004802 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004803 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4804 + subId + "' for key:" + key);
4805 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004806 } finally {
4807 Binder.restoreCallingIdentity(identity);
4808 }
4809 }
4810
4811 @Override
4812 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004813 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4814 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4815 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004816 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4817 mApp, subId, "getImsProvisioningString");
4818
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004819 final long identity = Binder.clearCallingIdentity();
4820 try {
4821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004822 int slotId = getSlotIndex(subId);
4823 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4824 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4825 + subId + "' for key:" + key);
4826 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4827 }
calvinpanb5a34062021-02-08 19:59:36 +08004828 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004829 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004830 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4831 + subId + "' for key:" + key);
4832 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
4836 }
4837
4838 @Override
4839 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004840 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4841 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4842 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4844 "setImsProvisioningInt");
joonhunshin2c3e4232021-11-28 07:32:01 +00004845
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004849 int slotId = getSlotIndex(subId);
4850 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4851 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4852 + subId + "' for key:" + key);
4853 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4854 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004855
4856 int retVal = ImsProvisioningController.getInstance()
4857 .setProvisioningValue(subId, key, value);
4858 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4859 return retVal;
4860 }
4861
calvinpanb5a34062021-02-08 19:59:36 +08004862 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4863 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004864 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004865 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004866 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
4870 }
4871
4872 @Override
4873 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004874 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4875 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4876 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4878 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004882 int slotId = getSlotIndex(subId);
4883 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4884 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4885 + subId + "' for key:" + key);
4886 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4887 }
calvinpanb5a34062021-02-08 19:59:36 +08004888 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4889 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004891 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
4896 }
4897
Brad Ebinger919631e2021-06-02 17:46:35 -07004898 /**
4899 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4900 * for the given slot ID or no ImsResolver instance has been created.
4901 * @param slotId The slot ID that the IMS service is created for.
4902 * @throws ImsException If there is no ImsService configured for this slot.
4903 */
4904 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4905 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4906 ImsFeature.FEATURE_MMTEL)) {
4907 throw new ImsException("This subscription does not support MMTEL over IMS",
4908 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4909 }
4910 }
4911
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004912 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004913 int slotId = SubscriptionManager.getSlotIndex(subId);
4914 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004915 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4916 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004917 }
4918 return slotId;
4919 }
4920
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 private int getSlotIndex(int subId) {
4922 int slotId = SubscriptionManager.getSlotIndex(subId);
4923 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4924 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4925 }
4926 return slotId;
4927 }
4928
Wink Saville36469e72014-06-11 15:17:00 -07004929 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004930 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004931 */
4932 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004933 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4934 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004935 try {
4936 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4937 } catch (SecurityException se) {
4938 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4939 throw new SecurityException("Package " + callingPackage + " does not belong to "
4940 + Binder.getCallingUid());
4941 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004942 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004943 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004944 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004945 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004946 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004947 mApp, subId, callingPackage, callingFeatureId,
4948 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004949 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4950 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 final long identity = Binder.clearCallingIdentity();
4953 try {
4954 final Phone phone = getPhone(subId);
4955 if (phone != null) {
4956 return phone.getServiceState().getDataNetworkType();
4957 } else {
4958 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4959 }
4960 } finally {
4961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004963 }
4964
4965 /**
4966 * Returns the data network type
4967 */
4968 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004969 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004970 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4971 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004972 }
4973
4974 /**
4975 * Returns the data network type for a subId
4976 */
4977 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004978 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4979 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07004980 String functionName = "getDataNetworkTypeForSubscriber";
4981 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
4982 mApp, functionName)) {
4983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4984 mApp, subId, callingPackage, callingFeatureId, functionName)) {
4985 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4986 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004987 }
4988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 final long identity = Binder.clearCallingIdentity();
4990 try {
4991 final Phone phone = getPhone(subId);
4992 if (phone != null) {
4993 return phone.getServiceState().getDataNetworkType();
4994 } else {
4995 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4996 }
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005000 }
5001
5002 /**
Wink Saville36469e72014-06-11 15:17:00 -07005003 * Returns the Voice network type for a subId
5004 */
5005 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005006 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5007 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005008 String functionName = "getVoiceNetworkTypeForSubscriber";
5009 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5010 mApp, functionName)) {
5011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5012 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5013 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5014 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005015 }
5016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 final long identity = Binder.clearCallingIdentity();
5018 try {
5019 final Phone phone = getPhone(subId);
5020 if (phone != null) {
5021 return phone.getServiceState().getVoiceNetworkType();
5022 } else {
5023 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5024 }
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005028 }
5029
5030 /**
5031 * @return true if a ICC card is present
5032 */
5033 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005034 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005035 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5036 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005037 }
5038
5039 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005040 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005041 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005042 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005043 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 final Phone phone = PhoneFactory.getPhone(slotIndex);
5047 if (phone != null) {
5048 return phone.getIccCard().hasIccCard();
5049 } else {
5050 return false;
5051 }
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005055 }
5056
5057 /**
5058 * Return if the current radio is LTE on CDMA. This
5059 * is a tri-state return value as for a period of time
5060 * the mode may be unknown.
5061 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005062 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005063 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005064 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005065 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005067 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5068 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5069 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005070 }
5071
Sanket Padawe356d7632015-06-22 14:03:32 -07005072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005073 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5074 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005075 try {
5076 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5077 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005078 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5079 }
5080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 final long identity = Binder.clearCallingIdentity();
5082 try {
5083 final Phone phone = getPhone(subId);
5084 if (phone == null) {
5085 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5086 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005087 return TelephonyProperties.lte_on_cdma_device()
5088 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 }
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005092 }
Wink Saville36469e72014-06-11 15:17:00 -07005093 }
5094
Wink Saville36469e72014-06-11 15:17:00 -07005095 /**
5096 * {@hide}
5097 * Returns Default subId, 0 in the case of single standby.
5098 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005099 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005100 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005101 }
5102
Shishir Agrawala9f32182016-04-12 12:00:16 -07005103 private int getSlotForDefaultSubscription() {
5104 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5105 }
5106
Wink Savilleb564aae2014-10-23 10:18:09 -07005107 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005108 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005109 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005110
Pengquan Menge92a50d2018-09-21 15:54:48 -07005111 private boolean isActiveSubscription(int subId) {
5112 return mSubscriptionController.isActiveSubId(subId);
5113 }
5114
Ihab Awadf2177b72013-11-25 13:33:23 -08005115 /**
5116 * @see android.telephony.TelephonyManager.WifiCallingChoices
5117 */
5118 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 final long identity = Binder.clearCallingIdentity();
5120 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005121 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5123 getWhenToMakeWifiCallsDefaultPreference());
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
5126 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005127 }
5128
5129 /**
5130 * @see android.telephony.TelephonyManager.WifiCallingChoices
5131 */
5132 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005136 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
5140 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005141 }
5142
Sailesh Nepald1e68152013-12-12 19:08:02 -08005143 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005144 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005145 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005146 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005147
Jordan Liu4c733742019-02-28 12:03:40 -08005148 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5149 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5150 if (phoneId == -1) {
5151 throw new IllegalArgumentException("Given slot index: " + slotIndex
5152 + " does not correspond to an active phone");
5153 }
5154 return PhoneFactory.getPhone(phoneId);
5155 }
5156
Shishir Agrawal566b7612013-10-28 14:41:00 -07005157 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005158 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5159 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5161 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005163 if (DBG) {
5164 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5165 }
5166 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5167 p2);
5168 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005169
Jordan Liu4c733742019-02-28 12:03:40 -08005170
5171 @Override
5172 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5173 int slotIndex, String callingPackage, String aid, int p2) {
5174 enforceModifyPermission();
5175 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5176 if (DBG) {
5177 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5178 }
5179 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5180 callingPackage, aid, p2);
5181 }
5182
5183 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5184 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 if (TextUtils.equals(ISDR_AID, aid)) {
5188 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005189 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5190 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 if (bestComponent == null
5192 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5193 loge("The calling package is not allowed to access ISD-R.");
5194 throw new SecurityException(
5195 "The calling package is not allowed to access ISD-R.");
5196 }
Derek Tan740e1672017-06-27 14:56:27 -07005197 }
Derek Tan740e1672017-06-27 14:56:27 -07005198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005200 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5201 null /* workSource */);
5202 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 return response;
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
5206 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005207 }
5208
5209 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005210 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5212 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005213 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5214 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5215 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005216
Jordan Liu4c733742019-02-28 12:03:40 -08005217 @Override
5218 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5219 enforceModifyPermission();
5220 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5221 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5222 channel);
5223 }
5224
5225 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 final long identity = Binder.clearCallingIdentity();
5227 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 if (channel < 0) {
5229 return false;
5230 }
Jordan Liu4c733742019-02-28 12:03:40 -08005231 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5232 null /* workSource */);
5233 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 return success;
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005237 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005238 }
5239
5240 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005241 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005242 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5244 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005245 if (DBG) {
5246 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5247 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5248 + p3 + " data=" + data);
5249 }
5250 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5251 command, p1, p2, p3, data);
5252 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005253
Jordan Liu4c733742019-02-28 12:03:40 -08005254 @Override
5255 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5256 int command, int p1, int p2, int p3, String data) {
5257 enforceModifyPermission();
5258 if (DBG) {
5259 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5260 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5261 + p3 + " data=" + data);
5262 }
5263 return iccTransmitApduLogicalChannelWithPermission(
5264 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5265 data);
5266 }
5267
5268 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5269 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005272 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 return "";
5274 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005277 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5278 null /* workSource */);
5279 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 // Append the returned status code to the end of the response payload.
5282 String s = Integer.toHexString(
5283 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5284 if (response.payload != null) {
5285 s = IccUtils.bytesToHexString(response.payload) + s;
5286 }
5287 return s;
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005290 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005291 }
Jake Hambye994d462014-02-03 13:10:13 -08005292
Evan Charltonc66da362014-05-16 14:06:40 -07005293 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005294 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5295 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5297 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005299 if (DBG) {
5300 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5301 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5302 }
5303 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5304 cla, command, p1, p2, p3, data);
5305 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005306
Jordan Liu4c733742019-02-28 12:03:40 -08005307 @Override
5308 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5309 int command, int p1, int p2, int p3, String data) {
5310 enforceModifyPermission();
5311 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5312 if (DBG) {
5313 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5314 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5315 + " data=" + data);
5316 }
5317
5318 return iccTransmitApduBasicChannelWithPermission(
5319 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5320 p2, p3, data);
5321 }
5322
5323 // open APDU basic channel assuming the caller has sufficient permissions
5324 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5325 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5329 && TextUtils.equals(ISDR_AID, data)) {
5330 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005331 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5332 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 if (bestComponent == null
5334 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5335 loge("The calling package is not allowed to select ISD-R.");
5336 throw new SecurityException(
5337 "The calling package is not allowed to select ISD-R.");
5338 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005339 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005342 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5343 null /* workSource */);
5344 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 // Append the returned status code to the end of the response payload.
5347 String s = Integer.toHexString(
5348 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5349 if (response.payload != null) {
5350 s = IccUtils.bytesToHexString(response.payload) + s;
5351 }
5352 return s;
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005355 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005356 }
5357
5358 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005359 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005360 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5362 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 final long identity = Binder.clearCallingIdentity();
5365 try {
5366 if (DBG) {
5367 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5368 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5369 }
5370
5371 IccIoResult response =
5372 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5373 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5374 subId);
5375
5376 if (DBG) {
5377 log("Exchange SIM_IO [R]" + response);
5378 }
5379
5380 byte[] result = null;
5381 int length = 2;
5382 if (response.payload != null) {
5383 length = 2 + response.payload.length;
5384 result = new byte[length];
5385 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5386 } else {
5387 result = new byte[length];
5388 }
5389
5390 result[length - 1] = (byte) response.sw2;
5391 result[length - 2] = (byte) response.sw1;
5392 return result;
5393 } finally {
5394 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005395 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005396 }
5397
Nathan Haroldb3014052017-01-25 15:57:32 -08005398 /**
5399 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5400 * on a particular subscription
5401 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005402 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5403 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005405 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005406 return null;
5407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408
5409 final long identity = Binder.clearCallingIdentity();
5410 try {
5411 if (appType != TelephonyManager.APPTYPE_USIM
5412 && appType != TelephonyManager.APPTYPE_SIM) {
5413 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5414 return null;
5415 }
5416 Object response = sendRequest(
5417 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5418 if (response instanceof String[]) {
5419 return (String[]) response;
5420 }
yincheng zhao2737e882019-09-06 17:06:54 -07005421 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005423 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 } finally {
5425 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005426 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005427 }
5428
yincheng zhao2737e882019-09-06 17:06:54 -07005429 /**
5430 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5431 * subscription.
5432 *
5433 * @param subId the id of the subscription.
5434 * @param appType the uicc app type, must be USIM or SIM.
5435 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5436 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005437 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005438 * @return number of fplmns that is successfully written to the SIM.
5439 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005440 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5441 String callingFeatureId) {
5442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5443 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005444 if (DBG) logv("no permissions for setForbiddenplmns");
5445 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5446 }
5447 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5448 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5449 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5450 }
5451 if (fplmns == null) {
5452 throw new IllegalArgumentException("Fplmn List provided is null");
5453 }
5454 for (String fplmn : fplmns) {
5455 if (!CellIdentity.isValidPlmn(fplmn)) {
5456 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5457 }
5458 }
5459 final long identity = Binder.clearCallingIdentity();
5460 try {
5461 Object response = sendRequest(
5462 CMD_SET_FORBIDDEN_PLMNS,
5463 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5464 subId);
5465 return (int) response;
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
5468 }
5469 }
5470
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005471 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005472 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5474 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 final long identity = Binder.clearCallingIdentity();
5477 try {
5478 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5479 if (response.payload == null) {
5480 return "";
5481 }
Evan Charltonc66da362014-05-16 14:06:40 -07005482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 // Append the returned status code to the end of the response payload.
5484 String s = Integer.toHexString(
5485 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5486 s = IccUtils.bytesToHexString(response.payload) + s;
5487 return s;
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
Evan Charltonc66da362014-05-16 14:06:40 -07005491 }
5492
Jake Hambye994d462014-02-03 13:10:13 -08005493 /**
5494 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5495 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5496 *
5497 * @param itemID the ID of the item to read
5498 * @return the NV item as a String, or null on error.
5499 */
5500 @Override
5501 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005502 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5504 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505
5506 final long identity = Binder.clearCallingIdentity();
5507 try {
5508 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005509 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5511 return value;
5512 } finally {
5513 Binder.restoreCallingIdentity(identity);
5514 }
Jake Hambye994d462014-02-03 13:10:13 -08005515 }
5516
5517 /**
5518 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5519 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5520 *
5521 * @param itemID the ID of the item to read
5522 * @param itemValue the value to write, as a String
5523 * @return true on success; false on any failure
5524 */
5525 @Override
5526 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005527 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5529 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530
5531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5534 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005535 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5537 return success;
5538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540 }
Jake Hambye994d462014-02-03 13:10:13 -08005541 }
5542
5543 /**
5544 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5545 * Used for device configuration by some CDMA operators.
5546 *
5547 * @param preferredRoamingList byte array containing the new PRL
5548 * @return true on success; false on any failure
5549 */
5550 @Override
5551 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5553 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554
5555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5558 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5559 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5560 return success;
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
Jake Hambye994d462014-02-03 13:10:13 -08005564 }
5565
5566 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005567 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005568 * Used for device configuration by some CDMA operators.
5569 *
chen xu6dac5ab2018-10-26 17:39:23 -07005570 * @param slotIndex - device slot.
5571 *
Jake Hambye994d462014-02-03 13:10:13 -08005572 * @return true on success; false on any failure
5573 */
5574 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005575 public boolean resetModemConfig(int slotIndex) {
5576 Phone phone = PhoneFactory.getPhone(slotIndex);
5577 if (phone != null) {
5578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5579 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580
chen xu6dac5ab2018-10-26 17:39:23 -07005581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5584 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5585 return success;
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
5588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 }
chen xu6dac5ab2018-10-26 17:39:23 -07005590 return false;
5591 }
5592
5593 /**
5594 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5595 *
5596 * @param slotIndex - device slot.
5597 *
5598 * @return true on success; false on any failure
5599 */
5600 @Override
5601 public boolean rebootModem(int slotIndex) {
5602 Phone phone = PhoneFactory.getPhone(slotIndex);
5603 if (phone != null) {
5604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5605 mApp, phone.getSubId(), "rebootModem");
5606
5607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5610 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5611 return success;
5612 } finally {
5613 Binder.restoreCallingIdentity(identity);
5614 }
5615 }
5616 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005617 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005618
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005619 public String[] getPcscfAddress(String apnType, String callingPackage,
5620 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005621 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5623 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005624 return new String[0];
5625 }
5626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627 final long identity = Binder.clearCallingIdentity();
5628 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005629 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
Wink Saville36469e72014-06-11 15:17:00 -07005633 }
5634
Brad Ebinger51f743a2017-01-23 13:50:20 -08005635 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005636 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5637 * {@link #disableIms(int)}.
5638 * @param slotIndex device slot.
5639 */
5640 public void resetIms(int slotIndex) {
5641 enforceModifyPermission();
5642
5643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 if (mImsResolver == null) {
5646 // may happen if the does not support IMS.
5647 return;
5648 }
5649 mImsResolver.disableIms(slotIndex);
5650 mImsResolver.enableIms(slotIndex);
5651 } finally {
5652 Binder.restoreCallingIdentity(identity);
5653 }
5654 }
5655
5656 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005657 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5658 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005659 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005660 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005665 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005666 // may happen if the device does not support IMS.
5667 return;
5668 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005669 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 } finally {
5671 Binder.restoreCallingIdentity(identity);
5672 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005673 }
5674
5675 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005676 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5677 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005678 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005679 public void disableIms(int slotId) {
5680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681
5682 final long identity = Binder.clearCallingIdentity();
5683 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005684 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005685 // may happen if the device does not support IMS.
5686 return;
5687 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005688 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689 } finally {
5690 Binder.restoreCallingIdentity(identity);
5691 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005692 }
5693
5694 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005695 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5696 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005697 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005698 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005699 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005700 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701
5702 final long identity = Binder.clearCallingIdentity();
5703 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005704 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005705 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5706 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005707 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005708 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005712 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005713 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005714 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5715 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005716 @Override
5717 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005718 enforceModifyPermission();
5719
5720 final long identity = Binder.clearCallingIdentity();
5721 try {
5722 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005723 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
5727 }
5728
5729 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005730 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005731 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005732 */
5733 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5734 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005738 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005739 // may happen if the device does not support IMS.
5740 return null;
5741 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005742 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005746 }
5747
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005748 /**
5749 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005750 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005751 */
5752 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005757 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005758 // may happen if the device does not support IMS.
5759 return null;
5760 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005761 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005765 }
5766
Brad Ebinger884c07b2018-02-15 16:17:40 -08005767 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005768 * Sets the ImsService Package Name that Telephony will bind to.
5769 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 * @param slotIndex the slot ID that the ImsService should bind for.
5771 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005772 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005773 * @param featureTypes An integer array of feature types associated with a packageName.
5774 * @param packageName The name of the package that the current configuration will be replaced
5775 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005776 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005777 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005778 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5779 int[] featureTypes, String packageName) {
5780 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5783 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005784 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 final long identity = Binder.clearCallingIdentity();
5787 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005788 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005789 // may happen if the device does not support IMS.
5790 return false;
5791 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005792 Map<Integer, String> featureConfig = new HashMap<>();
5793 for (int featureType : featureTypes) {
5794 featureConfig.put(featureType, packageName);
5795 }
5796 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5797 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 } finally {
5799 Binder.restoreCallingIdentity(identity);
5800 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005801 }
5802
5803 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005804 * Clears any carrier ImsService overrides for the slot index specified that were previously
5805 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5806 *
5807 * This should only be used for testing.
5808 *
5809 * @param slotIndex the slot ID that the ImsService should bind for.
5810 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5811 */
5812 @Override
5813 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5814 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5815 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5816 "clearCarrierImsServiceOverride");
5817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5818 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5819 "clearCarrierImsServiceOverride");
5820
5821 final long identity = Binder.clearCallingIdentity();
5822 try {
5823 if (mImsResolver == null) {
5824 // may happen if the device does not support IMS.
5825 return false;
5826 }
5827 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
5830 }
5831 }
5832
5833 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005835 *
5836 * @param slotId The slot that the ImsService is associated with.
5837 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5838 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005840 * @return the package name of the ImsService configuration.
5841 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5843 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005844 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005846 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005847 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5848 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 final long identity = Binder.clearCallingIdentity();
5851 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005853 // may happen if the device does not support IMS.
5854 return "";
5855 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005856 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5858 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005862 }
5863
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005864 /**
5865 * Get the MmTelFeature state associated with the requested subscription id.
5866 * @param subId The subscription that the MmTelFeature is associated with.
5867 * @param callback A callback with an integer containing the
5868 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5869 */
5870 @Override
5871 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5872 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5873 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5874 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5875 "IMS not available on device.");
5876 }
5877 final long token = Binder.clearCallingIdentity();
5878 try {
5879 int slotId = getSlotIndex(subId);
5880 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5881 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5882 + subId + "'");
5883 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5884 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005885 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005886 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5887 try {
5888 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5889 } catch (RemoteException e) {
5890 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5891 + "Ignore");
5892 }
5893 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005894 } catch (ImsException e) {
5895 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005896 } finally {
5897 Binder.restoreCallingIdentity(token);
5898 }
5899 }
5900
Daniel Brightbb5840b2021-01-12 15:48:18 -08005901 /**
5902 * Sets the ims registration state on all valid {@link Phone}s.
5903 */
5904 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005905 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906
5907 final long identity = Binder.clearCallingIdentity();
5908 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005909 // NOTE: Before S, this method only set the default phone.
5910 for (final Phone phone : PhoneFactory.getPhones()) {
5911 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5912 phone.setImsRegistrationState(registered);
5913 }
5914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Wink Saville36469e72014-06-11 15:17:00 -07005918 }
5919
5920 /**
Stuart Scott54788802015-03-30 13:18:01 -07005921 * Set the network selection mode to automatic.
5922 *
5923 */
5924 @Override
5925 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5927 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928
5929 final long identity = Binder.clearCallingIdentity();
5930 try {
shilufc958392020-01-20 11:36:01 -08005931 if (!isActiveSubscription(subId)) {
5932 return;
5933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005935 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5936 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Stuart Scott54788802015-03-30 13:18:01 -07005940 }
5941
Jack Yud10cdd42020-09-28 20:28:01 -07005942 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005943 * Ask the radio to connect to the input network and change selection mode to manual.
5944 *
5945 * @param subId the id of the subscription.
5946 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5947 * the operator to attach to.
5948 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5949 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5950 * normal network selection next time.
5951 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005952 */
5953 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005954 public boolean setNetworkSelectionModeManual(
5955 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5957 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005958
5959 if (!isActiveSubscription(subId)) {
5960 return false;
5961 }
5962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 final long identity = Binder.clearCallingIdentity();
5964 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005965 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005967 if (DBG) {
5968 log("setNetworkSelectionModeManual: subId: " + subId
5969 + " operator: " + operatorInfo);
5970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005975 }
shilu84f6e8b2019-12-19 13:58:01 -08005976 /**
5977 * Get the manual network selection
5978 *
5979 * @param subId the id of the subscription.
5980 *
5981 * @return the previously saved user selected PLMN
5982 */
5983 @Override
5984 public String getManualNetworkSelectionPlmn(int subId) {
5985 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005986 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005987 mApp, subId, "getManualNetworkSelectionPlmn");
5988
5989 final long identity = Binder.clearCallingIdentity();
5990 try {
5991 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005992 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005993 }
5994
5995 final Phone phone = getPhone(subId);
5996 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005997 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005998 }
5999 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6000 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6001 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6002 } finally {
6003 Binder.restoreCallingIdentity(identity);
6004 }
6005 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006006
6007 /**
6008 * Scans for available networks.
6009 */
6010 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006011 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6012 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6014 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006015 LocationAccessPolicy.LocationPermissionResult locationResult =
6016 LocationAccessPolicy.checkLocationPermission(mApp,
6017 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6018 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006019 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006020 .setCallingPid(Binder.getCallingPid())
6021 .setCallingUid(Binder.getCallingUid())
6022 .setMethod("getCellNetworkScanResults")
6023 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006024 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6025 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006026 .build());
6027 switch (locationResult) {
6028 case DENIED_HARD:
6029 throw new SecurityException("Not allowed to access scan results -- location");
6030 case DENIED_SOFT:
6031 return null;
6032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033
Pengquan Menga1bb6272018-09-06 09:59:22 -07006034 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 try {
6036 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006037 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006042 }
6043
6044 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006045 * Get the call forwarding info, given the call forwarding reason.
6046 */
6047 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006048 public void getCallForwarding(int subId, int callForwardingReason,
6049 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006050 enforceReadPrivilegedPermission("getCallForwarding");
6051 long identity = Binder.clearCallingIdentity();
6052 try {
6053 if (DBG) {
6054 log("getCallForwarding: subId " + subId
6055 + " callForwardingReason" + callForwardingReason);
6056 }
Hall Liu27d24262020-09-18 19:04:59 -07006057
6058 Phone phone = getPhone(subId);
6059 if (phone == null) {
6060 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006061 callback.onError(
6062 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006063 } catch (RemoteException e) {
6064 // ignore
6065 }
6066 return;
6067 }
6068
6069 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6070 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6071 @Override
6072 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6073 try {
6074 callback.onCallForwardingInfoAvailable(info);
6075 } catch (RemoteException e) {
6076 // ignore
6077 }
6078 }
6079
6080 @Override
6081 public void onError(int error) {
6082 try {
6083 callback.onError(error);
6084 } catch (RemoteException e) {
6085 // ignore
6086 }
6087 }
6088 });
6089 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
6093 }
6094
6095 /**
6096 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6097 * reason, the number to forward, and the timeout before the forwarding is attempted.
6098 */
6099 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006100 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6101 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006102 enforceModifyPermission();
6103 long identity = Binder.clearCallingIdentity();
6104 try {
6105 if (DBG) {
6106 log("setCallForwarding: subId " + subId
6107 + " callForwardingInfo" + callForwardingInfo);
6108 }
Hall Liu27d24262020-09-18 19:04:59 -07006109
6110 Phone phone = getPhone(subId);
6111 if (phone == null) {
6112 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006113 callback.accept(
6114 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006115 } catch (RemoteException e) {
6116 // ignore
6117 }
6118 return;
6119 }
6120
6121 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6122 FunctionalUtils.ignoreRemoteException(callback::accept));
6123
6124 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006125 } finally {
6126 Binder.restoreCallingIdentity(identity);
6127 }
6128 }
6129
6130 /**
Hall Liu27d24262020-09-18 19:04:59 -07006131 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006132 */
6133 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006134 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006135 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006136 long identity = Binder.clearCallingIdentity();
6137 try {
Hall Liu27d24262020-09-18 19:04:59 -07006138 Phone phone = getPhone(subId);
6139 if (phone == null) {
6140 try {
6141 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6142 } catch (RemoteException e) {
6143 // ignore
6144 }
6145 return;
6146 }
SongFerngWang0e767992021-03-31 22:08:45 +08006147 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6148 PersistableBundle c = configManager.getConfigForSubId(subId);
6149 boolean requireUssd = c.getBoolean(
6150 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006151
Shuo Qian4a594052020-01-23 11:59:30 -08006152 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006153 if (requireUssd) {
6154 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6155 getSubscriptionCarrierId(subId));
6156 String newUssdCommand = "";
6157 try {
6158 newUssdCommand = carrierXmlParser.getFeature(
6159 CarrierXmlParser.FEATURE_CALL_WAITING)
6160 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6161 } catch (NullPointerException e) {
6162 loge("Failed to generate USSD number" + e);
6163 }
6164 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6165 mMainThreadHandler, callback, carrierXmlParser,
6166 CarrierXmlParser.SsEntry.SSAction.QUERY);
6167 final String ussdCommand = newUssdCommand;
6168 Executors.newSingleThreadExecutor().execute(() -> {
6169 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6170 });
6171 } else {
6172 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6173 callback::accept);
6174 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6175 }
Shuo Qian4a594052020-01-23 11:59:30 -08006176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
6179 }
6180
6181 /**
Hall Liu27d24262020-09-18 19:04:59 -07006182 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006183 */
6184 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006185 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006186 enforceModifyPermission();
6187 long identity = Binder.clearCallingIdentity();
6188 try {
Hall Liu27d24262020-09-18 19:04:59 -07006189 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6190
6191 Phone phone = getPhone(subId);
6192 if (phone == null) {
6193 try {
6194 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6195 } catch (RemoteException e) {
6196 // ignore
6197 }
6198 return;
6199 }
6200
SongFerngWang0e767992021-03-31 22:08:45 +08006201 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6202 PersistableBundle c = configManager.getConfigForSubId(subId);
6203 boolean requireUssd = c.getBoolean(
6204 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006205
SongFerngWang0e767992021-03-31 22:08:45 +08006206 if (DBG) log("getCallWaitingStatus: subId " + subId);
6207 if (requireUssd) {
6208 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6209 getSubscriptionCarrierId(subId));
6210 CarrierXmlParser.SsEntry.SSAction ssAction =
6211 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6212 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6213 String newUssdCommand = "";
6214 try {
6215 newUssdCommand = carrierXmlParser.getFeature(
6216 CarrierXmlParser.FEATURE_CALL_WAITING)
6217 .makeCommand(ssAction, null);
6218 } catch (NullPointerException e) {
6219 loge("Failed to generate USSD number" + e);
6220 }
6221 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6222 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6223 final String ussdCommand = newUssdCommand;
6224 Executors.newSingleThreadExecutor().execute(() -> {
6225 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6226 });
6227 } else {
6228 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6229 FunctionalUtils.ignoreRemoteException(callback::accept));
6230
6231 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6232 }
Shuo Qian4a594052020-01-23 11:59:30 -08006233 } finally {
6234 Binder.restoreCallingIdentity(identity);
6235 }
6236 }
6237
6238 /**
yinxub1bed742017-04-17 11:45:04 -07006239 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006240 *
yinxub1bed742017-04-17 11:45:04 -07006241 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006242 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6243 * location related information which will be sent if the caller already possess
6244 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006245 * @param request contains the radio access networks with bands/channels to scan
6246 * @param messenger callback messenger for scan results or errors
6247 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006248 * @return the id of the requested scan which can be used to stop the scan.
6249 */
6250 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006251 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6252 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006253 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6255 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006256 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006257 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6258 if (!renounceFineLocationAccess) {
6259 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6260 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6261 .setCallingPackage(callingPackage)
6262 .setCallingFeatureId(callingFeatureId)
6263 .setCallingPid(Binder.getCallingPid())
6264 .setCallingUid(Binder.getCallingUid())
6265 .setMethod("requestNetworkScan")
6266 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6267 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6268 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6269 .build());
6270 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006271 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006272 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6273 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006274 if (e != null) {
6275 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6276 throw e;
6277 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006278 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006279 return TelephonyScanManager.INVALID_SCAN_ID;
6280 }
6281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 }
Hall Liu912dfd32019-04-25 14:02:26 -07006283 int callingUid = Binder.getCallingUid();
6284 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006288 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006289 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006290 } finally {
6291 Binder.restoreCallingIdentity(identity);
6292 }
yinxu504e1392017-04-12 16:03:22 -07006293 }
6294
Hall Liub2ac8ef2019-02-28 15:56:23 -08006295 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006296 NetworkScanRequest request, int subId, String callingPackage) {
6297 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006298 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6299 boolean hasNetworkScanPermission =
6300 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6301 == PERMISSION_GRANTED;
6302
6303 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6304 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6305 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006306 }
6307
6308 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6309 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006310 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6311 return new SecurityException("Specific channels must not be"
6312 + " scanned without location access.");
6313 }
6314 }
6315 }
6316
Hall Liub2ac8ef2019-02-28 15:56:23 -08006317 return null;
6318 }
6319
yinxu504e1392017-04-12 16:03:22 -07006320 /**
6321 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006322 *
6323 * @param subId id of the subscription
6324 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006325 */
6326 @Override
6327 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6329 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330
Hall Liu912dfd32019-04-25 14:02:26 -07006331 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 final long identity = Binder.clearCallingIdentity();
6333 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006334 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
yinxu504e1392017-04-12 16:03:22 -07006338 }
6339
6340 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006341 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006342 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006343 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006344 */
6345 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006346 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006347 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006348 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006349 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350
6351 final long identity = Binder.clearCallingIdentity();
6352 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006353 if (DBG) log("getAllowedNetworkTypesBitmask");
6354 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6355 int networkTypesBitmask = (result != null ? result[0] : -1);
6356 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6357 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 } finally {
6359 Binder.restoreCallingIdentity(identity);
6360 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006361 }
6362
6363 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006364 * Get the allowed network types for certain reason.
6365 *
6366 * @param subId the id of the subscription.
6367 * @param reason the reason the allowed network type change is taking place
6368 * @return the allowed network types.
6369 */
6370 @Override
6371 public long getAllowedNetworkTypesForReason(int subId,
6372 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006373 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006374 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006375 final long identity = Binder.clearCallingIdentity();
6376 try {
6377 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
6381 }
6382
6383 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006384 * Enable/Disable E-UTRA-NR Dual Connectivity
6385 * @param subId subscription id of the sim card
6386 * @param nrDualConnectivityState expected NR dual connectivity state
6387 * This can be passed following states
6388 * <ol>
6389 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6390 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6391 * <li>Disable NR dual connectivity and force secondary cell to be released
6392 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6393 * </ol>
6394 * @return operation result.
6395 */
6396 @Override
6397 public int setNrDualConnectivityState(int subId,
6398 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6400 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006401 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006402 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6403 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6404 }
6405
Sooraj Sasindran37444802020-08-11 10:40:43 -07006406 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6407 final long identity = Binder.clearCallingIdentity();
6408 try {
6409 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6410 nrDualConnectivityState, subId,
6411 workSource);
6412 if (DBG) log("enableNRDualConnectivity result: " + result);
6413 return result;
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
6417 }
6418
6419 /**
6420 * Is E-UTRA-NR Dual Connectivity enabled
6421 * @return true if dual connectivity is enabled else false
6422 */
6423 @Override
6424 public boolean isNrDualConnectivityEnabled(int subId) {
6425 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006426 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006427 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006428 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006429 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6430 return false;
6431 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006432 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6433 final long identity = Binder.clearCallingIdentity();
6434 try {
6435 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6436 null, subId, workSource);
6437 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6438 return isEnabled;
6439 } finally {
6440 Binder.restoreCallingIdentity(identity);
6441 }
6442 }
6443
6444 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006445 * Set the allowed network types of the device and
6446 * provide the reason triggering the allowed network change.
6447 *
6448 * @param subId the id of the subscription.
6449 * @param reason the reason the allowed network type change is taking place
6450 * @param allowedNetworkTypes the allowed network types.
6451 * @return true on success; false on any failure.
6452 */
6453 @Override
6454 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006455 @TelephonyManager.AllowedNetworkTypesReason int reason,
6456 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6458 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006459 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006460 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6461 return false;
6462 }
6463 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6464 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006465 return false;
6466 }
6467
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006468 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6469 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6470
6471
6472 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6473 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6474 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006475 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006476
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006477 final long identity = Binder.clearCallingIdentity();
6478 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006479 Boolean success = (Boolean) sendRequest(
6480 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6481 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6482
6483 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6484 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
6488 }
6489
6490 /**
Miaoa84611c2019-03-15 09:21:10 +08006491 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006492 *
Miaoa84611c2019-03-15 09:21:10 +08006493 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006494 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006495 * @hide
6496 */
6497 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006498 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006501 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502 try {
Miaoa84611c2019-03-15 09:21:10 +08006503 if (phone != null) {
6504 return phone.hasMatchedTetherApnSetting();
6505 } else {
6506 return false;
6507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 } finally {
6509 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006510 }
Junda Liu475951f2014-11-07 16:45:03 -08006511 }
6512
6513 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006514 * Get the user enabled state of Mobile Data.
6515 *
6516 * TODO: remove and use isUserDataEnabled.
6517 * This can't be removed now because some vendor codes
6518 * calls through ITelephony directly while they should
6519 * use TelephonyManager.
6520 *
6521 * @return true on enabled
6522 */
6523 @Override
6524 public boolean getDataEnabled(int subId) {
6525 return isUserDataEnabled(subId);
6526 }
6527
6528 /**
6529 * Get whether mobile data is enabled per user setting.
6530 *
6531 * There are other factors deciding whether mobile data is actually enabled, but they are
6532 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006533 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006534 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6535 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006536 *
6537 * @return {@code true} if data is enabled else {@code false}
6538 */
6539 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006540 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006541 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006542 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006543 try {
6544 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6545 functionName);
6546 } catch (Exception e) {
6547 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6548 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006549 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006551 mApp, subId, functionName);
6552
Robert Greenwalt646120a2014-05-23 11:54:03 -07006553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554
6555 final long identity = Binder.clearCallingIdentity();
6556 try {
6557 int phoneId = mSubscriptionController.getPhoneId(subId);
6558 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6559 Phone phone = PhoneFactory.getPhone(phoneId);
6560 if (phone != null) {
6561 boolean retVal = phone.isUserDataEnabled();
6562 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6563 return retVal;
6564 } else {
6565 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6566 return false;
6567 }
6568 } finally {
6569 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006570 }
6571 }
6572
6573 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006574 * Checks if the device is capable of mobile data by considering whether whether the
6575 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6576 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006577 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006578 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006579 */
6580 @Override
6581 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006582 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006583 try {
6584 try {
6585 mApp.enforceCallingOrSelfPermission(
6586 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006587 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006588 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006589 try {
6590 mApp.enforceCallingOrSelfPermission(
6591 android.Manifest.permission.READ_PHONE_STATE,
6592 functionName);
6593 } catch (Exception e2) {
6594 mApp.enforceCallingOrSelfPermission(
6595 permission.READ_BASIC_PHONE_STATE, functionName);
6596 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006597 }
6598 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006599 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 Phone phone = PhoneFactory.getPhone(phoneId);
6606 if (phone != null) {
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006607 boolean retVal;
6608 if (phone.isUsingNewDataStack()) {
6609 retVal = phone.getDataNetworkController().getDataSettingsManager()
6610 .isDataEnabled();
6611 } else {
6612 retVal = phone.getDataEnabledSettings().isDataEnabled();
6613 }
6614 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 return retVal;
6616 } else {
6617 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6618 return false;
6619 }
6620 } finally {
6621 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006622 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006623 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006624
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006625 /**
6626 * Check if data is enabled for a specific reason
6627 * @param subId Subscription index
6628 * @param reason the reason the data enable change is taking place
6629 * @return {@code true} if the overall data is enabled; {@code false} if not.
6630 */
6631 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006632 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006633 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006634 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006635 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006636 try {
6637 mApp.enforceCallingOrSelfPermission(
6638 android.Manifest.permission.ACCESS_NETWORK_STATE,
6639 functionName);
6640 } catch (Exception e) {
6641 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6642 functionName);
6643 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006644 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006645 try {
6646 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006647 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006648 } catch (Exception e2) {
6649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006650 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006651 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006652 }
6653
6654
6655 final long identity = Binder.clearCallingIdentity();
6656 try {
6657 int phoneId = mSubscriptionController.getPhoneId(subId);
6658 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006659 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006660 + " reason=" + reason);
6661 }
6662 Phone phone = PhoneFactory.getPhone(phoneId);
6663 if (phone != null) {
6664 boolean retVal;
6665 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6666 retVal = phone.isUserDataEnabled();
6667 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006668 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006669 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006670 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006671 return retVal;
6672 } else {
6673 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006674 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006675 + subId + " retVal=false");
6676 }
6677 return false;
6678 }
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
6682 }
6683
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006684 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006685 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006686 if (uid == Process.PHONE_UID) {
6687 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6688 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006689 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6690 }
6691
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006692 //load access rules from carrier configs, and check those as well: b/139133814
6693 SubscriptionController subController = SubscriptionController.getInstance();
6694 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6695 || subController == null) return privilegeFromSim;
6696
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006697 PackageManager pkgMgr = phone.getContext().getPackageManager();
6698 String[] packages = pkgMgr.getPackagesForUid(uid);
6699
6700 final long identity = Binder.clearCallingIdentity();
6701 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006702 int subId = phone.getSubId();
6703 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6704 // A test override is in place for the privileges for this subId, so don't try to
6705 // read the subscription privileges.
6706 return privilegeFromSim;
6707 }
6708 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006709 SubscriptionManager subManager = (SubscriptionManager)
6710 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6711 for (String pkg : packages) {
6712 if (subManager.canManageSubscription(subInfo, pkg)) {
6713 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6714 }
6715 }
6716 return privilegeFromSim;
6717 } finally {
6718 Binder.restoreCallingIdentity(identity);
6719 }
6720 }
6721
6722 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6723 String pkgName) {
6724 //load access rules from carrier configs, and check those as well: b/139133814
6725 SubscriptionController subController = SubscriptionController.getInstance();
6726 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6727 || subController == null) return privilegeFromSim;
6728
6729 final long identity = Binder.clearCallingIdentity();
6730 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006731 int subId = phone.getSubId();
6732 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6733 // A test override is in place for the privileges for this subId, so don't try to
6734 // read the subscription privileges.
6735 return privilegeFromSim;
6736 }
6737 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006738 SubscriptionManager subManager = (SubscriptionManager)
6739 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6740 return subManager.canManageSubscription(subInfo, pkgName)
6741 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6742 } finally {
6743 Binder.restoreCallingIdentity(identity);
6744 }
6745 }
6746
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006747 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006748 public int getCarrierPrivilegeStatus(int subId) {
6749 final Phone phone = getPhone(subId);
6750 if (phone == null) {
6751 loge("getCarrierPrivilegeStatus: Invalid subId");
6752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6753 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006754 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6755 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006756 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006757 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6758 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006759
6760 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006761 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006762 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006763 }
Junda Liu29340342014-07-10 15:23:27 -07006764
6765 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006766 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006767 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006768 final Phone phone = getPhone(subId);
6769 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006770 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6772 }
6773 UiccProfile profile =
6774 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6775 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006776 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006777 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6778 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006779 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006780 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006781 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 }
6783
6784 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006785 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006786 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006787 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006788 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006789 }
6790
6791 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006792 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6793 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006794 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006795 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6796 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006797 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006798 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006799 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006800 }
6801
6802 @Override
6803 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006804 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006805 if (TextUtils.isEmpty(pkgName))
6806 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006807 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6808 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006809 UiccPort port = UiccController.getInstance().getUiccPort(i);
6810 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006811 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006812 continue;
6813 }
6814
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006815 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006816 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006817 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006818 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6819 break;
6820 }
6821 }
6822
6823 return result;
Junda Liu29340342014-07-10 15:23:27 -07006824 }
Derek Tan89e89d42014-07-08 17:00:10 -07006825
6826 @Override
Junda Liue64de782015-04-16 17:19:16 -07006827 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006828 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006829 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6830 loge("phoneId " + phoneId + " is not valid.");
6831 return null;
6832 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006833 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6834 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006835 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006836 return null ;
6837 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006838 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006839 }
6840
Amith Yamasani6e118872016-02-19 12:53:51 -08006841 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006842 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006843 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006844 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006845 List<String> privilegedPackages = new ArrayList<>();
6846 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006847 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006848 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006849 if (port != null) {
6850 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006851 if (packages == null) {
6852 // Only check packages in user 0 for now
6853 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006854 PackageManager.MATCH_DISABLED_COMPONENTS
6855 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006856 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006857 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006858 }
6859 for (int p = packages.size() - 1; p >= 0; p--) {
6860 PackageInfo pkgInfo = packages.get(p);
6861 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006862 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006863 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006864 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006865 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006866 privilegedPackages.add(pkgInfo.packageName);
6867 }
6868 }
6869 }
6870 }
6871 return privilegedPackages;
6872 }
6873
chen xuf7e9fe82019-05-09 19:31:02 -07006874 @Override
6875 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006876 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6877
6878 final long identity = Binder.clearCallingIdentity();
6879
chen xuf7e9fe82019-05-09 19:31:02 -07006880 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006881 try {
6882 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6883 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6884 }
6885 } finally {
6886 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006887 }
6888 return privilegedPackages;
6889 }
6890
Wink Savilleb564aae2014-10-23 10:18:09 -07006891 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006892 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006893 UiccPort port = phone == null ? null : phone.getUiccPort();
6894 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006895 return null;
6896 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006897 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006898 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006899 return null;
6900 }
6901 return iccId;
6902 }
6903
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006904 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006905 public void setCallComposerStatus(int subId, int status) {
6906 enforceModifyPermission();
6907
6908 final long identity = Binder.clearCallingIdentity();
6909 try {
6910 Phone phone = getPhone(subId);
6911 if (phone != null) {
6912 Phone defaultPhone = phone.getImsPhone();
6913 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6914 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6915 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006916 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6917 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006918 }
6919 }
Shuo Qian284ae752020-12-22 19:10:14 -08006920 } catch (ImsException e) {
6921 throw new ServiceSpecificException(e.getCode());
6922 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006923 Binder.restoreCallingIdentity(identity);
6924 }
6925 }
6926
6927 @Override
6928 public int getCallComposerStatus(int subId) {
6929 enforceReadPrivilegedPermission("getCallComposerStatus");
6930
6931 final long identity = Binder.clearCallingIdentity();
6932 try {
6933 Phone phone = getPhone(subId);
6934 if (phone != null) {
6935 Phone defaultPhone = phone.getImsPhone();
6936 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6937 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6938 return imsPhone.getCallComposerStatus();
6939 }
6940 }
6941 } finally {
6942 Binder.restoreCallingIdentity(identity);
6943 }
6944 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6945 }
6946
6947 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006948 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6949 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006950 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006951 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 final long identity = Binder.clearCallingIdentity();
6954 try {
6955 final String iccId = getIccId(subId);
6956 final Phone phone = getPhone(subId);
6957 if (phone == null) {
6958 return false;
6959 }
6960 final String subscriberId = phone.getSubscriberId();
6961
6962 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006963 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964 + subscriberId + " to " + number);
6965 }
6966
6967 if (TextUtils.isEmpty(iccId)) {
6968 return false;
6969 }
6970
6971 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6972
6973 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6974 if (alphaTag == null) {
6975 editor.remove(alphaTagPrefKey);
6976 } else {
6977 editor.putString(alphaTagPrefKey, alphaTag);
6978 }
6979
6980 // Record both the line number and IMSI for this ICCID, since we need to
6981 // track all merged IMSIs based on line number
6982 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6983 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6984 if (number == null) {
6985 editor.remove(numberPrefKey);
6986 editor.remove(subscriberPrefKey);
6987 } else {
6988 editor.putString(numberPrefKey, number);
6989 editor.putString(subscriberPrefKey, subscriberId);
6990 }
6991
6992 editor.commit();
6993 return true;
6994 } finally {
6995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006996 }
Derek Tan7226c842014-07-02 17:42:23 -07006997 }
6998
6999 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007000 public String getLine1NumberForDisplay(int subId, String callingPackage,
7001 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007002 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007004 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007005 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007006 return null;
7007 }
Derek Tan97ebb422014-09-05 16:55:38 -07007008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009 final long identity = Binder.clearCallingIdentity();
7010 try {
7011 String iccId = getIccId(subId);
7012 if (iccId != null) {
7013 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7014 if (DBG_MERGE) {
7015 log("getLine1NumberForDisplay returning "
7016 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7017 }
7018 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7021 return null;
7022 } finally {
7023 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007024 }
Derek Tan7226c842014-07-02 17:42:23 -07007025 }
7026
7027 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007028 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7029 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007031 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007032 return null;
7033 }
Derek Tan97ebb422014-09-05 16:55:38 -07007034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 final long identity = Binder.clearCallingIdentity();
7036 try {
7037 String iccId = getIccId(subId);
7038 if (iccId != null) {
7039 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7040 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7041 }
7042 return null;
7043 } finally {
7044 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007045 }
Derek Tan7226c842014-07-02 17:42:23 -07007046 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007047
7048 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007049 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7050 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007051 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7052 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007054 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007055 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007056 return null;
7057 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007058
Jordan Liub49b04b2019-05-06 14:45:15 -07007059 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7060 // the process, where TelephonyManager was instantiated.
7061 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007062 final long identity = Binder.clearCallingIdentity();
7063 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007064 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 final TelephonyManager tele = TelephonyManager.from(context);
7066 final SubscriptionManager sub = SubscriptionManager.from(context);
7067
7068 // Figure out what subscribers are currently active
7069 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070
Jordan Liub49b04b2019-05-06 14:45:15 -07007071 // Only consider subs which match the current subId
7072 // This logic can be simplified. See b/131189269 for progress.
7073 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007074 activeSubscriberIds.add(tele.getSubscriberId(subId));
7075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076
7077 // First pass, find a number override for an active subscriber
7078 String mergeNumber = null;
7079 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7080 for (String key : prefs.keySet()) {
7081 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7082 final String subscriberId = (String) prefs.get(key);
7083 if (activeSubscriberIds.contains(subscriberId)) {
7084 final String iccId = key.substring(
7085 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7086 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7087 mergeNumber = (String) prefs.get(numberKey);
7088 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007089 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 + " for active subscriber " + subscriberId);
7091 }
7092 if (!TextUtils.isEmpty(mergeNumber)) {
7093 break;
7094 }
7095 }
7096 }
7097 }
7098
7099 // Shortcut when no active merged subscribers
7100 if (TextUtils.isEmpty(mergeNumber)) {
7101 return null;
7102 }
7103
7104 // Second pass, find all subscribers under that line override
7105 final ArraySet<String> result = new ArraySet<>();
7106 for (String key : prefs.keySet()) {
7107 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7108 final String number = (String) prefs.get(key);
7109 if (mergeNumber.equals(number)) {
7110 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7111 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7112 final String subscriberId = (String) prefs.get(subscriberKey);
7113 if (!TextUtils.isEmpty(subscriberId)) {
7114 result.add(subscriberId);
7115 }
7116 }
7117 }
7118 }
7119
7120 final String[] resultArray = result.toArray(new String[result.size()]);
7121 Arrays.sort(resultArray);
7122 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007123 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7125 }
7126 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007127 } finally {
7128 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007129 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007130 }
7131
7132 @Override
zoey chen38003472019-12-13 17:16:31 +08007133 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7134 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007135
7136 final long identity = Binder.clearCallingIdentity();
7137 try {
7138 final TelephonyManager telephonyManager = mApp.getSystemService(
7139 TelephonyManager.class);
7140 String subscriberId = telephonyManager.getSubscriberId(subId);
7141 if (subscriberId == null) {
7142 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007143 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007144 + subId);
7145 }
7146 return null;
7147 }
7148
7149 final SubscriptionInfo info = SubscriptionController.getInstance()
7150 .getSubscriptionInfo(subId);
7151 final ParcelUuid groupUuid = info.getGroupUuid();
7152 // If it doesn't belong to any group, return just subscriberId of itself.
7153 if (groupUuid == null) {
7154 return new String[]{subscriberId};
7155 }
7156
7157 // Get all subscriberIds from the group.
7158 final List<String> mergedSubscriberIds = new ArrayList<>();
7159 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007160 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007161 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007162 for (SubscriptionInfo subInfo : groupInfos) {
7163 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7164 if (subscriberId != null) {
7165 mergedSubscriberIds.add(subscriberId);
7166 }
7167 }
7168
7169 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
7172
7173 }
7174 }
7175
7176 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007177 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007178 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007179 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180
7181 final long identity = Binder.clearCallingIdentity();
7182 try {
7183 final Phone phone = getPhone(subId);
7184 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7185 } finally {
7186 Binder.restoreCallingIdentity(identity);
7187 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007188 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007189
7190 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007191 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007192 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7193 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007194 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7195 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196
7197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 final Phone phone = getPhone(subId);
7200 if (phone == null) {
7201 return false;
7202 }
7203 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7204 cdmaNonRoamingList);
7205 } finally {
7206 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007207 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007208 }
7209
7210 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007211 @Deprecated
7212 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7213 enforceModifyPermission();
7214
7215 int returnValue = 0;
7216 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007217 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007218 if(result.exception == null) {
7219 if (result.result != null) {
7220 byte[] responseData = (byte[])(result.result);
7221 if(responseData.length > oemResp.length) {
7222 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7223 responseData.length + "bytes. Buffer Size is " +
7224 oemResp.length + "bytes.");
7225 }
7226 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7227 returnValue = responseData.length;
7228 }
7229 } else {
7230 CommandException ex = (CommandException) result.exception;
7231 returnValue = ex.getCommandError().ordinal();
7232 if(returnValue > 0) returnValue *= -1;
7233 }
7234 } catch (RuntimeException e) {
7235 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7236 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7237 if(returnValue > 0) returnValue *= -1;
7238 }
7239
7240 return returnValue;
7241 }
7242
7243 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007244 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007245 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007246 try {
7247 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007248 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007249 mApp, phone.getSubId(), "getRadioAccessFamily");
7250 } catch (SecurityException e) {
7251 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7252 throw e;
7253 }
chen xub97461a2018-10-26 14:17:57 -07007254 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007255 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007256 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007258 final long identity = Binder.clearCallingIdentity();
7259 try {
chen xub97461a2018-10-26 14:17:57 -07007260 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007261 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007262 mApp, phone.getSubId(), "getRadioAccessFamily");
7263 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
chen xub97461a2018-10-26 14:17:57 -07007267 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007268 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007269
7270 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007271 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007272 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007273 try {
7274 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7275 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007276 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007277 }
7278 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007279 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007280 }
7281 RoleManager rm = mApp.getSystemService(RoleManager.class);
7282 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7283 if (!dialerRoleHolders.contains(callingPackage)) {
7284 throw new SecurityException("App must be the dialer role holder to"
7285 + " upload a call composer pic");
7286 }
7287
7288 Executors.newSingleThreadExecutor().execute(() -> {
7289 ByteArrayOutputStream output = new ByteArrayOutputStream(
7290 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7291 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7292 boolean readUntilEnd = false;
7293 int totalBytesRead = 0;
7294 byte[] buffer = new byte[16 * 1024];
7295 while (true) {
7296 int numRead;
7297 try {
7298 numRead = input.read(buffer);
7299 } catch (IOException e) {
7300 try {
7301 fd.checkError();
7302 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7303 null);
7304 } catch (IOException e1) {
7305 // This means that the other side closed explicitly with an error. If this
7306 // happens, log and ignore.
7307 loge("Remote end of call composer picture pipe closed: " + e1);
7308 }
7309 break;
7310 }
7311 if (numRead == -1) {
7312 readUntilEnd = true;
7313 break;
7314 }
7315 totalBytesRead += numRead;
7316 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7317 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7318 try {
7319 input.close();
7320 } catch (IOException e) {
7321 // ignore
7322 }
7323 break;
7324 }
7325 output.write(buffer, 0, numRead);
7326 }
7327 // Generally, the remote end will close the file descriptors. The only case where we
7328 // close is above, where the picture size is too big.
7329
7330 try {
7331 fd.checkError();
7332 } catch (IOException e) {
7333 loge("Remote end for call composer closed with an error: " + e);
7334 return;
7335 }
7336
Hall Liuaa4211e2021-01-20 15:43:39 -08007337 if (!readUntilEnd) {
7338 loge("Did not finish reading entire image; aborting");
7339 return;
7340 }
Hall Liu82694d52020-12-11 18:22:04 -08007341
Hall Liuaa4211e2021-01-20 15:43:39 -08007342 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7343 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7344 new CallComposerPictureTransfer.Factory() {},
7345 imageData,
7346 (result) -> {
7347 if (result.first != null) {
7348 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7349 Bundle outputResult = new Bundle();
7350 outputResult.putParcelable(
7351 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7352 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7353 outputResult);
7354 } else {
7355 callback.send(result.second, null);
7356 }
7357 }
7358 );
Hall Liu82694d52020-12-11 18:22:04 -08007359 });
7360 }
7361
7362 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007363 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007364 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007365 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366
7367 final long identity = Binder.clearCallingIdentity();
7368 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007369 ImsManager.getInstance(defaultPhone.getContext(),
7370 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371 } finally {
7372 Binder.restoreCallingIdentity(identity);
7373 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007374 }
7375
7376 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007377 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007378 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007379 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7380 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007381 return false;
7382 }
Svet Ganovb320e182015-04-16 12:30:10 -07007383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 final long identity = Binder.clearCallingIdentity();
7385 try {
7386 // Check the user preference and the system-level IMS setting. Even if the user has
7387 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7388 // In the long run, we may instead need to check if there exists a connection service
7389 // which can support video calling.
7390 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007391 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 return imsManager.isVtEnabledByPlatform()
7393 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7394 && imsManager.isVtEnabledByUser();
7395 } finally {
7396 Binder.restoreCallingIdentity(identity);
7397 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007398 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007399
Andrew Leea1239f22015-03-02 17:44:07 -08007400 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007401 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7402 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007404 mApp, subId, callingPackage, callingFeatureId,
7405 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 return false;
7407 }
7408
7409 final long identity = Binder.clearCallingIdentity();
7410 try {
7411 CarrierConfigManager configManager =
7412 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007413 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
Andrew Leea1239f22015-03-02 17:44:07 -08007418 }
7419
7420 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007421 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007423 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 return false;
7425 }
7426
7427 final long identity = Binder.clearCallingIdentity();
7428 try {
7429 CarrierConfigManager configManager =
7430 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007431 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7433 } finally {
7434 Binder.restoreCallingIdentity(identity);
7435 }
Andrew Leea1239f22015-03-02 17:44:07 -08007436 }
7437
Andrew Lee9431b832015-03-09 18:46:45 -07007438 @Override
7439 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007440 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007441 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007442 }
7443
7444 @Override
7445 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 final long identity = Binder.clearCallingIdentity();
7447 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007448 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
Andrew Lee9431b832015-03-09 18:46:45 -07007452 }
7453
Hall Liuf6668912018-10-31 17:05:23 -07007454 /**
7455 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7456 * support for the feature and device firmware support.
7457 *
7458 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7459 */
7460 @Override
7461 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007463 final Phone phone = getPhone(subscriptionId);
7464 if (phone == null) {
7465 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7466 return false;
7467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007469 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7471 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007472 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 return isCarrierSupported && isDeviceSupported;
7474 } finally {
7475 Binder.restoreCallingIdentity(identity);
7476 }
Hall Liu98187582018-01-22 19:15:32 -08007477 }
7478
Hall Liuf6668912018-10-31 17:05:23 -07007479 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007480 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7481 * RTT setting, will return true if the device and carrier both support RTT.
7482 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007483 */
7484 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 final long identity = Binder.clearCallingIdentity();
7486 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007487 boolean isRttSupported = isRttSupported(subscriptionId);
7488 boolean isUserRttSettingOn = Settings.Secure.getInt(
7489 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7490 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7491 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7492 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007496 }
7497
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007498 @Deprecated
7499 @Override
7500 public String getDeviceId(String callingPackage) {
7501 return getDeviceIdWithFeature(callingPackage, null);
7502 }
7503
Sanket Padawe7310cc72015-01-14 09:53:20 -08007504 /**
7505 * Returns the unique device ID of phone, for example, the IMEI for
7506 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7507 *
7508 * <p>Requires Permission:
7509 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7510 */
7511 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007512 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007513 try {
7514 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7515 } catch (SecurityException se) {
7516 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7517 throw new SecurityException("Package " + callingPackage + " does not belong to "
7518 + Binder.getCallingUid());
7519 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007520 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007521 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007522 return null;
7523 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007524 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007525 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007527 return null;
7528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529
7530 final long identity = Binder.clearCallingIdentity();
7531 try {
7532 return phone.getDeviceId();
7533 } finally {
7534 Binder.restoreCallingIdentity(identity);
7535 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007536 }
7537
Ping Sunc67b7c22016-03-02 19:16:45 +08007538 /**
7539 * {@hide}
7540 * Returns the IMS Registration Status on a particular subid
7541 *
7542 * @param subId
7543 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007544 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007545 Phone phone = getPhone(subId);
7546 if (phone != null) {
7547 return phone.isImsRegistered();
7548 } else {
7549 return false;
7550 }
7551 }
7552
Santos Cordon7a1885b2015-02-03 11:15:19 -08007553 @Override
7554 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 final long identity = Binder.clearCallingIdentity();
7556 try {
7557 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7558 } finally {
7559 Binder.restoreCallingIdentity(identity);
7560 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007561 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007562
Tyler Gunnf70ed162019-04-03 15:28:53 -07007563 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007564 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007565 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007567 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007568 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7569 }
7570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7573 } finally {
7574 Binder.restoreCallingIdentity(identity);
7575 }
7576 }
7577
7578 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007579 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007580 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007581 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007582 mApp,
7583 subscriptionId,
7584 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007585 final long identity = Binder.clearCallingIdentity();
7586 try {
7587 Phone phone = getPhone(subscriptionId);
7588 if (phone == null) {
7589 return null;
7590 }
7591 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
7595 }
7596
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007597 /**
7598 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007599 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007600 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 Phone phone = getPhone(subId);
7604 if (phone != null) {
7605 return phone.isWifiCallingEnabled();
7606 } else {
7607 return false;
7608 }
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007611 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007612 }
7613
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007614 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007615 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007616 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007617 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618 final long identity = Binder.clearCallingIdentity();
7619 try {
7620 Phone phone = getPhone(subId);
7621 if (phone != null) {
7622 return phone.isVideoEnabled();
7623 } else {
7624 return false;
7625 }
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007628 }
7629 }
7630
7631 /**
7632 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7633 * defined in {@link ImsRegistrationImplBase}.
7634 */
7635 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007636 final long identity = Binder.clearCallingIdentity();
7637 try {
7638 Phone phone = getPhone(subId);
7639 if (phone != null) {
7640 return phone.getImsRegistrationTech();
7641 } else {
7642 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7643 }
7644 } finally {
7645 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007646 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007647 }
7648
Stuart Scott8eef64f2015-04-08 15:13:54 -07007649 @Override
7650 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007651 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007652 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7653 return;
7654 }
Kai Shif70f46f2021-03-03 13:59:46 -08007655 Phone defaultPhone = getDefaultPhone();
7656 if (defaultPhone != null) {
7657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7658 mApp, getDefaultPhone().getSubId(), "factoryReset");
7659 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007660 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007661
Svet Ganovcc087f82015-05-12 20:35:54 -07007662 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007663 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7664 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007665 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007666 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007667 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007668 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007669 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007670 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007671 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007672 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007673 // There has been issues when Sms raw table somehow stores orphan
7674 // fragments. They lead to garbled message when new fragments come
7675 // in and combined with those stale ones. In case this happens again,
7676 // user can reset all network settings which will clean up this table.
7677 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007678 // Clean up IMS settings as well here.
7679 int slotId = getSlotIndex(subId);
7680 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7681 ImsManager.getInstance(mApp, slotId).factoryReset();
7682 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007683
Kai Shif70f46f2021-03-03 13:59:46 -08007684 if (defaultPhone == null) {
7685 return;
7686 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007687 // Erase modem config if erase modem on network setting is enabled.
7688 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7689 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7690 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007691 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007692 }
Kai Shif70f46f2021-03-03 13:59:46 -08007693
7694 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007695 } finally {
7696 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007697 }
7698 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007699
SongFerngWangfd89b102021-05-27 22:44:54 +08007700 @VisibleForTesting
7701 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7702 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7703 return;
7704 }
7705 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7706 RILConstants.PREFERRED_NETWORK_MODE);
7707 SubscriptionManager.setSubscriptionProperty(subId,
7708 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7709 "user=" + defaultNetworkType);
7710 phone.loadAllowedNetworksFromSubscriptionDatabase();
7711 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7712 defaultNetworkType, null);
7713 }
7714
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007715 private void cleanUpSmsRawTable(Context context) {
7716 ContentResolver resolver = context.getContentResolver();
7717 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7718 resolver.delete(uri, null, null);
7719 }
7720
Narayan Kamath1c496c22015-04-16 14:40:19 +01007721 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007722 public String getSimLocaleForSubscriber(int subId) {
7723 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7724 final Phone phone = getPhone(subId);
7725 if (phone == null) {
7726 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007727 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 final long identity = Binder.clearCallingIdentity();
7730 try {
chen xu5d3637b2019-01-21 23:31:38 -08007731 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007732 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007733 if (info == null) {
7734 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7735 return null;
7736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 // Try and fetch the locale from the carrier properties or from the SIM language
7738 // preferences (EF-PL and EF-LI)...
7739 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007741 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7742 if (localeFromDefaultSim != null) {
7743 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7744 if (DBG) log("Using locale from subId: " + subId + " locale: "
7745 + localeFromDefaultSim);
7746 return localeFromDefaultSim.toLanguageTag();
7747 } else {
7748 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007749 }
7750 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 // The SIM language preferences only store a language (e.g. fr = French), not an
7753 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7754 // the SIM and carrier preferences does not include a country we add the country
7755 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007756 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007758 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 return mccLocale.toLanguageTag();
7760 }
7761
7762 if (DBG) log("No locale found - returning null");
7763 return null;
7764 } finally {
7765 Binder.restoreCallingIdentity(identity);
7766 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007767 }
7768
7769 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007770 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007771 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007772 }
7773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774 /**
7775 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7776 */
7777 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007778 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007779 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007780 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007781
Chenjie Yu1ba97252018-01-11 18:16:20 -08007782 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007783 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007784
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007785 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007786 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7787 * representing the state of the modem.
7788 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007789 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7790 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007791 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007792 */
7793 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007794 public void requestModemActivityInfo(ResultReceiver result) {
7795 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007796 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797
7798 final long identity = Binder.clearCallingIdentity();
7799 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007800 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 } finally {
7802 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007803 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007804 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007805
Siddharth Rayb8114062018-06-17 15:02:38 -07007806 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7807 // less than total activity duration.
7808 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7809 if (info == null) {
7810 return false;
7811 }
7812 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007813 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7814 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7815
Siddharth Rayb8114062018-06-17 15:02:38 -07007816 return (info.isValid()
7817 && (info.getSleepTimeMillis() <= activityDurationMs)
7818 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007819 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007820 && (totalTxTimeMs <= activityDurationMs));
7821 }
7822
Jack Yu85bd38a2015-11-09 11:34:32 -08007823 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007824 * Returns the service state information on specified subscription.
7825 */
7826 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007827 public ServiceState getServiceStateForSubscriber(int subId,
7828 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7829 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007831 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007832 return null;
7833 }
7834
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007835 boolean hasFinePermission = false;
7836 boolean hasCoarsePermission = false;
7837 if (!renounceFineLocationAccess) {
7838 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7839 LocationAccessPolicy.checkLocationPermission(mApp,
7840 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7841 .setCallingPackage(callingPackage)
7842 .setCallingFeatureId(callingFeatureId)
7843 .setCallingPid(Binder.getCallingPid())
7844 .setCallingUid(Binder.getCallingUid())
7845 .setMethod("getServiceStateForSubscriber")
7846 .setLogAsInfo(true)
7847 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7848 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7849 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7850 .build());
7851 hasFinePermission =
7852 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7853 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007854
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007855 if (!renounceCoarseLocationAccess) {
7856 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7857 LocationAccessPolicy.checkLocationPermission(mApp,
7858 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7859 .setCallingPackage(callingPackage)
7860 .setCallingFeatureId(callingFeatureId)
7861 .setCallingPid(Binder.getCallingPid())
7862 .setCallingUid(Binder.getCallingUid())
7863 .setMethod("getServiceStateForSubscriber")
7864 .setLogAsInfo(true)
7865 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7866 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7867 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7868 .build());
7869 hasCoarsePermission =
7870 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7871 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007872
Jack Yu479f40e2020-10-27 21:29:25 -07007873 final Phone phone = getPhone(subId);
7874 if (phone == null) {
7875 return null;
7876 }
7877
Jordan Liu0f2bc442020-11-18 16:47:37 -08007878 final long identity = Binder.clearCallingIdentity();
7879
Jack Yu479f40e2020-10-27 21:29:25 -07007880 boolean isCallingPackageDataService = phone.getDataServicePackages()
7881 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007883 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7884 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7885 Rlog.d(LOG_TAG,
7886 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7887 return null;
7888 }
7889
Hall Liuf19c44f2018-11-27 14:38:17 -08007890 ServiceState ss = phone.getServiceState();
7891
7892 // Scrub out the location info in ServiceState depending on what level of access
7893 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007894 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007895 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7896 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007897 } finally {
7898 Binder.restoreCallingIdentity(identity);
7899 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007900 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007901
7902 /**
7903 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7904 *
7905 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7906 * voicemail ringtone.
7907 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7908 * PhoneAccount.
7909 */
7910 @Override
7911 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 final long identity = Binder.clearCallingIdentity();
7913 try {
7914 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7915 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007916 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007919 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7920 } finally {
7921 Binder.restoreCallingIdentity(identity);
7922 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007923 }
7924
7925 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007926 * Sets the per-account voicemail ringtone.
7927 *
7928 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7929 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7930 *
7931 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7932 * voicemail ringtone.
7933 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7934 * PhoneAccount.
7935 */
7936 @Override
7937 public void setVoicemailRingtoneUri(String callingPackage,
7938 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007939 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007940 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007941 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7942 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7944 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7945 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007947
7948 final long identity = Binder.clearCallingIdentity();
7949 try {
7950 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7951 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007952 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953 }
7954 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7955 } finally {
7956 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007957 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007958 }
7959
7960 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007961 * Returns whether vibration is set for voicemail notification in Phone settings.
7962 *
7963 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7964 * voicemail vibration setting.
7965 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7966 */
7967 @Override
7968 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 final long identity = Binder.clearCallingIdentity();
7970 try {
7971 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7972 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007973 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007976 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7977 } finally {
7978 Binder.restoreCallingIdentity(identity);
7979 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007980 }
7981
Youhan Wange64578a2016-05-02 15:32:42 -07007982 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007983 * Sets the per-account voicemail vibration.
7984 *
7985 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7986 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7987 *
7988 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7989 * voicemail vibration setting.
7990 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7991 * specific PhoneAccount.
7992 */
7993 @Override
7994 public void setVoicemailVibrationEnabled(String callingPackage,
7995 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007996 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007997 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007998 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7999 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8001 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8002 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008003 }
8004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 final long identity = Binder.clearCallingIdentity();
8006 try {
8007 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8008 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008009 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 }
8011 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8012 } finally {
8013 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008014 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008015 }
8016
8017 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008018 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8019 *
8020 * @throws SecurityException if the caller does not have the required permission
8021 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008022 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008023 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008024 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008025 }
8026
8027 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008028 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8029 * permission.
8030 *
8031 * @throws SecurityException if the caller does not have the required permission
8032 */
8033 private void enforceSendSmsPermission() {
8034 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8035 }
8036
8037 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008038 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008039 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008040 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008041 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008042 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043 final long identity = Binder.clearCallingIdentity();
8044 try {
8045 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008046 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 if (componentName == null) {
8048 throw new SecurityException(
8049 "Caller not current active visual voicemail package[null]");
8050 }
8051 String vvmPackage = componentName.getPackageName();
8052 if (!callingPackage.equals(vvmPackage)) {
8053 throw new SecurityException("Caller not current active visual voicemail package["
8054 + vvmPackage + "]");
8055 }
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008058 }
8059 }
8060
8061 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008062 * Return the application ID for the app type.
8063 *
8064 * @param subId the subscription ID that this request applies to.
8065 * @param appType the uicc app type.
8066 * @return Application ID for specificied app type, or null if no uicc.
8067 */
8068 @Override
8069 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008070 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008071 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072
8073 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008074 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075 if (phone == null) {
8076 return null;
8077 }
8078 String aid = null;
8079 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008080 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 .getApplicationByType(appType).getAid();
8082 } catch (Exception e) {
8083 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8084 }
8085 return aid;
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008088 }
Youhan Wange64578a2016-05-02 15:32:42 -07008089 }
8090
Youhan Wang4001d252016-05-11 10:29:41 -07008091 /**
8092 * Return the Electronic Serial Number.
8093 *
8094 * @param subId the subscription ID that this request applies to.
8095 * @return ESN or null if error.
8096 */
8097 @Override
8098 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008099 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008100 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101
8102 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008103 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 if (phone == null) {
8105 return null;
8106 }
8107 String esn = null;
8108 try {
8109 esn = phone.getEsn();
8110 } catch (Exception e) {
8111 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8112 }
8113 return esn;
8114 } finally {
8115 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008116 }
Youhan Wang4001d252016-05-11 10:29:41 -07008117 }
8118
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008119 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008120 * Return the Preferred Roaming List Version.
8121 *
8122 * @param subId the subscription ID that this request applies to.
8123 * @return PRLVersion or null if error.
8124 */
8125 @Override
8126 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008127 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008128 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008129
8130 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008131 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132 if (phone == null) {
8133 return null;
8134 }
8135 String cdmaPrlVersion = null;
8136 try {
8137 cdmaPrlVersion = phone.getCdmaPrlVersion();
8138 } catch (Exception e) {
8139 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8140 }
8141 return cdmaPrlVersion;
8142 } finally {
8143 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008144 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008145 }
8146
8147 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008148 * Get snapshot of Telephony histograms
8149 * @return List of Telephony histograms
8150 * @hide
8151 */
8152 @Override
8153 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8155 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008156
8157 final long identity = Binder.clearCallingIdentity();
8158 try {
8159 return RIL.getTelephonyRILTimingHistograms();
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
8162 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008163 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008164
8165 /**
8166 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008167 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8168 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008169 * Require system privileges. In the future we may add this to carrier APIs.
8170 *
Michele Berionne482f8202018-11-27 18:57:59 -08008171 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008172 */
8173 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008174 @TelephonyManager.SetCarrierRestrictionResult
8175 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008176 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008177 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008178
Michele Berionne482f8202018-11-27 18:57:59 -08008179 if (carrierRestrictionRules == null) {
8180 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008181 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183 final long identity = Binder.clearCallingIdentity();
8184 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008185 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008186 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187 } finally {
8188 Binder.restoreCallingIdentity(identity);
8189 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008190 }
8191
8192 /**
8193 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008194 * Get the allowed carrier list and the excluded carrier list, including the priority between
8195 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008196 * Require system privileges. In the future we may add this to carrier APIs.
8197 *
Michele Berionne482f8202018-11-27 18:57:59 -08008198 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008199 */
8200 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008201 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008202 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008203 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008204
8205 final long identity = Binder.clearCallingIdentity();
8206 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008207 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8208 if (response instanceof CarrierRestrictionRules) {
8209 return (CarrierRestrictionRules) response;
8210 }
8211 // Response is an Exception of some kind,
8212 // which is signalled to the user as a NULL retval
8213 return null;
8214 } catch (Exception e) {
8215 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8216 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217 } finally {
8218 Binder.restoreCallingIdentity(identity);
8219 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008220 }
8221
fionaxu59545b42016-05-25 15:53:37 -07008222 /**
fionaxu59545b42016-05-25 15:53:37 -07008223 * Action set from carrier signalling broadcast receivers to enable/disable radio
8224 * @param subId the subscription ID that this action applies to.
8225 * @param enabled control enable or disable radio.
8226 * {@hide}
8227 */
8228 @Override
8229 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8230 enforceModifyPermission();
8231 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232
8233 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008234 if (phone == null) {
8235 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8236 return;
8237 }
8238 try {
8239 phone.carrierActionSetRadioEnabled(enabled);
8240 } catch (Exception e) {
8241 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 } finally {
8243 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008244 }
8245 }
8246
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008247 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008248 * Enable or disable Voice over NR (VoNR)
8249 * @param subId the subscription ID that this action applies to.
8250 * @param enabled enable or disable VoNR.
8251 * @return operation result.
8252 */
8253 @Override
8254 public int setVoNrEnabled(int subId, boolean enabled) {
8255 enforceModifyPermission();
8256 final Phone phone = getPhone(subId);
8257
8258 final long identity = Binder.clearCallingIdentity();
8259 if (phone == null) {
8260 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8261 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8262 }
8263
8264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8265 try {
8266 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8267 workSource);
8268 if (DBG) log("setVoNrEnabled result: " + result);
8269 return result;
8270 } finally {
8271 Binder.restoreCallingIdentity(identity);
8272 }
8273 }
8274
8275 /**
8276 * Is voice over NR enabled
8277 * @return true if VoNR is enabled else false
8278 */
8279 @Override
8280 public boolean isVoNrEnabled(int subId) {
8281 enforceReadPrivilegedPermission("isVoNrEnabled");
8282 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8283 final long identity = Binder.clearCallingIdentity();
8284 try {
8285 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8286 null, subId, workSource);
8287 if (DBG) log("isVoNrEnabled: " + isEnabled);
8288 return isEnabled;
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
8292 }
8293
8294 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008295 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8296 * network status based on which carrier apps could apply actions accordingly,
8297 * enable/disable default url handler for example.
8298 *
8299 * @param subId the subscription ID that this action applies to.
8300 * @param report control start/stop reporting the default network status.
8301 * {@hide}
8302 */
8303 @Override
8304 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8305 enforceModifyPermission();
8306 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307
8308 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008309 if (phone == null) {
8310 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8311 return;
8312 }
8313 try {
8314 phone.carrierActionReportDefaultNetworkStatus(report);
8315 } catch (Exception e) {
8316 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317 } finally {
8318 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008319 }
8320 }
8321
8322 /**
fionaxud9622282017-07-17 17:51:30 -07008323 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8324 * @param subId the subscription ID that this action applies to.
8325 * {@hide}
8326 */
8327 @Override
8328 public void carrierActionResetAll(int subId) {
8329 enforceModifyPermission();
8330 final Phone phone = getPhone(subId);
8331 if (phone == null) {
8332 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8333 return;
8334 }
8335 try {
8336 phone.carrierActionResetAll();
8337 } catch (Exception e) {
8338 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8339 }
8340 }
8341
8342 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008343 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8344 * bug report is being generated.
8345 */
8346 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008347 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008348 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8349 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008350 writer.println("Permission Denial: can't dump Phone from pid="
8351 + Binder.getCallingPid()
8352 + ", uid=" + Binder.getCallingUid()
8353 + "without permission "
8354 + android.Manifest.permission.DUMP);
8355 return;
8356 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008357 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008358 }
Jack Yueb89b242016-06-22 13:27:47 -07008359
Brad Ebingerdac2f002018-04-03 15:17:52 -07008360 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008361 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8362 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8363 @NonNull String[] args) {
8364 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8365 this, in.getFileDescriptor(), out.getFileDescriptor(),
8366 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008367 }
8368
Jack Yueb89b242016-06-22 13:27:47 -07008369 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008370 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008371 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008372 * @param reason the reason the data enable change is taking place
8373 * @param enabled True if enabling the data, otherwise disabling.
8374 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008375 */
8376 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008377 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008378 boolean enabled) {
8379 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8380 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8381 try {
8382 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008383 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008384 } catch (SecurityException se) {
8385 enforceModifyPermission();
8386 }
8387 } else {
8388 enforceModifyPermission();
8389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390
8391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 Phone phone = getPhone(subId);
8394 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008395 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8396 phone.carrierActionSetMeteredApnsEnabled(enabled);
8397 } else {
8398 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8399 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008400 }
8401 } finally {
8402 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008403 }
8404 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008405
8406 /**
8407 * Get Client request stats
8408 * @return List of Client Request Stats
8409 * @hide
8410 */
8411 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008412 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8413 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008415 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008416 return null;
8417 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008418 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008420 final long identity = Binder.clearCallingIdentity();
8421 try {
8422 if (phone != null) {
8423 return phone.getClientRequestStats();
8424 }
8425
8426 return null;
8427 } finally {
8428 Binder.restoreCallingIdentity(identity);
8429 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008430 }
8431
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008432 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008433 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008434 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008435 }
Jack Yueb4124c2017-02-16 15:32:43 -08008436
8437 /**
Grace Chen70990072017-03-24 17:21:30 -07008438 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008439 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008440 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008441 * @param state State of SIM (power down, power up, pass through)
8442 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8443 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8444 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008445 *
8446 **/
8447 @Override
Grace Chen70990072017-03-24 17:21:30 -07008448 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008449 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008450 Phone phone = PhoneFactory.getPhone(slotIndex);
8451
vagdeviaf9a5b92018-08-15 16:01:53 -07008452 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8453
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008454 final long identity = Binder.clearCallingIdentity();
8455 try {
8456 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008457 phone.setSimPowerState(state, null, workSource);
8458 }
8459 } finally {
8460 Binder.restoreCallingIdentity(identity);
8461 }
8462 }
8463
8464 /**
8465 * Set SIM card power state.
8466 *
8467 * @param slotIndex SIM slot id.
8468 * @param state State of SIM (power down, power up, pass through)
8469 * @param callback callback to trigger after success or failure
8470 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8471 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8472 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8473 *
8474 **/
8475 @Override
8476 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8477 IIntegerConsumer callback) {
8478 enforceModifyPermission();
8479 Phone phone = PhoneFactory.getPhone(slotIndex);
8480
8481 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8482
8483 final long identity = Binder.clearCallingIdentity();
8484 try {
8485 if (phone != null) {
8486 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8487 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008488 }
8489 } finally {
8490 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008491 }
8492 }
Shuo Qiandd210312017-04-12 22:11:33 +00008493
Tyler Gunn65d45c22017-06-05 11:22:26 -07008494 private boolean isUssdApiAllowed(int subId) {
8495 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008496 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008497 if (configManager == null) {
8498 return false;
8499 }
8500 PersistableBundle pb = configManager.getConfigForSubId(subId);
8501 if (pb == null) {
8502 return false;
8503 }
8504 return pb.getBoolean(
8505 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8506 }
8507
Shuo Qiandd210312017-04-12 22:11:33 +00008508 /**
8509 * Check if phone is in emergency callback mode
8510 * @return true if phone is in emergency callback mode
8511 * @param subId sub id
8512 */
goneil9c5f4872017-12-05 14:07:56 -08008513 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008514 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008515 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008516 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008517
8518 final long identity = Binder.clearCallingIdentity();
8519 try {
8520 if (phone != null) {
8521 return phone.isInEcm();
8522 } else {
8523 return false;
8524 }
8525 } finally {
8526 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008527 }
8528 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008529
8530 /**
8531 * Get the current signal strength information for the given subscription.
8532 * Because this information is not updated when the device is in a low power state
8533 * it should not be relied-upon to be current.
8534 * @param subId Subscription index
8535 * @return the most recent cached signal strength info from the modem
8536 */
8537 @Override
8538 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008539 final long identity = Binder.clearCallingIdentity();
8540 try {
8541 Phone p = getPhone(subId);
8542 if (p == null) {
8543 return null;
8544 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546 return p.getSignalStrength();
8547 } finally {
8548 Binder.restoreCallingIdentity(identity);
8549 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008550 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008551
Pengquan Meng77b7f132018-08-22 14:49:57 -07008552 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008553 * Get the current modem radio state for the given slot.
8554 * @param slotIndex slot index.
8555 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008556 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008557 * @return the current radio power state from the modem
8558 */
8559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008560 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008561 Phone phone = PhoneFactory.getPhone(slotIndex);
8562 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8564 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008565 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8566 }
8567
8568 final long identity = Binder.clearCallingIdentity();
8569 try {
8570 return phone.getRadioPowerState();
8571 } finally {
8572 Binder.restoreCallingIdentity(identity);
8573 }
8574 }
8575 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8576 }
8577
8578 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008579 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8580 *
8581 * <p>Requires one of the following permissions:
8582 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008583 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008584 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8585 * privileges.
8586 *
8587 * @param subId subscription id
8588 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8589 * {@code false}.
8590 */
8591 @Override
8592 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008593 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008594 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008595 try {
8596 mApp.enforceCallingOrSelfPermission(
8597 android.Manifest.permission.ACCESS_NETWORK_STATE,
8598 functionName);
8599 } catch (Exception e) {
8600 mApp.enforceCallingOrSelfPermission(
8601 permission.READ_BASIC_PHONE_STATE, functionName);
8602 }
Shuo Qian093013d2020-08-13 15:42:55 -07008603 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008604 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008605 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008606 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008607
Pengquan Menga1bb6272018-09-06 09:59:22 -07008608 boolean isEnabled = false;
8609 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008610 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008611 Phone phone = getPhone(subId);
8612 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008613 } finally {
8614 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008615 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008616 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008617 }
8618
8619
8620 /**
8621 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8622 *
8623 * <p> Requires permission:
8624 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8625 * privileges.
8626 *
8627 * @param subId subscription id
8628 * @param isEnabled {@code true} means enable, {@code false} means disable.
8629 */
8630 @Override
8631 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8633 mApp, subId, "setDataRoamingEnabled");
8634
Pengquan Menga1bb6272018-09-06 09:59:22 -07008635 final long identity = Binder.clearCallingIdentity();
8636 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008637 Phone phone = getPhone(subId);
8638 if (phone != null) {
8639 phone.setDataRoamingEnabled(isEnabled);
8640 }
8641 } finally {
8642 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008643 }
8644 }
8645
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008646 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008647 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008648 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008649 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008650 mApp, subId, "isManualNetworkSelectionAllowed");
8651
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008652 boolean isAllowed = true;
8653 final long identity = Binder.clearCallingIdentity();
8654 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008655 Phone phone = getPhone(subId);
8656 if (phone != null) {
8657 isAllowed = phone.isCspPlmnEnabled();
8658 }
8659 } finally {
8660 Binder.restoreCallingIdentity(identity);
8661 }
8662 return isAllowed;
8663 }
8664
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008665 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8666 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8667 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8668 // Update each UiccPort object based on privilege access
8669 UiccPort[] uiccPorts = card.getUiccPortList();
8670 for (UiccPort port : uiccPorts) {
8671 UiccProfile profile = port.getUiccProfile();
8672 if (profile == null ||
8673 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8674 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8675 return false;
8676 }
8677 }
8678 return true;
8679 }
8680
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008681 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008682 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008683 // Verify that tha callingPackage belongs to the calling UID
8684 mApp.getSystemService(AppOpsManager.class)
8685 .checkPackage(Binder.getCallingUid(), callingPackage);
8686
Jordan Liu1e142fc2019-04-22 15:10:43 -07008687 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008688 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008689 try {
8690 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008691 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008692 } catch (SecurityException e) {
8693 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8694 // has carrier privileges on an active UICC
8695 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8696 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008697 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008698 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008699 }
sandeepjs0a502c42021-09-27 15:34:44 +00008700 // checking compatibility, if calling app's target SDK is T and beyond.
8701 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8702 Binder.getCallingUid())) {
8703 isIccIdAccessRestricted = true;
8704 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008705 final long identity = Binder.clearCallingIdentity();
8706 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008707 UiccController uiccController = UiccController.getInstance();
8708 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008709 if (hasReadPermission) {
8710 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008711 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008712
8713 // Remove private info if the caller doesn't have access
8714 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8715 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008716 //setting the value after compatibility check
8717 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008718 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8719 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008720 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008721 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8722 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8723 if (card == null || card.getUiccPortList().length == 0) {
8724 // assume no access if the card or ports are unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008725 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008726 continue;
8727 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008728
8729 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008730 filteredInfos.add(cardInfo);
8731 } else {
sandeepjs0a502c42021-09-27 15:34:44 +00008732 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008733 }
8734 }
8735 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008736 } finally {
8737 Binder.restoreCallingIdentity(identity);
8738 }
8739 }
8740
sandeepjs0a502c42021-09-27 15:34:44 +00008741 /**
8742 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8743 * generally private and require carrier privileges to view.
8744 *
8745 * @hide
8746 */
8747 @NonNull
8748 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8749 List<UiccPortInfo> portinfo = new ArrayList<>();
8750 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8751 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8752 }
8753 return new UiccCardInfo(
8754 cardInfo.isEuicc(),
8755 cardInfo.getCardId(),
8756 null,
8757 cardInfo.getPhysicalSlotIndex(),
8758 cardInfo.isRemovable(),
8759 cardInfo.isMultipleEnabledProfilesSupported(),
8760 portinfo
8761 );
8762 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008763
sandeepjs0a502c42021-09-27 15:34:44 +00008764 /**
8765 * @hide
8766 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8767 * These values are generally private and require carrier privileges to view.
8768 */
8769 @NonNull
8770 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8771 return new UiccPortInfo(
8772 UiccPortInfo.ICCID_REDACTED,
8773 portInfo.getPortIndex(),
8774 portInfo.getLogicalSlotIndex(),
8775 portInfo.isActive()
8776 );
8777 }
8778 @Override
8779 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
8780 // Verify that tha callingPackage belongs to the calling UID
8781 mApp.getSystemService(AppOpsManager.class)
8782 .checkPackage(Binder.getCallingUid(), callingPackage);
8783
8784 boolean hasReadPermission = false;
8785 boolean isLogicalSlotAccessRestricted = false;
8786 String iccId;
8787
8788 try {
8789 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8790 hasReadPermission = true;
8791 } catch (SecurityException e) {
8792 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8793 // has carrier privileges on an active UICC
8794 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8795 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8796 hasReadPermission = true;
8797 }
8798 }
8799
8800 // checking compatibility, if calling app's target SDK is T and beyond.
8801 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8802 Binder.getCallingUid())) {
8803 isLogicalSlotAccessRestricted = true;
8804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008805 final long identity = Binder.clearCallingIdentity();
8806 try {
8807 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8808 if (slots == null) {
8809 Rlog.i(LOG_TAG, "slots is null.");
8810 return null;
8811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008812 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8813 for (int i = 0; i < slots.length; i++) {
8814 UiccSlot slot = slots[i];
8815 if (slot == null) {
8816 continue;
8817 }
8818
Jordan Liu7be7e652019-05-06 18:55:02 +00008819 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008820 UiccCard card = slot.getUiccCard();
sandeepjs0a502c42021-09-27 15:34:44 +00008821 //if has read permission
8822 if (hasReadPermission) {
8823 iccId = slot.getIccId();
8824 } else {
8825 // if no read permission checking carrier
8826 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
8827 iccId = slot.getIccId();
8828 } else {
8829 //if no carrier permission redact ICCID
8830 iccId = IccUtils.TEST_ICCID;
8831 }
8832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008833 if (card != null) {
8834 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008835 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008836 cardId = slot.getEid();
8837 if (TextUtils.isEmpty(cardId)) {
sandeepjs0a502c42021-09-27 15:34:44 +00008838 cardId = iccId;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008840 }
8841
Jordan Liu857451f2019-05-09 16:35:35 -07008842 if (cardId != null) {
8843 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8844 // if cardId is an EID, it's all digits so this is fine
8845 cardId = IccUtils.stripTrailingFs(cardId);
8846 }
8847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008848 int cardState = 0;
8849 switch (slot.getCardState()) {
8850 case CARDSTATE_ABSENT:
8851 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8852 break;
8853 case CARDSTATE_PRESENT:
8854 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8855 break;
8856 case CARDSTATE_ERROR:
8857 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8858 break;
8859 case CARDSTATE_RESTRICTED:
8860 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8861 break;
8862 default:
8863 break;
8864
8865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008866 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008867 slot.isEuicc(),
8868 cardId,
8869 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008870 slot.isExtendedApduSupported(),
sandeepjs0a502c42021-09-27 15:34:44 +00008871 slot.isRemovable(), Collections.singletonList(
8872 new UiccPortInfo(
8873 iccId,
8874 0 /* TODO: to use portList from UiccSlots */,
8875 slot.getPhoneId(),
8876 slot.isActive())));
8877 //setting the value after compatibility check
8878 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008879 }
8880 return infos;
8881 } finally {
8882 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008883 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008884 }
8885
8886 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008887 @Deprecated
8888 //TODO : once integrating with HAL Changes we can clean up this Internal API.
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008889 public boolean switchSlots(int[] physicalSlots) {
8890 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008891
8892 final long identity = Binder.clearCallingIdentity();
8893 try {
8894 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8895 } finally {
8896 Binder.restoreCallingIdentity(identity);
8897 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008898 }
Jack Yu4c988042018-02-27 15:30:01 -08008899
8900 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008901 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8902 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8903 enforceModifyPermission();
8904
8905 final long identity = Binder.clearCallingIdentity();
8906 try {
8907 //TODO: once integrating the HAL changes we can proceed with to work on the parsing side
8908 int[] physicalSlots = new int[slotMapping.size()];
8909 for (int i = 0; i < physicalSlots.length; i++) {
8910 physicalSlots[i] = slotMapping.get(i).getPhysicalSlotIndex();
8911 }
8912 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8913 } finally {
8914 Binder.restoreCallingIdentity(identity);
8915 }
8916 }
8917
8918 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008919 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008920 final long identity = Binder.clearCallingIdentity();
8921 try {
8922 return UiccController.getInstance().getCardIdForDefaultEuicc();
8923 } finally {
8924 Binder.restoreCallingIdentity(identity);
8925 }
8926 }
8927
Pengquan Meng85728fb2018-03-12 16:31:21 -07008928 /**
goneil47ffb6e2018-04-06 15:40:58 -07008929 * A test API to reload the UICC profile.
8930 *
8931 * <p>Requires that the calling app has permission
8932 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8933 * @hide
8934 */
8935 @Override
8936 public void refreshUiccProfile(int subId) {
8937 enforceModifyPermission();
8938
8939 final long identity = Binder.clearCallingIdentity();
8940 try {
8941 Phone phone = getPhone(subId);
8942 if (phone == null) {
8943 return;
8944 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008945 UiccPort uiccPort = phone.getUiccPort();
8946 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008947 return;
8948 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008949 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008950 if (uiccProfile == null) {
8951 return;
8952 }
8953 uiccProfile.refresh();
8954 } finally {
8955 Binder.restoreCallingIdentity(identity);
8956 }
8957 }
8958
8959 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008960 * Returns false if the mobile data is disabled by default, otherwise return true.
8961 */
8962 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008963 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008964 }
8965
8966 /**
8967 * Returns true if the data roaming is enabled by default, i.e the system property
8968 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8969 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8970 */
8971 private boolean getDefaultDataRoamingEnabled(int subId) {
8972 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008973 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008974 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008975 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8976 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8977 return isDataRoamingEnabled;
8978 }
8979
8980 /**
8981 * Returns the default network type for the given {@code subId}, if the default network type is
8982 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8983 */
8984 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008985 List<Integer> list = TelephonyProperties.default_network();
8986 int phoneId = mSubscriptionController.getPhoneId(subId);
8987 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8988 return list.get(phoneId);
8989 }
8990 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008991 }
fionaxua13278b2018-03-21 00:08:13 -07008992
8993 @Override
8994 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008995 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008996 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008997
8998 final long identity = Binder.clearCallingIdentity();
8999 try {
9000 final Phone phone = getPhone(subId);
9001 if (phone == null) {
9002 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9003 return;
9004 }
chen xueaba88a2019-03-15 13:15:10 -07009005 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9006 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009007 if (carrierPrivilegeRules == null) {
9008 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9009 } else {
9010 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009012 } finally {
9013 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009014 }
fionaxua13278b2018-03-21 00:08:13 -07009015 }
9016
9017 @Override
9018 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009019 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009020
9021 final long identity = Binder.clearCallingIdentity();
9022 try {
9023 final Phone phone = getPhone(subId);
9024 if (phone == null) {
9025 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9026 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9027 }
9028 return phone.getCarrierIdListVersion();
9029 } finally {
9030 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009031 }
fionaxua13278b2018-03-21 00:08:13 -07009032 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009033
9034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009035 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9036 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009038 mApp, subId, callingPackage, callingFeatureId,
9039 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009040 return -1;
9041 }
9042
9043 final long identity = Binder.clearCallingIdentity();
9044 try {
9045 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9046 } finally {
9047 Binder.restoreCallingIdentity(identity);
9048 }
9049 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009050
9051 @Override
9052 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009053 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009054 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009055 mApp, subId, "getCdmaRoamingMode");
9056
9057 final long identity = Binder.clearCallingIdentity();
9058 try {
9059 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9060 } finally {
9061 Binder.restoreCallingIdentity(identity);
9062 }
9063 }
9064
9065 @Override
9066 public boolean setCdmaRoamingMode(int subId, int mode) {
9067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9068 mApp, subId, "setCdmaRoamingMode");
9069
9070 final long identity = Binder.clearCallingIdentity();
9071 try {
9072 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9073 } finally {
9074 Binder.restoreCallingIdentity(identity);
9075 }
9076 }
9077
9078 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009079 public int getCdmaSubscriptionMode(int subId) {
9080 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009081 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009082 mApp, subId, "getCdmaSubscriptionMode");
9083
9084 final long identity = Binder.clearCallingIdentity();
9085 try {
9086 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9087 } finally {
9088 Binder.restoreCallingIdentity(identity);
9089 }
9090 }
9091
9092 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009093 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9095 mApp, subId, "setCdmaSubscriptionMode");
9096
9097 final long identity = Binder.clearCallingIdentity();
9098 try {
9099 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9100 } finally {
9101 Binder.restoreCallingIdentity(identity);
9102 }
9103 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009104
sqianc5eccab2018-10-19 18:46:41 -07009105 @Override
sqian8c685422019-02-22 15:55:18 -08009106 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009107 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009109 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9110 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009111 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9112 }
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
sqian854d44b2018-12-12 16:48:18 -08009115 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9116 for (Phone phone: PhoneFactory.getPhones()) {
9117 if (phone.getEmergencyNumberTracker() != null
9118 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9119 emergencyNumberListInternal.put(
9120 phone.getSubId(),
9121 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9122 }
sqian11b7a0e2018-12-05 18:48:28 -08009123 }
sqian854d44b2018-12-12 16:48:18 -08009124 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009125 } finally {
9126 Binder.restoreCallingIdentity(identity);
9127 }
sqianc5eccab2018-10-19 18:46:41 -07009128 }
9129
9130 @Override
sqian8c685422019-02-22 15:55:18 -08009131 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009132 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009133 if (!exactMatch) {
9134 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009135 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009136 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009137 }
9138 final long identity = Binder.clearCallingIdentity();
9139 try {
sqian854d44b2018-12-12 16:48:18 -08009140 for (Phone phone: PhoneFactory.getPhones()) {
9141 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009142 && phone.getEmergencyNumberTracker()
9143 .isEmergencyNumber(number, exactMatch)) {
9144 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009145 }
sqian11b7a0e2018-12-05 18:48:28 -08009146 }
9147 return false;
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
9152
sqianf4ca7ed2019-01-15 18:32:07 -08009153 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009154 * Start emergency callback mode for GsmCdmaPhone for testing.
9155 */
9156 @Override
9157 public void startEmergencyCallbackMode() {
9158 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9159 "startEmergencyCallbackMode");
9160 enforceModifyPermission();
9161 final long identity = Binder.clearCallingIdentity();
9162 try {
9163 for (Phone phone : PhoneFactory.getPhones()) {
9164 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9165 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9166 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9167 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9168 gsmCdmaPhone.obtainMessage(
9169 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9170 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9171 }
9172 }
9173 } finally {
9174 Binder.restoreCallingIdentity(identity);
9175 }
9176 }
9177
9178 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009179 * Update emergency number list for test mode.
9180 */
9181 @Override
9182 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9183 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9184 "updateEmergencyNumberListTestMode");
9185
9186 final long identity = Binder.clearCallingIdentity();
9187 try {
9188 for (Phone phone: PhoneFactory.getPhones()) {
9189 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9190 if (tracker != null) {
9191 tracker.executeEmergencyNumberTestModeCommand(action, num);
9192 }
9193 }
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
9196 }
9197 }
9198
9199 /**
9200 * Get the full emergency number list for test mode.
9201 */
9202 @Override
9203 public List<String> getEmergencyNumberListTestMode() {
9204 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9205 "getEmergencyNumberListTestMode");
9206
9207 final long identity = Binder.clearCallingIdentity();
9208 try {
9209 Set<String> emergencyNumbers = new HashSet<>();
9210 for (Phone phone: PhoneFactory.getPhones()) {
9211 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9212 if (tracker != null) {
9213 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9214 emergencyNumbers.add(num.getNumber());
9215 }
9216 }
9217 }
9218 return new ArrayList<>(emergencyNumbers);
9219 } finally {
9220 Binder.restoreCallingIdentity(identity);
9221 }
9222 }
9223
chen xud6b45bd2018-10-30 22:27:10 -07009224 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009225 public int getEmergencyNumberDbVersion(int subId) {
9226 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9227
9228 final long identity = Binder.clearCallingIdentity();
9229 try {
9230 final Phone phone = getPhone(subId);
9231 if (phone == null) {
9232 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9233 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9234 }
9235 return phone.getEmergencyNumberDbVersion();
9236 } finally {
9237 Binder.restoreCallingIdentity(identity);
9238 }
9239 }
9240
9241 @Override
9242 public void notifyOtaEmergencyNumberDbInstalled() {
9243 enforceModifyPermission();
9244
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
9247 for (Phone phone: PhoneFactory.getPhones()) {
9248 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9249 if (tracker != null) {
9250 tracker.updateOtaEmergencyNumberDatabase();
9251 }
9252 }
9253 } finally {
9254 Binder.restoreCallingIdentity(identity);
9255 }
9256 }
9257
9258 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009259 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009260 enforceActiveEmergencySessionPermission();
9261
9262 final long identity = Binder.clearCallingIdentity();
9263 try {
9264 for (Phone phone: PhoneFactory.getPhones()) {
9265 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9266 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009267 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9268 }
9269 }
9270 } finally {
9271 Binder.restoreCallingIdentity(identity);
9272 }
9273 }
9274
9275 @Override
9276 public void resetOtaEmergencyNumberDbFilePath() {
9277 enforceActiveEmergencySessionPermission();
9278
9279 final long identity = Binder.clearCallingIdentity();
9280 try {
9281 for (Phone phone: PhoneFactory.getPhones()) {
9282 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9283 if (tracker != null) {
9284 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009285 }
9286 }
9287 } finally {
9288 Binder.restoreCallingIdentity(identity);
9289 }
9290 }
9291
9292 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009293 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9294 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9295 Phone phone = getPhone(subId);
9296 if (phone == null) {
9297 return null;
9298 }
9299 final long identity = Binder.clearCallingIdentity();
9300 try {
9301 UiccProfile profile = UiccController.getInstance()
9302 .getUiccProfileForPhone(phone.getPhoneId());
9303 if (profile != null) {
9304 return profile.getCertsFromCarrierPrivilegeAccessRules();
9305 }
9306 } finally {
9307 Binder.restoreCallingIdentity(identity);
9308 }
9309 return null;
9310 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009311
9312 /**
9313 * Enable or disable a modem stack.
9314 */
9315 @Override
9316 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9317 enforceModifyPermission();
9318
9319 final long identity = Binder.clearCallingIdentity();
9320 try {
9321 Phone phone = PhoneFactory.getPhone(slotIndex);
9322 if (phone == null) {
9323 return false;
9324 } else {
9325 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9326 }
9327 } finally {
9328 Binder.restoreCallingIdentity(identity);
9329 }
9330 }
Michelecea4cf22018-12-21 15:00:11 -08009331
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009332 /**
9333 * Whether a modem stack is enabled or not.
9334 */
9335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009336 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9337 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009338 Phone phone = PhoneFactory.getPhone(slotIndex);
9339 if (phone == null) return false;
9340
9341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009342 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9343 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009344 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9345 }
9346
9347 final long identity = Binder.clearCallingIdentity();
9348 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009349 try {
9350 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9351 } catch (NoSuchElementException ex) {
9352 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9353 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009354 } finally {
9355 Binder.restoreCallingIdentity(identity);
9356 }
9357 }
9358
Michelecea4cf22018-12-21 15:00:11 -08009359 @Override
Michele0ea7d782019-03-19 14:58:42 -07009360 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009361 enforceModifyPermission();
9362
9363 final long identity = Binder.clearCallingIdentity();
9364 try {
9365 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009366 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009367 .commit();
9368 } finally {
9369 Binder.restoreCallingIdentity(identity);
9370 }
9371 }
9372
9373 @Override
Michele0ea7d782019-03-19 14:58:42 -07009374 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009375 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009377 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9378 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009379 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009380 }
Michelecea4cf22018-12-21 15:00:11 -08009381
9382 final long identity = Binder.clearCallingIdentity();
9383 try {
Michele0ea7d782019-03-19 14:58:42 -07009384 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009385 } finally {
9386 Binder.restoreCallingIdentity(identity);
9387 }
9388 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009389
Michele0ea7d782019-03-19 14:58:42 -07009390 @TelephonyManager.IsMultiSimSupportedResult
9391 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009392 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9393 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9394 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009395 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9396 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009397 }
9398 // Check if the hardware supports multisim functionality. If usage of multisim is not
9399 // supported by the modem, indicate that it is restricted.
9400 PhoneCapability staticCapability =
9401 mPhoneConfigurationManager.getStaticPhoneCapability();
9402 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009403 loge("isMultiSimSupportedInternal: no static configuration available");
9404 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009405 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009406 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009407 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9408 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009409 }
9410 // Check if support of multiple SIMs is restricted by carrier
9411 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009412 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009413 }
9414
Michele0ea7d782019-03-19 14:58:42 -07009415 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009416 }
9417
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009418 /**
9419 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009420 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9421 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9422 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009423 * @param numOfSims number of active sims we want to switch to
9424 */
9425 @Override
9426 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009427 if (numOfSims == 1) {
9428 enforceModifyPermission();
9429 } else {
9430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9431 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9432 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009433 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009434
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009435 try {
Michele30b57b22019-03-01 12:01:14 -08009436 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009437 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009438 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9439 return;
9440 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009441 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9442 } finally {
9443 Binder.restoreCallingIdentity(identity);
9444 }
9445 }
9446
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009447 @Override
9448 public boolean isApplicationOnUicc(int subId, int appType) {
9449 enforceReadPrivilegedPermission("isApplicationOnUicc");
9450 Phone phone = getPhone(subId);
9451 if (phone == null) {
9452 return false;
9453 }
9454 final long identity = Binder.clearCallingIdentity();
9455 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009456 UiccPort uiccPort = phone.getUiccPort();
9457 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009458 return false;
9459 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009460 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009461 if (uiccProfile == null) {
9462 return false;
9463 }
9464 if (TelephonyManager.APPTYPE_SIM <= appType
9465 && appType <= TelephonyManager.APPTYPE_ISIM) {
9466 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9467 }
9468 return false;
9469 } finally {
9470 Binder.restoreCallingIdentity(identity);
9471 }
9472 }
9473
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009474 /**
chen xub4baa772019-04-03 10:23:41 -07009475 * Get whether making changes to modem configurations will trigger reboot.
9476 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009477 */
9478 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009479 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9480 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009482 mApp, subId, callingPackage, callingFeatureId,
9483 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009484 return false;
9485 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009486 final long identity = Binder.clearCallingIdentity();
9487 try {
9488 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9489 } finally {
9490 Binder.restoreCallingIdentity(identity);
9491 }
9492 }
9493
Nathan Harold29f5f052019-02-15 13:41:57 -08009494 private void updateModemStateMetrics() {
9495 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9496 // TODO: check the state for each modem if the api is ready.
9497 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9498 }
9499
Pengquan Meng3889a572019-01-23 11:16:29 -08009500 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00009501 public int[] getSlotsMapping(@NonNull String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009502 enforceReadPrivilegedPermission("getSlotsMapping");
9503
9504 final long identity = Binder.clearCallingIdentity();
9505 try {
9506 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9507 // All logical slots should have a mapping to a physical slot.
9508 int[] logicalSlotsMapping = new int[phoneCount];
sandeepjs0a502c42021-09-27 15:34:44 +00009509 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009510 for (int i = 0; i < slotInfos.length; i++) {
9511 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9512 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9513 }
9514 }
9515 return logicalSlotsMapping;
9516 } finally {
9517 Binder.restoreCallingIdentity(identity);
9518 }
9519 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009520
9521 /**
9522 * Get the IRadio HAL Version
9523 */
9524 @Override
9525 public int getRadioHalVersion() {
9526 Phone phone = getDefaultPhone();
9527 if (phone == null) return -1;
9528 HalVersion hv = phone.getHalVersion();
9529 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9530 return hv.major * 100 + hv.minor;
9531 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009532
9533 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009534 * Get the current calling package name.
9535 * @return the current calling package name
9536 */
9537 @Override
9538 public String getCurrentPackageName() {
9539 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9540 }
9541
9542 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009543 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9544 * corresponding network requests on a subId.
9545 *
9546 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009547 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009548 * 2) APN is un-metered for this subscription, or
9549 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009550 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009551 *
9552 * @return whether data is allowed for a apn type.
9553 *
9554 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009555 */
9556 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009557 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009558 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9559 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009560
9561 // Now that all security checks passes, perform the operation as ourselves.
9562 final long identity = Binder.clearCallingIdentity();
9563 try {
9564 Phone phone = getPhone(subId);
9565 if (phone == null) return false;
9566
Jack Yu41407ee2019-05-13 16:54:09 -07009567 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009568 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9569 } finally {
9570 Binder.restoreCallingIdentity(identity);
9571 }
9572 }
9573
9574 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009575 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009576 enforceReadPrivilegedPermission("isApnMetered");
9577
9578 // Now that all security checks passes, perform the operation as ourselves.
9579 final long identity = Binder.clearCallingIdentity();
9580 try {
9581 Phone phone = getPhone(subId);
9582 if (phone == null) return true; // By default return true.
9583
Jack Yu41407ee2019-05-13 16:54:09 -07009584 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009585 } finally {
9586 Binder.restoreCallingIdentity(identity);
9587 }
9588 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009589
9590 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009591 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9592 int subscriptionId, IBooleanConsumer resultCallback) {
9593 enforceModifyPermission();
9594 long token = Binder.clearCallingIdentity();
9595 try {
9596 Phone phone = getPhone(subscriptionId);
9597 if (phone == null) {
9598 try {
9599 if (resultCallback != null) {
9600 resultCallback.accept(false);
9601 }
9602 } catch (RemoteException e) {
9603 // ignore
9604 }
9605 return;
9606 }
9607 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9608 Pair.create(specifiers, (x) -> {
9609 try {
9610 if (resultCallback != null) {
9611 resultCallback.accept(x);
9612 }
9613 } catch (RemoteException e) {
9614 // ignore
9615 }
9616 });
9617 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9618 } finally {
9619 Binder.restoreCallingIdentity(token);
9620 }
9621 }
9622
9623 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009624 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9625 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009626 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009627 mApp, subId, "getSystemSelectionChannels");
9628 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9629 final long identity = Binder.clearCallingIdentity();
9630 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009631 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9632 if (result instanceof IllegalStateException) {
9633 throw (IllegalStateException) result;
9634 }
9635 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009636 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9637 return specifiers;
9638 } finally {
9639 Binder.restoreCallingIdentity(identity);
9640 }
9641 }
9642
9643 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009644 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009645 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009646 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9647 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9648 if (iccRecords == null) {
9649 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9650 return false;
9651 }
9652 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9653 }
9654
9655 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009656 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9657 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009658 if (callingPackage == null) {
9659 callingPackage = getCurrentPackageName();
9660 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009661 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9662 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009663 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9664 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009665 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9666 }
9667 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9668 Intent intent = new Intent();
9669 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9670 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9671 // Bring up choose default SMS subscription dialog right now
9672 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9673 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9674 mApp.startActivity(intent);
9675 }
chen xud5ca2d52019-05-28 15:20:57 -07009676
9677 @Override
9678 public String getMmsUAProfUrl(int subId) {
9679 //TODO investigate if this API should require proper permission check in R b/133791609
9680 final long identity = Binder.clearCallingIdentity();
9681 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009682 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9683 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9684 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9685 return carrierUAProfUrl;
9686 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009687 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9688 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009689 } finally {
9690 Binder.restoreCallingIdentity(identity);
9691 }
9692 }
9693
9694 @Override
9695 public String getMmsUserAgent(int subId) {
9696 //TODO investigate if this API should require proper permission check in R b/133791609
9697 final long identity = Binder.clearCallingIdentity();
9698 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009699 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9700 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9701 if (!TextUtils.isEmpty(carrierUserAgent)) {
9702 return carrierUserAgent;
9703 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009704 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9705 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009706 } finally {
9707 Binder.restoreCallingIdentity(identity);
9708 }
9709 }
Jack Yub07d4972019-05-28 16:12:25 -07009710
9711 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009712 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9713 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009714
Jack Yub07d4972019-05-28 16:12:25 -07009715 final long identity = Binder.clearCallingIdentity();
9716 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009717 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009718 if (phone == null) return false;
9719
Hall Liua62f5da2020-09-25 10:42:19 -07009720 switch (policy) {
9721 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9722 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9723 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9724 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9725 default:
9726 throw new IllegalArgumentException(policy + " is not a valid policy");
9727 }
Jack Yub07d4972019-05-28 16:12:25 -07009728 } finally {
9729 Binder.restoreCallingIdentity(identity);
9730 }
9731 }
9732
9733 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009734 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009735 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009736 enforceModifyPermission();
9737
changbettyd5c246e2019-12-24 15:40:37 +08009738 final long identity = Binder.clearCallingIdentity();
9739 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009740 Phone phone = getPhone(subscriptionId);
9741 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009742
Hall Liua62f5da2020-09-25 10:42:19 -07009743 switch (policy) {
9744 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9745 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9746 break;
9747 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9748 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9749 break;
9750 default:
9751 throw new IllegalArgumentException(policy + " is not a valid policy");
9752 }
changbettyd5c246e2019-12-24 15:40:37 +08009753 } finally {
9754 Binder.restoreCallingIdentity(identity);
9755 }
9756 }
9757
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009758 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009759 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009760 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9761 * otherwise.
9762 */
9763 @Override
9764 public void setCepEnabled(boolean isCepEnabled) {
9765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9766
9767 final long identity = Binder.clearCallingIdentity();
9768 try {
9769 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9770 for (Phone phone : PhoneFactory.getPhones()) {
9771 Phone defaultPhone = phone.getImsPhone();
9772 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9773 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9774 ImsPhoneCallTracker imsPhoneCallTracker =
9775 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9776 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9777 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9778 + imsPhone.getMsisdn());
9779 }
9780 }
9781 } finally {
9782 Binder.restoreCallingIdentity(identity);
9783 }
9784 }
allenwtsu46dcc572020-01-08 18:24:03 +08009785
9786 /**
9787 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9788 *
9789 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9790 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9791 * before being read.
9792 */
9793 @Override
9794 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9795 isCompressed) {
9796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9797 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009798 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9799 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9800 }
9801 if (!isImsAvailableOnDevice()) {
9802 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9803 "IMS not available on device.");
9804 }
9805
9806 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009807 try {
Hui Wang761a6682020-10-31 05:12:53 +00009808 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9809 } finally {
9810 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009811 }
9812 }
zoey chene02881a2019-12-30 16:11:23 +08009813
9814 @Override
9815 public boolean isIccLockEnabled(int subId) {
9816 enforceReadPrivilegedPermission("isIccLockEnabled");
9817
9818 // Now that all security checks passes, perform the operation as ourselves.
9819 final long identity = Binder.clearCallingIdentity();
9820 try {
9821 Phone phone = getPhone(subId);
9822 if (phone != null && phone.getIccCard() != null) {
9823 return phone.getIccCard().getIccLockEnabled();
9824 } else {
9825 return false;
9826 }
9827 } finally {
9828 Binder.restoreCallingIdentity(identity);
9829 }
9830 }
9831
9832 /**
9833 * Set the ICC pin lock enabled or disabled.
9834 *
9835 * @return an integer representing the status of IccLock enabled or disabled in the following
9836 * three cases:
9837 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9838 * successfully.
9839 * - Positive number and zero for remaining password attempts.
9840 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9841 *
9842 */
9843 @Override
9844 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9845 enforceModifyPermission();
9846
9847 Phone phone = getPhone(subId);
9848 if (phone == null) {
9849 return 0;
9850 }
9851 // Now that all security checks passes, perform the operation as ourselves.
9852 final long identity = Binder.clearCallingIdentity();
9853 try {
9854 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9855 new Pair<Boolean, String>(enabled, password), phone, null);
9856 return attemptsRemaining;
9857
9858 } catch (Exception e) {
9859 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9860 } finally {
9861 Binder.restoreCallingIdentity(identity);
9862 }
9863 return 0;
9864 }
9865
9866 /**
9867 * Change the ICC password used in ICC pin lock.
9868 *
9869 * @return an integer representing the status of IccLock changed in the following three cases:
9870 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9871 * - Positive number and zero for remaining password attempts.
9872 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9873 *
9874 */
9875 @Override
9876 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9877 enforceModifyPermission();
9878
9879 Phone phone = getPhone(subId);
9880 if (phone == null) {
9881 return 0;
9882 }
9883 // Now that all security checks passes, perform the operation as ourselves.
9884 final long identity = Binder.clearCallingIdentity();
9885 try {
9886 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9887 new Pair<String, String>(oldPassword, newPassword), phone, null);
9888 return attemptsRemaining;
9889
9890 } catch (Exception e) {
9891 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9892 } finally {
9893 Binder.restoreCallingIdentity(identity);
9894 }
9895 return 0;
9896 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009897
9898 /**
9899 * Request for receiving user activity notification
9900 */
9901 @Override
9902 public void requestUserActivityNotification() {
9903 if (!mNotifyUserActivity.get()
9904 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9905 mNotifyUserActivity.set(true);
9906 }
9907 }
9908
9909 /**
9910 * Called when userActivity is signalled in the power manager.
9911 * This is safe to call from any thread, with any window manager locks held or not.
9912 */
9913 @Override
9914 public void userActivity() {
9915 // ***************************************
9916 // * Inherited from PhoneWindowManager *
9917 // ***************************************
9918 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9919 // WITH ITS LOCKS HELD.
9920 //
9921 // This code must be VERY careful about the locks
9922 // it acquires.
9923 // In fact, the current code acquires way too many,
9924 // and probably has lurking deadlocks.
9925
9926 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9927 throw new SecurityException("Only the OS may call notifyUserActivity()");
9928 }
9929
9930 if (mNotifyUserActivity.getAndSet(false)) {
9931 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9932 USER_ACTIVITY_NOTIFICATION_DELAY);
9933 }
9934 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009935
9936 @Override
9937 public boolean canConnectTo5GInDsdsMode() {
9938 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9939 }
Jack Yud10cdd42020-09-28 20:28:01 -07009940
9941 @Override
9942 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9943 String callingFeatureId) {
9944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9945 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9946 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9947 }
9948
9949 Phone phone = getPhone(subId);
9950 if (phone == null) {
9951 throw new RuntimeException("phone is not available");
9952 }
9953 // Now that all security checks passes, perform the operation as ourselves.
9954 final long identity = Binder.clearCallingIdentity();
9955 try {
9956 return phone.getEquivalentHomePlmns();
9957 } finally {
9958 Binder.restoreCallingIdentity(identity);
9959 }
9960 }
Daniel Bright59e67312020-11-13 11:49:37 -08009961
9962 @Override
9963 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009964 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9965 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009966 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009967 if (radioInterfaceCapabilities == null) {
9968 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009969 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009970 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009971 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009972
Hui Wang641e81c2020-10-12 12:14:23 -07009973 @Override
9974 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9975 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009976 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9977 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9978 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9979 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9980 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009981 if (DBG) {
9982 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9983 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9984 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9985 }
9986
9987 if (!SubscriptionManager.isValidSubscriptionId(subId)
9988 || appType < TelephonyManager.APPTYPE_UNKNOWN
9989 || appType > TelephonyManager.APPTYPE_ISIM
9990 || nafUrl == null || securityProtocol == null || callback == null) {
9991 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9992 if (callback != null) {
9993 try {
9994 callback.onAuthenticationFailure(
9995 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9996 } catch (RemoteException exception) {
9997 log("Fail to notify onAuthenticationFailure due to " + exception);
9998 }
9999 return;
10000 }
10001 }
10002
10003 final long token = Binder.clearCallingIdentity();
10004 try {
10005 getGbaManager(subId).bootstrapAuthenticationRequest(
10006 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10007 forceBootStrapping, callback));
10008 } finally {
10009 Binder.restoreCallingIdentity(token);
10010 }
10011 }
10012
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010013 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010014 * Attempts to set the radio power state for all phones for thermal reason.
10015 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010016 * requested radio power state will actually be set. See {@link
10017 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10018 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010019 * @param enable {@code true} if trying to turn radio on.
10020 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10021 * false}.
10022 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010023 private boolean setRadioPowerForThermal(boolean enable) {
10024 boolean isPhoneAvailable = false;
10025 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10026 Phone phone = PhoneFactory.getPhone(i);
10027 if (phone != null) {
10028 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10029 isPhoneAvailable = true;
10030 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010031 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010032
10033 // return true if successfully informed the phone object about the thermal radio power
10034 // request.
10035 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010036 }
10037
10038 private int handleDataThrottlingRequest(int subId,
10039 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010040 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10041 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10042 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10043 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10044 throw new IllegalArgumentException("modem does not support data throttling");
10045 }
10046
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010047 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10048 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010049 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010050 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10051 }
10052
10053 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10054
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010055 if (isDataThrottlingSupported) {
10056 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010057 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010058 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10059 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10060 } else if (thermalMitigationResult
10061 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010062 log("Modem likely does not support data throttling on secondary carrier. Data " +
10063 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10064 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010065 }
10066 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010067 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010068
10069 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010070 }
10071
Jack Nudelman644b91a2021-03-12 14:09:48 -080010072 private static List<String> getThermalMitigationAllowlist(Context context) {
10073 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10074 for (String pckg : context.getResources()
10075 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10076 sThermalMitigationAllowlistedPackages.add(pckg);
10077 }
10078 }
10079
10080 return sThermalMitigationAllowlistedPackages;
10081 }
10082
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010083 private boolean isAnyPhoneInEmergencyState() {
10084 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10085 if (tm.isInEmergencyCall()) {
10086 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10087 return true;
10088 }
10089 for (Phone phone : PhoneFactory.getPhones()) {
10090 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10091 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10092 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10093 + phone.isInEcm());
10094 return true;
10095 }
10096 }
10097
10098 return false;
10099 }
10100
Jack Nudelman644b91a2021-03-12 14:09:48 -080010101 /**
10102 * Used by shell commands to add an authorized package name for thermal mitigation.
10103 * @param packageName name of package to be allowlisted
10104 * @param context
10105 */
10106 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10107 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10108 sThermalMitigationAllowlistedPackages.add(packageName);
10109 }
10110
10111 /**
10112 * Used by shell commands to remove an authorized package name for thermal mitigation.
10113 * @param packageName name of package to remove from allowlist
10114 * @param context
10115 */
10116 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10117 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10118 sThermalMitigationAllowlistedPackages.remove(packageName);
10119 }
10120
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010121 /**
10122 * Thermal mitigation request to control functionalities at modem.
10123 *
10124 * @param subId the id of the subscription.
10125 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010126 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010127 *
10128 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10129 */
10130 @Override
10131 @ThermalMitigationResult
10132 public int sendThermalMitigationRequest(
10133 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010134 ThermalMitigationRequest thermalMitigationRequest,
10135 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010136 enforceModifyPermission();
10137
Jack Nudelman644b91a2021-03-12 14:09:48 -080010138 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10139 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10140 .contains(callingPackage)) {
10141 throw new SecurityException("Calling package must be configured in the device config. "
10142 + "calling package: " + callingPackage);
10143 }
10144
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010145 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10146 final long identity = Binder.clearCallingIdentity();
10147
10148 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10149 try {
10150 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10151 switch (thermalMitigationAction) {
10152 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10153 thermalMitigationResult =
10154 handleDataThrottlingRequest(subId,
10155 thermalMitigationRequest.getDataThrottlingRequest());
10156 break;
10157 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10158 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10159 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10160 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10161 }
10162
10163 // Ensure that radio is on. If not able to power on due to phone being
10164 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010165 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010166 thermalMitigationResult =
10167 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10168 break;
10169 }
10170
10171 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10172 false);
10173 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10174 break;
10175 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10176 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10177 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10178 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10179 }
10180
10181 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10182 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010183 Phone phone = getPhone(subId);
10184 if (phone == null) {
10185 thermalMitigationResult =
10186 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10187 break;
10188 }
10189
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010190 TelephonyConnectionService service =
10191 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010192 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010193 Log.e(LOG_TAG, "An emergency call is pending");
10194 thermalMitigationResult =
10195 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10196 break;
10197 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010198 thermalMitigationResult =
10199 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10200 break;
10201 }
10202 } else {
10203 thermalMitigationResult =
10204 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10205 break;
10206 }
10207
10208 // Turn radio off. If not able to power off due to phone being unavailable,
10209 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010210 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010211 thermalMitigationResult =
10212 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10213 break;
10214 }
10215 thermalMitigationResult =
10216 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10217 break;
10218 default:
10219 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10220 + "not exist. Requested action: " + thermalMitigationAction);
10221 }
10222 } catch (IllegalArgumentException e) {
10223 throw e;
10224 } catch (Exception e) {
10225 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10226 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10227 } finally {
10228 Binder.restoreCallingIdentity(identity);
10229 }
10230
10231 if (DBG) {
10232 log("thermalMitigationRequest returning with thermalMitigationResult: "
10233 + thermalMitigationResult);
10234 }
10235
10236 return thermalMitigationResult;
10237 }
Hui Wang641e81c2020-10-12 12:14:23 -070010238
10239 /**
10240 * Set the GbaService Package Name that Telephony will bind to.
10241 *
10242 * @param subId The sim that the GbaService is associated with.
10243 * @param packageName The name of the package to be replaced with.
10244 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10245 */
10246 @Override
10247 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10248 enforceModifyPermission();
10249
10250 final long identity = Binder.clearCallingIdentity();
10251 try {
10252 return getGbaManager(subId).overrideServicePackage(packageName);
10253 } finally {
10254 Binder.restoreCallingIdentity(identity);
10255 }
10256 }
10257
10258 /**
10259 * Return the package name of the currently bound GbaService.
10260 *
10261 * @param subId The sim that the GbaService is associated with.
10262 * @return the package name of the GbaService configuration, null if GBA is not supported.
10263 */
10264 @Override
10265 public String getBoundGbaService(int subId) {
10266 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10267
10268 final long identity = Binder.clearCallingIdentity();
10269 try {
10270 return getGbaManager(subId).getServicePackage();
10271 } finally {
10272 Binder.restoreCallingIdentity(identity);
10273 }
10274 }
10275
10276 /**
10277 * Set the release time for telephony to unbind GbaService.
10278 *
10279 * @param subId The sim that the GbaService is associated with.
10280 * @param interval The release time to unbind GbaService by millisecond.
10281 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10282 */
10283 @Override
10284 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10285 enforceModifyPermission();
10286
10287 final long identity = Binder.clearCallingIdentity();
10288 try {
10289 return getGbaManager(subId).overrideReleaseTime(interval);
10290 } finally {
10291 Binder.restoreCallingIdentity(identity);
10292 }
10293 }
10294
10295 /**
10296 * Return the release time for telephony to unbind GbaService.
10297 *
10298 * @param subId The sim that the GbaService is associated with.
10299 * @return The release time to unbind GbaService by millisecond.
10300 */
10301 @Override
10302 public int getGbaReleaseTime(int subId) {
10303 enforceReadPrivilegedPermission("getGbaReleaseTime");
10304
10305 final long identity = Binder.clearCallingIdentity();
10306 try {
10307 return getGbaManager(subId).getReleaseTime();
10308 } finally {
10309 Binder.restoreCallingIdentity(identity);
10310 }
10311 }
10312
10313 private GbaManager getGbaManager(int subId) {
10314 GbaManager instance = GbaManager.getInstance(subId);
10315 if (instance == null) {
10316 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10317 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10318 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10319 }
10320 return instance;
10321 }
Hui Wang761a6682020-10-31 05:12:53 +000010322
10323 /**
10324 * indicate whether the device and the carrier can support
10325 * RCS VoLTE single registration.
10326 */
10327 @Override
10328 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010329 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10330 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10331 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10332 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010333
10334 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10335 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10336 }
10337
10338 final long identity = Binder.clearCallingIdentity();
10339 try {
10340 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10341 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010342 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10343 if (isCapable != null) {
10344 return isCapable;
10345 }
Hui Wang761a6682020-10-31 05:12:53 +000010346 }
Hui Wang67af90e2021-06-04 16:57:15 -070010347 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10348 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352 }
10353
10354 /**
10355 * Register RCS provisioning callback.
10356 */
10357 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010358 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010359 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010360 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010361 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010362 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10363 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010364
10365 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10366 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10367 }
10368 if (!isImsAvailableOnDevice()) {
10369 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10370 "IMS not available on device.");
10371 }
10372
10373 final long identity = Binder.clearCallingIdentity();
10374 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010375 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010376 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010377 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10378 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010379 }
Hui Wang761a6682020-10-31 05:12:53 +000010380 } finally {
10381 Binder.restoreCallingIdentity(identity);
10382 }
10383 }
10384
10385 /**
10386 * Unregister RCS provisioning callback.
10387 */
10388 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010389 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010390 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010391 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010392 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010393 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10394 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010395
10396 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10397 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10398 }
10399 if (!isImsAvailableOnDevice()) {
10400 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10401 "IMS not available on device.");
10402 }
10403
10404 final long identity = Binder.clearCallingIdentity();
10405 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010406 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010407 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010408 } finally {
10409 Binder.restoreCallingIdentity(identity);
10410 }
10411 }
10412
10413 /**
10414 * trigger RCS reconfiguration.
10415 */
10416 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010417 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10418 "triggerRcsReconfiguration",
10419 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010420
10421 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10422 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10423 }
10424 if (!isImsAvailableOnDevice()) {
10425 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10426 "IMS not available on device.");
10427 }
10428
10429 final long identity = Binder.clearCallingIdentity();
10430 try {
10431 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10432 } finally {
10433 Binder.restoreCallingIdentity(identity);
10434 }
10435 }
10436
10437 /**
10438 * Provide the client configuration parameters of the RCS application.
10439 */
10440 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010441 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10442 "setRcsClientConfiguration",
10443 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010444
10445 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10446 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10447 }
10448 if (!isImsAvailableOnDevice()) {
10449 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10450 "IMS not available on device.");
10451 }
10452
10453 final long identity = Binder.clearCallingIdentity();
10454
10455 try {
10456 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10457 if (configBinder == null) {
10458 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010459 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10460 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010461 } else {
10462 configBinder.setRcsClientConfiguration(rcc);
10463 }
10464 } catch (RemoteException e) {
10465 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010466 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10467 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010468 } finally {
10469 Binder.restoreCallingIdentity(identity);
10470 }
10471 }
10472
10473 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010474 * Enables or disables the test mode for RCS VoLTE single registration.
10475 */
10476 @Override
10477 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10478 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10479 "setRcsSingleRegistrationTestModeEnabled");
10480
10481 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10482 }
10483
10484 /**
10485 * Gets the test mode for RCS VoLTE single registration.
10486 */
10487 @Override
10488 public boolean getRcsSingleRegistrationTestModeEnabled() {
10489 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10490 "getRcsSingleRegistrationTestModeEnabled");
10491
10492 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10493 }
10494
10495 /**
Hui Wang761a6682020-10-31 05:12:53 +000010496 * Overrides the config of RCS VoLTE single registration enabled for the device.
10497 */
10498 @Override
10499 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10500 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10501 "setDeviceSingleRegistrationEnabledOverride");
10502 enforceModifyPermission();
10503
10504 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10505 : Boolean.parseBoolean(enabledStr);
10506 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010507 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010508 }
10509
10510 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010511 * Sends a device to device communication message. Only usable via shell.
10512 * @param message message to send.
10513 * @param value message value.
10514 */
10515 @Override
10516 public void sendDeviceToDeviceMessage(int message, int value) {
10517 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010518 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010519 enforceModifyPermission();
10520
10521 final long identity = Binder.clearCallingIdentity();
10522 try {
10523 TelephonyConnectionService service =
10524 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10525 if (service == null) {
10526 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10527 return;
10528 }
10529 service.sendTestDeviceToDeviceMessage(message, value);
10530 } finally {
10531 Binder.restoreCallingIdentity(identity);
10532 }
10533 }
10534
Tyler Gunnbabbda02021-02-10 11:05:02 -080010535 /**
10536 * Sets the specified device to device transport active.
10537 * @param transport The transport to set active.
10538 */
10539 @Override
10540 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10541 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10542 "setActiveDeviceToDeviceTransport");
10543 enforceModifyPermission();
10544
10545 final long identity = Binder.clearCallingIdentity();
10546 try {
10547 TelephonyConnectionService service =
10548 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10549 if (service == null) {
10550 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10551 return;
10552 }
10553 service.setActiveDeviceToDeviceTransport(transport);
10554 } finally {
10555 Binder.restoreCallingIdentity(identity);
10556 }
10557 }
Tyler Gunn92479152021-01-20 16:30:10 -080010558
Tyler Gunnd4575212021-05-03 14:46:49 -070010559 @Override
10560 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10561 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10562 "setDeviceToDeviceForceEnabled");
10563
10564 final long identity = Binder.clearCallingIdentity();
10565 try {
10566 Arrays.stream(PhoneFactory.getPhones()).forEach(
10567 p -> {
10568 Phone thePhone = p.getImsPhone();
10569 if (thePhone != null && thePhone instanceof ImsPhone) {
10570 ImsPhone imsPhone = (ImsPhone) thePhone;
10571 CallTracker tracker = imsPhone.getCallTracker();
10572 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10573 ImsPhoneCallTracker imsPhoneCallTracker =
10574 (ImsPhoneCallTracker) tracker;
10575 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10576 }
10577 }
10578 }
10579 );
10580 } finally {
10581 Binder.restoreCallingIdentity(identity);
10582 }
10583 }
10584
Tyler Gunn92479152021-01-20 16:30:10 -080010585 /**
Hui Wang761a6682020-10-31 05:12:53 +000010586 * Gets the config of RCS VoLTE single registration enabled for the device.
10587 */
10588 @Override
10589 public boolean getDeviceSingleRegistrationEnabled() {
10590 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10591 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10592 }
10593
10594 /**
10595 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10596 */
10597 @Override
10598 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10599 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10600 "setCarrierSingleRegistrationEnabledOverride");
10601 enforceModifyPermission();
10602
10603 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10604 : Boolean.parseBoolean(enabledStr);
10605 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10606 subId, enabled);
10607 }
10608
10609 /**
10610 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10611 */
10612 @Override
10613 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10614 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10615 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10616 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010617
10618 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010619 * Overrides the ims feature validation result
10620 */
10621 @Override
10622 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10624 "setImsFeatureValidationOverride");
10625
10626 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10627 : Boolean.parseBoolean(enabledStr);
10628 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10629 subId, enabled);
10630 }
10631
10632 /**
10633 * Gets the ims feature validation override value
10634 */
10635 @Override
10636 public boolean getImsFeatureValidationOverride(int subId) {
10637 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10638 "getImsFeatureValidationOverride");
10639 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10640 }
10641
10642 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010643 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10644 * their mobile plan.
10645 */
10646 @Override
10647 public String getMobileProvisioningUrl() {
10648 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10649 final long identity = Binder.clearCallingIdentity();
10650 try {
10651 return getDefaultPhone().getMobileProvisioningUrl();
10652 } finally {
10653 Binder.restoreCallingIdentity(identity);
10654 }
10655 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010656
James.cf Linbcdf8b32021-01-14 16:44:13 +080010657 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010658 * Get the EAB contact from the EAB database.
10659 */
10660 @Override
10661 public String getContactFromEab(String contact) {
10662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10663 enforceModifyPermission();
10664 final long identity = Binder.clearCallingIdentity();
10665 try {
10666 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10667 } finally {
10668 Binder.restoreCallingIdentity(identity);
10669 }
10670 }
10671
10672 /**
Calvin Pana1434322021-07-01 19:27:01 +080010673 * Get the EAB capability from the EAB database.
10674 */
10675 @Override
10676 public String getCapabilityFromEab(String contact) {
10677 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10678 enforceModifyPermission();
10679 final long identity = Binder.clearCallingIdentity();
10680 try {
10681 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10682 } finally {
10683 Binder.restoreCallingIdentity(identity);
10684 }
10685 }
10686
10687 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010688 * Remove the EAB contacts from the EAB database.
10689 */
10690 @Override
10691 public int removeContactFromEab(int subId, String contacts) {
10692 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10693 enforceModifyPermission();
10694 final long identity = Binder.clearCallingIdentity();
10695 try {
10696 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10697 } finally {
10698 Binder.restoreCallingIdentity(identity);
10699 }
10700 }
10701
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010702 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010703 public boolean getDeviceUceEnabled() {
10704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10705 final long identity = Binder.clearCallingIdentity();
10706 try {
10707 return mApp.getDeviceUceEnabled();
10708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
10712
10713 @Override
10714 public void setDeviceUceEnabled(boolean isEnabled) {
10715 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10716 final long identity = Binder.clearCallingIdentity();
10717 try {
10718 mApp.setDeviceUceEnabled(isEnabled);
10719 } finally {
10720 Binder.restoreCallingIdentity(identity);
10721 }
10722 }
10723
Brad Ebinger14d467f2021-02-12 06:18:28 +000010724 /**
10725 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10726 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10727 */
10728 // Used for SHELL command only right now.
10729 @Override
10730 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10731 List<String> featureTags) {
10732 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10733 "addUceRegistrationOverrideShell");
10734 final long identity = Binder.clearCallingIdentity();
10735 try {
10736 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10737 new ArraySet<>(featureTags));
10738 } catch (ImsException e) {
10739 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10740 } finally {
10741 Binder.restoreCallingIdentity(identity);
10742 }
10743 }
10744
10745 /**
10746 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10747 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10748 */
10749 // Used for SHELL command only right now.
10750 @Override
10751 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10752 List<String> featureTags) {
10753 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10754 "removeUceRegistrationOverrideShell");
10755 final long identity = Binder.clearCallingIdentity();
10756 try {
10757 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10758 new ArraySet<>(featureTags));
10759 } catch (ImsException e) {
10760 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10761 } finally {
10762 Binder.restoreCallingIdentity(identity);
10763 }
10764 }
10765
10766 /**
10767 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10768 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10769 */
10770 // Used for SHELL command only right now.
10771 @Override
10772 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10773 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10774 "clearUceRegistrationOverrideShell");
10775 final long identity = Binder.clearCallingIdentity();
10776 try {
10777 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10778 } catch (ImsException e) {
10779 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10780 } finally {
10781 Binder.restoreCallingIdentity(identity);
10782 }
10783 }
10784
10785 /**
10786 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10787 */
10788 // Used for SHELL command only right now.
10789 @Override
10790 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10791 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10792 "getLatestRcsContactUceCapabilityShell");
10793 final long identity = Binder.clearCallingIdentity();
10794 try {
10795 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10796 } catch (ImsException e) {
10797 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10798 } finally {
10799 Binder.restoreCallingIdentity(identity);
10800 }
10801 }
10802
10803 /**
10804 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10805 * device does not have an active PUBLISH.
10806 */
10807 // Used for SHELL command only right now.
10808 @Override
10809 public String getLastUcePidfXmlShell(int subId) {
10810 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10811 final long identity = Binder.clearCallingIdentity();
10812 try {
10813 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10814 } catch (ImsException e) {
10815 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10816 } finally {
10817 Binder.restoreCallingIdentity(identity);
10818 }
10819 }
10820
James.cf Line8713a42021-04-29 16:04:26 +080010821 /**
10822 * Remove UCE requests cannot be sent to the network status.
10823 */
10824 // Used for SHELL command only right now.
10825 @Override
10826 public boolean removeUceRequestDisallowedStatus(int subId) {
10827 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10828 final long identity = Binder.clearCallingIdentity();
10829 try {
10830 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10831 } catch (ImsException e) {
10832 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10833 } finally {
10834 Binder.restoreCallingIdentity(identity);
10835 }
10836 }
10837
James.cf Lin0fc71b02021-05-25 01:37:38 +080010838 /**
10839 * Remove UCE requests cannot be sent to the network status.
10840 */
10841 // Used for SHELL command only.
10842 @Override
10843 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10845 final long identity = Binder.clearCallingIdentity();
10846 try {
10847 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10848 } catch (ImsException e) {
10849 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10850 } finally {
10851 Binder.restoreCallingIdentity(identity);
10852 }
10853 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010854
James.cf Lin4b784aa2021-01-31 03:25:15 +080010855 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010856 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10857 String callingPackage) {
10858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10859 mApp, subId, "setSignalStrengthUpdateRequest");
10860
10861 final int callingUid = Binder.getCallingUid();
10862 // Verify that tha callingPackage belongs to the calling UID
10863 mApp.getSystemService(AppOpsManager.class)
10864 .checkPackage(callingUid, callingPackage);
10865
Rambo Wang3607f502021-02-01 21:51:40 -080010866 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010867
10868 final long identity = Binder.clearCallingIdentity();
10869 try {
10870 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10871 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10872
10873 if (result instanceof IllegalStateException) {
10874 throw (IllegalStateException) result;
10875 }
10876 } finally {
10877 Binder.restoreCallingIdentity(identity);
10878 }
10879 }
10880
10881 @Override
10882 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10883 String callingPackage) {
10884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10885 mApp, subId, "clearSignalStrengthUpdateRequest");
10886
10887 final int callingUid = Binder.getCallingUid();
10888 // Verify that tha callingPackage belongs to the calling UID
10889 mApp.getSystemService(AppOpsManager.class)
10890 .checkPackage(callingUid, callingPackage);
10891
10892 final long identity = Binder.clearCallingIdentity();
10893 try {
10894 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10895 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10896
10897 if (result instanceof IllegalStateException) {
10898 throw (IllegalStateException) result;
10899 }
10900 } finally {
10901 Binder.restoreCallingIdentity(identity);
10902 }
10903 }
10904
Rambo Wang3607f502021-02-01 21:51:40 -080010905 private static void validateSignalStrengthUpdateRequest(Context context,
10906 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010907 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10908 // phone/system process do not have further restriction on request
10909 return;
10910 }
10911
10912 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010913 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010914 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010915 context.enforceCallingOrSelfPermission(
10916 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10917 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010918 }
10919
10920 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10921 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10922 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10923 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10924 || info.isEnabled()) {
10925 throw new IllegalArgumentException(
10926 "Only system can set hide fields in SignalThresholdInfo");
10927 }
10928
10929 // Thresholds length for each RAN need in range. This has been validated in
10930 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10931 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10932 final int[] thresholds = info.getThresholds();
10933 Objects.requireNonNull(thresholds);
10934 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10935 || thresholds.length
10936 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10937 throw new IllegalArgumentException(
10938 "thresholds length is out of range: " + thresholds.length);
10939 }
10940 }
10941 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010942
10943 /**
10944 * Gets the current phone capability.
10945 *
10946 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10947 * @return the PhoneCapability which describes the data connection capability of modem.
10948 * It's used to evaluate possible phone config change, for example from single
10949 * SIM device to multi-SIM device.
10950 */
10951 @Override
10952 public PhoneCapability getPhoneCapability() {
10953 enforceReadPrivilegedPermission("getPhoneCapability");
10954 final long identity = Binder.clearCallingIdentity();
10955 try {
10956 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10957 } finally {
10958 Binder.restoreCallingIdentity(identity);
10959 }
10960 }
Michele Berionne5e411512020-11-13 02:36:59 +000010961
10962 /**
10963 * Prepare TelephonyManager for an unattended reboot. The reboot is
10964 * required to be done shortly after the API is invoked.
10965 */
10966 @Override
10967 @TelephonyManager.PrepareUnattendedRebootResult
10968 public int prepareForUnattendedReboot() {
10969 enforceRebootPermission();
10970
10971 final long identity = Binder.clearCallingIdentity();
10972 try {
10973 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10974 } finally {
10975 Binder.restoreCallingIdentity(identity);
10976 }
10977 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010978
10979 /**
10980 * Request to get the current slicing configuration including URSP rules and
10981 * NSSAIs (configured, allowed and rejected).
10982 *
10983 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10984 */
10985 @Override
10986 public void getSlicingConfig(ResultReceiver callback) {
10987 enforceReadPrivilegedPermission("getSlicingConfig");
10988
10989 final long identity = Binder.clearCallingIdentity();
10990 try {
10991 Phone phone = getDefaultPhone();
10992 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10993 } finally {
10994 Binder.restoreCallingIdentity(identity);
10995 }
10996 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000010997
10998 /**
10999 * Register an IMS connection state callback
11000 */
11001 @Override
11002 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11003 String callingPackage) {
11004 if (feature == ImsFeature.FEATURE_MMTEL) {
11005 // ImsMmTelManager
11006 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11007 TelephonyPermissions
11008 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11009 mApp, subId, "registerImsStateCallback");
11010 } else if (feature == ImsFeature.FEATURE_RCS) {
11011 // ImsRcsManager or SipDelegateManager
11012 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11013 Binder.getCallingUid(), "registerImsStateCallback",
11014 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11015 Manifest.permission.READ_PRECISE_PHONE_STATE,
11016 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11017 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11018 }
11019
11020 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11021 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11022 "IMS not available on device.");
11023 }
11024
11025 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11026 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11027 }
11028
11029 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11030 if (controller == null) {
11031 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11032 "IMS not available on device.");
11033 }
11034
11035 if (callingPackage == null) {
11036 callingPackage = getCurrentPackageName();
11037 }
11038
11039 final long token = Binder.clearCallingIdentity();
11040 try {
11041 int slotId = getSlotIndexOrException(subId);
11042 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11043 } catch (ImsException e) {
11044 throw new ServiceSpecificException(e.getCode());
11045 } finally {
11046 Binder.restoreCallingIdentity(token);
11047 }
11048 }
11049
11050 /**
11051 * Unregister an IMS connection state callback
11052 */
11053 @Override
11054 public void unregisterImsStateCallback(IImsStateCallback cb) {
11055 final long token = Binder.clearCallingIdentity();
11056 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11057 if (controller == null) {
11058 return;
11059 }
11060 try {
11061 controller.unregisterImsStateCallback(cb);
11062 } finally {
11063 Binder.restoreCallingIdentity(token);
11064 }
11065 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011066
11067 /**
11068 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11069 *
11070 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11071 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11072 * SecurityException.
11073 * If there is current registered network this value will be same as the registered cell
11074 * identity. If the device goes out of service the previous cell identity is cached and
11075 * will be returned. If the cache age of the Cell identity is more than 24 hours
11076 * it will be cleared and null will be returned.
11077 *
11078 */
11079 @Override
11080 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11081 String callingFeatureId) {
11082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11083 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11084 LocationAccessPolicy.checkLocationPermission(mApp,
11085 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11086 .setCallingPackage(callingPackage)
11087 .setCallingFeatureId(callingFeatureId)
11088 .setCallingPid(Binder.getCallingPid())
11089 .setCallingUid(Binder.getCallingUid())
11090 .setMethod("getLastKnownCellIdentity")
11091 .setLogAsInfo(true)
11092 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11093 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11094 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11095 .build());
11096
11097 boolean hasFinePermission =
11098 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11099 if (!hasFinePermission
11100 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11101 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11102 + "and BIND_CONNECTION_SERVICE permission.");
11103 }
11104
11105 final long identity = Binder.clearCallingIdentity();
11106 try {
11107 Phone phone = getPhone(subId);
11108 if (phone == null) return null;
11109 ServiceStateTracker sst = phone.getServiceStateTracker();
11110 if (sst == null) return null;
11111 return sst.getLastKnownCellIdentity();
11112 } finally {
11113 Binder.restoreCallingIdentity(identity);
11114 }
11115 }
jimsun38340bf2021-10-26 15:01:23 +080011116
11117 /**
11118 * Sets the modem service class Name that Telephony will bind to.
11119 *
11120 * @param serviceName The class name of the modem service.
11121 * @return true if the operation is succeed, otherwise false.
11122 */
11123 public boolean setModemService(String serviceName) {
11124 Log.d(LOG_TAG, "setModemService - " + serviceName);
11125 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11127 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11128 "setModemService");
11129 return mPhoneConfigurationManager.setModemService(serviceName);
11130 }
11131
11132 /**
11133 * Return the class name of the currently bounded modem service.
11134 *
11135 * @return the class name of the modem service.
11136 */
11137 public String getModemService() {
11138 String result;
11139 Log.d(LOG_TAG, "getModemService");
11140 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11141 TelephonyPermissions
11142 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11143 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11144 "getModemService");
11145 result = mPhoneConfigurationManager.getModemService();
11146 Log.d(LOG_TAG, "result = " + result);
11147 return result;
11148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011149}