blob: a06f6b7369447ade0c5568fb5e88d3c32d9235f8 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000032import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080033import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070034import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070035import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.content.Context;
37import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070039import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080040import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070041import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
43import android.os.AsyncResult;
44import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080045import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Bundle;
47import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Looper;
50import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080052import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070053import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070054import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080055import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080056import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070057import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070058import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080059import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070061import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070063import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070064import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080065import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070066import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090067import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080068import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080069import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070070import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070071import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080072import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080073import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800111import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800140import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700143import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700144import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800145import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700150import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800151import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800152import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800153import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700154import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800156import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700160import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700163import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800164import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700165import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700166import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700167import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700168import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800169import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800170import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700172import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800174import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800175import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800176import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700177import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700179import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800180import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700181import com.android.internal.telephony.imsphone.ImsPhone;
182import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800183import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700184import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800186import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700189import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000192import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800193import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000194import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800195import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700196import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700197import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800198import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800199import com.android.phone.callcomposer.CallComposerPictureManager;
200import com.android.phone.callcomposer.CallComposerPictureTransfer;
201import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700202import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700203import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800204import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700205import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700206import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800207import com.android.services.telephony.TelecomAccountRegistry;
208import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800209import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800210
Hall Liu82694d52020-12-11 18:22:04 -0800211import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700212import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800213import java.io.IOException;
214import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700215import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800217import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800218import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800219import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800220import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100221import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700223import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800226import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800227import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800228import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
230/**
231 * Implementation of the ITelephony interface.
232 */
Santos Cordon117fee72014-05-16 17:56:12 -0700233public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234 private static final String LOG_TAG = "PhoneInterfaceManager";
235 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
236 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800237 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238
239 // Message codes used with mMainThreadHandler
240 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700241 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
242 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243 private static final int CMD_OPEN_CHANNEL = 9;
244 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
245 private static final int CMD_CLOSE_CHANNEL = 11;
246 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800247 private static final int CMD_NV_READ_ITEM = 13;
248 private static final int EVENT_NV_READ_ITEM_DONE = 14;
249 private static final int CMD_NV_WRITE_ITEM = 15;
250 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
251 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
252 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700253 private static final int CMD_RESET_MODEM_CONFIG = 19;
254 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800255 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
256 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800257 private static final int CMD_SEND_ENVELOPE = 25;
258 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000259 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
260 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700261 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
262 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
263 private static final int CMD_EXCHANGE_SIM_IO = 31;
264 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800265 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
266 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700267 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
268 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700269 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
270 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700271 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
272 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
273 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
274 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700275 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
276 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
277 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
278 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700279 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800280 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
281 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000282 private static final int CMD_SWITCH_SLOTS = 50;
283 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700284 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
285 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
286 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
287 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
288 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
289 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
290 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
291 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700292 private static final int CMD_GET_ALL_CELL_INFO = 60;
293 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
294 private static final int CMD_GET_CELL_LOCATION = 62;
295 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700296 private static final int CMD_MODEM_REBOOT = 64;
297 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700298 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
299 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800300 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
301 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700302 private static final int CMD_GET_MODEM_STATUS = 70;
303 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700304 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
305 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700306 private static final int CMD_ERASE_MODEM_CONFIG = 74;
307 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800308 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
309 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
310 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
311 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800312 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
313 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800315 private static final int CMD_GET_CALL_FORWARDING = 83;
316 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
317 private static final int CMD_SET_CALL_FORWARDING = 85;
318 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
319 private static final int CMD_GET_CALL_WAITING = 87;
320 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
321 private static final int CMD_SET_CALL_WAITING = 89;
322 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700323 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
324 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
325 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
326 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700327 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
328 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800329 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
330 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800331 private static final int CMD_SET_DATA_THROTTLING = 99;
332 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800333 private static final int CMD_SET_SIM_POWER = 101;
334 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800335 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
336 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
337 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
338 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800339 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
340 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000341 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800342 private static final int CMD_GET_SLICING_CONFIG = 110;
343 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800344 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700345 private static final int CMD_ENABLE_VONR = 113;
346 private static final int EVENT_ENABLE_VONR_DONE = 114;
347 private static final int CMD_IS_VONR_ENABLED = 115;
348 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800350 // Parameters of select command.
351 private static final int SELECT_COMMAND = 0xA4;
352 private static final int SELECT_P1 = 0x04;
353 private static final int SELECT_P2 = 0;
354 private static final int SELECT_P3 = 0x10;
355
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 /** The singleton instance. */
357 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800358 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800362 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700363 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800364 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700365 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800366 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800367 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800368 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700369 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800370 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Peter Wangdafb9ac2020-01-15 14:13:38 -0800372 /** User Activity */
373 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800374 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
375
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700376 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
377
Derek Tan97ebb422014-09-05 16:55:38 -0700378 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
379 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800380 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800381 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700382
Michelecea4cf22018-12-21 15:00:11 -0800383 // String to store multi SIM allowed
384 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
385
Derek Tan740e1672017-06-27 14:56:27 -0700386 // The AID of ISD-R.
387 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
388
yinxub1bed742017-04-17 11:45:04 -0700389 private NetworkScanRequestTracker mNetworkScanRequestTracker;
390
David Kelly5e06a7f2018-03-12 14:10:59 +0000391 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
392 private static final int MANUFACTURER_CODE_LENGTH = 8;
393
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800394 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800395 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800396
Derek Tan89e89d42014-07-08 17:00:10 -0700397 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700398 * Experiment flag to enable erase modem config on reset network, default value is false
399 */
400 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
401 "reset_network_erase_modem_config_enabled";
402
Rambo Wang0f050d82021-02-12 11:43:36 -0800403 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
404
Naina Nallurid63128d2019-09-17 14:10:30 -0700405 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700406 * A request object to use for transmitting data to an ICC.
407 */
408 private static final class IccAPDUArgument {
409 public int channel, cla, command, p1, p2, p3;
410 public String data;
411
412 public IccAPDUArgument(int channel, int cla, int command,
413 int p1, int p2, int p3, String data) {
414 this.channel = channel;
415 this.cla = cla;
416 this.command = command;
417 this.p1 = p1;
418 this.p2 = p2;
419 this.p3 = p3;
420 this.data = data;
421 }
422 }
423
424 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700425 * A request object to use for transmitting data to an ICC.
426 */
427 private static final class ManualNetworkSelectionArgument {
428 public OperatorInfo operatorInfo;
429 public boolean persistSelection;
430
431 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
432 this.operatorInfo = operatorInfo;
433 this.persistSelection = persistSelection;
434 }
435 }
436
437 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
439 * request after sending. The main thread will notify the request when it is complete.
440 */
441 private static final class MainThreadRequest {
442 /** The argument to use for the request */
443 public Object argument;
444 /** The result of the request that is run on the main thread */
445 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800446 // The subscriber id that this request applies to. Defaults to
447 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
448 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449
Nathan Harold92bed182018-10-12 18:16:49 -0700450 // In cases where subId is unavailable, the caller needs to specify the phone.
451 public Phone phone;
452
vagdeviaf9a5b92018-08-15 16:01:53 -0700453 public WorkSource workSource;
454
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 public MainThreadRequest(Object argument) {
456 this.argument = argument;
457 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800458
Nathan Harold92bed182018-10-12 18:16:49 -0700459 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
460 this.argument = argument;
461 if (phone != null) {
462 this.phone = phone;
463 }
464 this.workSource = workSource;
465 }
466
vagdeviaf9a5b92018-08-15 16:01:53 -0700467 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800468 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800469 if (subId != null) {
470 this.subId = subId;
471 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700472 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 }
475
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800476 private static final class IncomingThirdPartyCallArgs {
477 public final ComponentName component;
478 public final String callId;
479 public final String callerDisplayName;
480
481 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
482 String callerDisplayName) {
483 this.component = component;
484 this.callId = callId;
485 this.callerDisplayName = callerDisplayName;
486 }
487 }
488
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 /**
490 * A handler that processes messages on the main thread in the phone process. Since many
491 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
492 * inbound binder threads to the main thread in the phone process. The Binder thread
493 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
494 * on, which will be notified when the operation completes and will contain the result of the
495 * request.
496 *
497 * <p>If a MainThreadRequest object is provided in the msg.obj field,
498 * note that request.result must be set to something non-null for the calling thread to
499 * unblock.
500 */
501 private final class MainThreadHandler extends Handler {
502 @Override
503 public void handleMessage(Message msg) {
504 MainThreadRequest request;
505 Message onCompleted;
506 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000507 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800509 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510
511 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 case CMD_HANDLE_USSD_REQUEST: {
513 request = (MainThreadRequest) msg.obj;
514 final Phone phone = getPhoneFromRequest(request);
515 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
516 String ussdRequest = ussdObject.first;
517 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700518
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 if (!isUssdApiAllowed(request.subId)) {
520 // Carrier does not support use of this API, return failure.
521 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
522 UssdResponse response = new UssdResponse(ussdRequest, null);
523 Bundle returnData = new Bundle();
524 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
525 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700526
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 request.result = true;
528 notifyRequester(request);
529 return;
530 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700531
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 try {
533 request.result = phone != null
534 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
535 } catch (CallStateException cse) {
536 request.result = false;
537 }
538 // Wake up the requesting thread
539 notifyRequester(request);
540 break;
pkanwar32d516d2016-10-14 19:37:38 -0700541 }
542
Yorke Lee716f67e2015-06-17 15:39:16 -0700543 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700545 final Phone phone = getPhoneFromRequest(request);
546 request.result = phone != null ?
547 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
548 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000557 uiccPort = getUiccPortFromRequest(request);
558 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 loge("iccTransmitApduLogicalChannel: No UICC");
560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
564 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000565 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 iccArgument.channel, iccArgument.cla, iccArgument.command,
567 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 break;
571
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
577 } else {
578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800581 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800583 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 } else {
585 loge("iccTransmitApduLogicalChannel: Unknown exception");
586 }
587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
593 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000594 uiccPort = getUiccPortFromRequest(request);
595 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 loge("iccTransmitApduBasicChannel: No UICC");
597 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 } else {
600 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
601 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000602 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
604 iccArgument.p3, iccArgument.data, onCompleted);
605 }
606 break;
607
608 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
611 if (ar.exception == null && ar.result != null) {
612 request.result = ar.result;
613 } else {
614 request.result = new IccIoResult(0x6F, 0, (byte[])null);
615 if (ar.result == null) {
616 loge("iccTransmitApduBasicChannel: Empty response");
617 } else if (ar.exception instanceof CommandException) {
618 loge("iccTransmitApduBasicChannel: CommandException: " +
619 ar.exception);
620 } else {
621 loge("iccTransmitApduBasicChannel: Unknown exception");
622 }
623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 break;
626
627 case CMD_EXCHANGE_SIM_IO:
628 request = (MainThreadRequest) msg.obj;
629 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000630 uiccPort = getUiccPortFromRequest(request);
631 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 loge("iccExchangeSimIO: No UICC");
633 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
637 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000638 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
640 iccArgument.data, onCompleted);
641 }
642 break;
643
644 case EVENT_EXCHANGE_SIM_IO_DONE:
645 ar = (AsyncResult) msg.obj;
646 request = (MainThreadRequest) ar.userObj;
647 if (ar.exception == null && ar.result != null) {
648 request.result = ar.result;
649 } else {
650 request.result = new IccIoResult(0x6f, 0, (byte[])null);
651 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 break;
654
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 case CMD_SEND_ENVELOPE:
656 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000657 uiccPort = getUiccPortFromRequest(request);
658 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 loge("sendEnvelopeWithStatus: No UICC");
660 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700661 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 } else {
663 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000664 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800666 break;
667
668 case EVENT_SEND_ENVELOPE_DONE:
669 ar = (AsyncResult) msg.obj;
670 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700671 if (ar.exception == null && ar.result != null) {
672 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800673 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700674 request.result = new IccIoResult(0x6F, 0, (byte[])null);
675 if (ar.result == null) {
676 loge("sendEnvelopeWithStatus: Empty response");
677 } else if (ar.exception instanceof CommandException) {
678 loge("sendEnvelopeWithStatus: CommandException: " +
679 ar.exception);
680 } else {
681 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
682 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 break;
686
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 case CMD_OPEN_CHANNEL:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800690 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000691 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800693 request.result = new IccOpenLogicalChannelResponse(-1,
694 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700696 } else {
697 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000698 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800699 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700700 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 break;
702
703 case EVENT_OPEN_CHANNEL_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 int[] result = (int[]) ar.result;
709 int channelId = result[0];
710 byte[] selectResponse = null;
711 if (result.length > 1) {
712 selectResponse = new byte[result.length - 1];
713 for (int i = 1; i < result.length; ++i) {
714 selectResponse[i - 1] = (byte) result[i];
715 }
716 }
717 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700718 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 if (ar.result == null) {
721 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 if (ar.exception != null) {
724 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
725 }
726
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700727 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700728 if (ar.exception instanceof CommandException) {
729 CommandException.Error error =
730 ((CommandException) (ar.exception)).getCommandError();
731 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700732 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700733 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700734 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 }
736 }
737 openChannelResp = new IccOpenLogicalChannelResponse(
738 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700740 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 break;
743
744 case CMD_CLOSE_CHANNEL:
745 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000746 uiccPort = getUiccPortFromRequest(request);
747 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700748 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900749 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700750 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700751 } else {
752 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000753 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700754 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 break;
756
757 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800758 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
759 break;
760
761 case CMD_NV_READ_ITEM:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
765 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800766 break;
767
768 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 ar = (AsyncResult) msg.obj;
770 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800771 if (ar.exception == null && ar.result != null) {
772 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800774 request.result = "";
775 if (ar.result == null) {
776 loge("nvReadItem: Empty response");
777 } else if (ar.exception instanceof CommandException) {
778 loge("nvReadItem: CommandException: " +
779 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700780 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800781 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 }
783 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
Jake Hambye994d462014-02-03 13:10:13 -0800787 case CMD_NV_WRITE_ITEM:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
790 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700792 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800793 break;
794
795 case EVENT_NV_WRITE_ITEM_DONE:
796 handleNullReturnEvent(msg, "nvWriteItem");
797 break;
798
799 case CMD_NV_WRITE_CDMA_PRL:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800802 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800803 break;
804
805 case EVENT_NV_WRITE_CDMA_PRL_DONE:
806 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
807 break;
808
chen xu6dac5ab2018-10-26 17:39:23 -0700809 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800810 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700811 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800812 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800813 break;
814
chen xu6dac5ab2018-10-26 17:39:23 -0700815 case EVENT_RESET_MODEM_CONFIG_DONE:
816 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800817 break;
818
Sooraj Sasindran37444802020-08-11 10:40:43 -0700819 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
822 request);
823 Phone phone = getPhoneFromRequest(request);
824 if (phone != null) {
825 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
826 } else {
827 loge("isNRDualConnectivityEnabled: No phone object");
828 request.result = false;
829 notifyRequester(request);
830 }
831 break;
832 }
833
834 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result;
839 } else {
840 // request.result must be set to something non-null
841 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700842 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700843 request.result = ar.result;
844 } else {
845 request.result = false;
846 }
847 if (ar.result == null) {
848 loge("isNRDualConnectivityEnabled: Empty response");
849 } else if (ar.exception instanceof CommandException) {
850 loge("isNRDualConnectivityEnabled: CommandException: "
851 + ar.exception);
852 } else {
853 loge("isNRDualConnectivityEnabled: Unknown exception");
854 }
855 }
856 notifyRequester(request);
857 break;
858
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700859 case CMD_IS_VONR_ENABLED: {
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
862 request);
863 Phone phone = getPhoneFromRequest(request);
864 if (phone != null) {
865 phone.isVoNrEnabled(onCompleted, request.workSource);
866 } else {
867 loge("isVoNrEnabled: No phone object");
868 request.result = false;
869 notifyRequester(request);
870 }
871 break;
872 }
873
874 case EVENT_IS_VONR_ENABLED_DONE:
875 ar = (AsyncResult) msg.obj;
876 request = (MainThreadRequest) ar.userObj;
877 if (ar.exception == null && ar.result != null) {
878 request.result = ar.result;
879 } else {
880 // request.result must be set to something non-null
881 // for the calling thread to unblock
882 if (ar.result != null) {
883 request.result = ar.result;
884 } else {
885 request.result = false;
886 }
887 if (ar.result == null) {
888 loge("isVoNrEnabled: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("isVoNrEnabled: CommandException: "
891 + ar.exception);
892 } else {
893 loge("isVoNrEnabled: Unknown exception");
894 }
895 }
896 notifyRequester(request);
897 break;
898
Sooraj Sasindran37444802020-08-11 10:40:43 -0700899 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
900 request = (MainThreadRequest) msg.obj;
901 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
902 Phone phone = getPhoneFromRequest(request);
903 if (phone != null) {
904 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
905 request.workSource);
906 } else {
907 loge("enableNrDualConnectivity: No phone object");
908 request.result =
909 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
910 notifyRequester(request);
911 }
912 break;
913 }
914
915 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null) {
919 request.result =
920 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
921 } else {
922 request.result =
923 TelephonyManager
924 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
925 if (ar.exception instanceof CommandException) {
926 CommandException.Error error =
927 ((CommandException) (ar.exception)).getCommandError();
928 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
929 request.result =
930 TelephonyManager
931 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000932 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
933 request.result =
934 TelephonyManager
935 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700936 }
937 loge("enableNrDualConnectivity" + ": CommandException: "
938 + ar.exception);
939 } else {
940 loge("enableNrDualConnectivity" + ": Unknown exception");
941 }
942 }
943 notifyRequester(request);
944 break;
945 }
946
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700947 case CMD_ENABLE_VONR: {
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
950 Phone phone = getPhoneFromRequest(request);
951 if (phone != null) {
952 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
953 request.workSource);
954 } else {
955 loge("setVoNrEnabled: No phone object");
956 request.result =
957 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
958 notifyRequester(request);
959 }
960 break;
961 }
962
963 case EVENT_ENABLE_VONR_DONE: {
964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
966 if (ar.exception == null) {
967 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
968 } else {
969 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
970 if (ar.exception instanceof CommandException) {
971 CommandException.Error error =
972 ((CommandException) (ar.exception)).getCommandError();
973 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
974 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
975 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
976 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
977 } else {
978 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
979 }
980 loge("setVoNrEnabled" + ": CommandException: "
981 + ar.exception);
982 } else {
983 loge("setVoNrEnabled" + ": Unknown exception");
984 }
985 }
986 notifyRequester(request);
987 break;
988 }
989
SongFerngWang3ef3e072020-12-21 16:41:52 +0800990 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800991 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800992 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
993 request);
994 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800995 break;
996
SongFerngWang3ef3e072020-12-21 16:41:52 +0800997 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception == null && ar.result != null) {
1001 request.result = ar.result; // Integer
1002 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301003 // request.result must be set to something non-null
1004 // for the calling thread to unblock
1005 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001006 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001007 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001008 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001009 loge("getAllowedNetworkTypesBitmask: CommandException: "
1010 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001011 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001012 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001013 }
1014 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001015 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 break;
1017
SongFerngWang3ef3e072020-12-21 16:41:52 +08001018 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001019 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001020 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1021 request);
1022 Pair<Integer, Long> reasonWithNetworkTypes =
1023 (Pair<Integer, Long>) request.argument;
1024 getPhoneFromRequest(request).setAllowedNetworkTypes(
1025 reasonWithNetworkTypes.first,
1026 reasonWithNetworkTypes.second,
1027 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001028 break;
1029
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1031 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001032 break;
1033
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001034 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1035 request = (MainThreadRequest)msg.obj;
1036 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001037 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001038 break;
1039
1040 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1041 ar = (AsyncResult)msg.obj;
1042 request = (MainThreadRequest)ar.userObj;
1043 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001044 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001045 break;
1046
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001047 case CMD_SET_VOICEMAIL_NUMBER:
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1050 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001051 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1052 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001053 break;
1054
1055 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1056 handleNullReturnEvent(msg, "setVoicemailNumber");
1057 break;
1058
Stuart Scott54788802015-03-30 13:18:01 -07001059 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1060 request = (MainThreadRequest) msg.obj;
1061 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1062 request);
1063 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1064 break;
1065
1066 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1067 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1068 break;
1069
Shishir Agrawal302c8692015-06-19 13:49:39 -07001070 case CMD_PERFORM_NETWORK_SCAN:
1071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1073 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1074 break;
1075
Hall Liu27d24262020-09-18 19:04:59 -07001076 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001077 request = (MainThreadRequest) msg.obj;
1078 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001079 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1080 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1081 request.argument;
1082 int callForwardingReason = args.first;
1083 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001084 break;
Hall Liu27d24262020-09-18 19:04:59 -07001085 }
1086 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001087 ar = (AsyncResult) msg.obj;
1088 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001089 TelephonyManager.CallForwardingInfoCallback callback =
1090 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1091 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001092 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001093 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001094 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1095 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1096 // Service Class is a bit mask per 3gpp 27.007. Search for
1097 // any service for voice call.
1098 if ((callForwardInfo.serviceClass
1099 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001100 callForwardingInfo = new CallForwardingInfo(true,
1101 callForwardInfo.reason,
1102 callForwardInfo.number,
1103 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001104 break;
1105 }
1106 }
1107 // Didn't find a call forward info for voice call.
1108 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001109 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1110 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001111 }
Hall Liu27d24262020-09-18 19:04:59 -07001112 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001113 } else {
1114 if (ar.result == null) {
1115 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1116 }
1117 if (ar.exception != null) {
1118 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1119 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001120 int errorCode = TelephonyManager
1121 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001122 if (ar.exception instanceof CommandException) {
1123 CommandException.Error error =
1124 ((CommandException) (ar.exception)).getCommandError();
1125 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001126 errorCode = TelephonyManager
1127 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001128 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001129 errorCode = TelephonyManager
1130 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001131 }
1132 }
Hall Liu27d24262020-09-18 19:04:59 -07001133 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001134 }
Shuo Qian4a594052020-01-23 11:59:30 -08001135 break;
Hall Liu27d24262020-09-18 19:04:59 -07001136 }
Shuo Qian4a594052020-01-23 11:59:30 -08001137
Hall Liu27d24262020-09-18 19:04:59 -07001138 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001141 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001142 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001143 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1144 request.argument).first;
1145 request.phone.setCallForwardingOption(
1146 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001147 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001148 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001149 callForwardingInfoToSet.getReason(),
1150 callForwardingInfoToSet.getNumber(),
1151 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1152 break;
Hall Liu27d24262020-09-18 19:04:59 -07001153 }
Shuo Qian4a594052020-01-23 11:59:30 -08001154
Hall Liu27d24262020-09-18 19:04:59 -07001155 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001156 ar = (AsyncResult) msg.obj;
1157 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001158 Consumer<Integer> callback =
1159 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1160 request.argument).second;
1161 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001162 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001163 int errorCode = TelephonyManager.CallForwardingInfoCallback
1164 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001165 if (ar.exception instanceof CommandException) {
1166 CommandException.Error error =
1167 ((CommandException) (ar.exception)).getCommandError();
1168 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001169 errorCode = TelephonyManager.CallForwardingInfoCallback
1170 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001171 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001172 errorCode = TelephonyManager.CallForwardingInfoCallback
1173 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001174 }
1175 }
1176 callback.accept(errorCode);
1177 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001178 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 }
Shuo Qian4a594052020-01-23 11:59:30 -08001180 break;
Hall Liu27d24262020-09-18 19:04:59 -07001181 }
Shuo Qian4a594052020-01-23 11:59:30 -08001182
Hall Liu27d24262020-09-18 19:04:59 -07001183 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1186 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1187 break;
Hall Liu27d24262020-09-18 19:04:59 -07001188 }
Shuo Qian4a594052020-01-23 11:59:30 -08001189
Hall Liu27d24262020-09-18 19:04:59 -07001190 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001191 ar = (AsyncResult) msg.obj;
1192 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001193 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001194 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1195 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001196 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001197 // Service Class is a bit mask per 3gpp 27.007.
1198 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001199 if (callForwardResults.length > 1
1200 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001201 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001202 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001203 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1204 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001205 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001206 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 }
1208 } else {
1209 if (ar.result == null) {
1210 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1211 }
1212 if (ar.exception != null) {
1213 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1214 }
1215 if (ar.exception instanceof CommandException) {
1216 CommandException.Error error =
1217 ((CommandException) (ar.exception)).getCommandError();
1218 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1219 callForwardingStatus =
1220 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1221 }
1222 }
1223 }
Hall Liu27d24262020-09-18 19:04:59 -07001224 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001225 break;
Hall Liu27d24262020-09-18 19:04:59 -07001226 }
Shuo Qian4a594052020-01-23 11:59:30 -08001227
Hall Liu27d24262020-09-18 19:04:59 -07001228 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001229 request = (MainThreadRequest) msg.obj;
1230 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001231 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1232 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001233 break;
Hall Liu27d24262020-09-18 19:04:59 -07001234 }
Shuo Qian4a594052020-01-23 11:59:30 -08001235
Hall Liu27d24262020-09-18 19:04:59 -07001236 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001237 ar = (AsyncResult) msg.obj;
1238 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001239 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1240 Consumer<Integer> callback =
1241 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1242 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001243 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001244 if (ar.exception instanceof CommandException) {
1245 CommandException.Error error =
1246 ((CommandException) (ar.exception)).getCommandError();
1247 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1248 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1249 } else {
1250 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1251 }
1252 } else {
1253 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1254 }
1255 } else {
1256 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1257 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259 break;
Hall Liu27d24262020-09-18 19:04:59 -07001260 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001261 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
1264 CellNetworkScanResult cellScanResult;
1265 if (ar.exception == null && ar.result != null) {
1266 cellScanResult = new CellNetworkScanResult(
1267 CellNetworkScanResult.STATUS_SUCCESS,
1268 (List<OperatorInfo>) ar.result);
1269 } else {
1270 if (ar.result == null) {
1271 loge("getCellNetworkScanResults: Empty response");
1272 }
1273 if (ar.exception != null) {
1274 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1275 }
1276 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1277 if (ar.exception instanceof CommandException) {
1278 CommandException.Error error =
1279 ((CommandException) (ar.exception)).getCommandError();
1280 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1281 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1282 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1283 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1284 }
1285 }
1286 cellScanResult = new CellNetworkScanResult(errorCode, null);
1287 }
1288 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001289 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001290 break;
1291
1292 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1293 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001294 ManualNetworkSelectionArgument selArg =
1295 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001296 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1297 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001298 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1299 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001300 break;
1301
1302 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
1305 if (ar.exception == null) {
1306 request.result = true;
1307 } else {
1308 request.result = false;
1309 loge("setNetworkSelectionModeManual " + ar.exception);
1310 }
1311 notifyRequester(request);
1312 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001313 break;
1314
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001315 case CMD_GET_MODEM_ACTIVITY_INFO:
1316 request = (MainThreadRequest) msg.obj;
1317 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001318 if (defaultPhone != null) {
1319 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001320 } else {
1321 ResultReceiver result = (ResultReceiver) request.argument;
1322 Bundle bundle = new Bundle();
1323 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001324 new ModemActivityInfo(0, 0, 0,
1325 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001326 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001327 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001328 break;
1329
Hall Liud0f208c2020-10-14 16:54:44 -07001330 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001331 ar = (AsyncResult) msg.obj;
1332 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001333 ResultReceiver result = (ResultReceiver) request.argument;
1334
Hall Liud0f208c2020-10-14 16:54:44 -07001335 ModemActivityInfo ret = null;
1336 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001337 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001338 // Update the last modem activity info and the result of the request.
1339 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1340 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001341 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001342 int[] txTimeMs = info.getTransmitTimeMillis();
1343 int[] lastModemTxTimeMs = mLastModemActivityInfo
1344 .getTransmitTimeMillis();
1345 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1346 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1347 }
Hall Liu49656c02020-10-09 19:00:11 -07001348 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001349 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1350 + mLastModemActivityInfo.getSleepTimeMillis());
1351 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1352 + mLastModemActivityInfo.getIdleTimeMillis());
1353 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1354 mLastModemActivityInfo.setReceiveTimeMillis(
1355 info.getReceiveTimeMillis()
1356 + mLastModemActivityInfo.getReceiveTimeMillis());
1357 }
Hall Liu49656c02020-10-09 19:00:11 -07001358 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001359 mLastModemActivityInfo.getSleepTimeMillis(),
1360 mLastModemActivityInfo.getIdleTimeMillis(),
1361 mLastModemActivityInfo.getTransmitTimeMillis(),
1362 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001363 } else {
1364 if (ar.result == null) {
1365 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001366 error = TelephonyManager.ModemActivityInfoException
1367 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001368 } else if (ar.exception instanceof CommandException) {
1369 loge("queryModemActivityInfo: CommandException: " +
1370 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001371 error = TelephonyManager.ModemActivityInfoException
1372 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001373 } else {
1374 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001375 error = TelephonyManager.ModemActivityInfoException
1376 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001377 }
1378 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001379 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001380 if (ret != null) {
1381 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1382 } else {
1383 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1384 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001385 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001386 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001387 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001388 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389
Meng Wang1a7c35a2016-05-05 20:56:15 -07001390 case CMD_SET_ALLOWED_CARRIERS:
1391 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001392 CarrierRestrictionRules argument =
1393 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001394 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001395 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001396 break;
1397
1398 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 if (ar.exception == null && ar.result != null) {
1402 request.result = ar.result;
1403 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001404 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1405 if (ar.exception instanceof CommandException) {
1406 loge("setAllowedCarriers: CommandException: " + ar.exception);
1407 CommandException.Error error =
1408 ((CommandException) (ar.exception)).getCommandError();
1409 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1410 request.result =
1411 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1412 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001413 } else {
1414 loge("setAllowedCarriers: Unknown exception");
1415 }
1416 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001417 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001418 break;
1419
1420 case CMD_GET_ALLOWED_CARRIERS:
1421 request = (MainThreadRequest) msg.obj;
1422 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001423 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001424 break;
1425
1426 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1427 ar = (AsyncResult) msg.obj;
1428 request = (MainThreadRequest) ar.userObj;
1429 if (ar.exception == null && ar.result != null) {
1430 request.result = ar.result;
1431 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001432 request.result = new IllegalStateException(
1433 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001434 if (ar.result == null) {
1435 loge("getAllowedCarriers: Empty response");
1436 } else if (ar.exception instanceof CommandException) {
1437 loge("getAllowedCarriers: CommandException: " +
1438 ar.exception);
1439 } else {
1440 loge("getAllowedCarriers: Unknown exception");
1441 }
1442 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001443 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001444 break;
1445
Nathan Haroldb3014052017-01-25 15:57:32 -08001446 case EVENT_GET_FORBIDDEN_PLMNS_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 {
1452 request.result = new IllegalArgumentException(
1453 "Failed to retrieve Forbidden Plmns");
1454 if (ar.result == null) {
1455 loge("getForbiddenPlmns: Empty response");
1456 } else {
1457 loge("getForbiddenPlmns: Unknown exception");
1458 }
1459 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001460 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001461 break;
1462
1463 case CMD_GET_FORBIDDEN_PLMNS:
1464 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001465 uiccPort = getUiccPortFromRequest(request);
1466 if (uiccPort == null) {
1467 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001468 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001469 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001470 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001471 break;
1472 }
1473 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001474 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001475 if (uiccApp == null) {
1476 loge("getForbiddenPlmns() no app with specified type -- "
1477 + appType);
1478 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001479 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001480 break;
1481 } else {
1482 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1483 + " specified type -- " + appType);
1484 }
1485 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1486 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1487 onCompleted);
1488 break;
1489
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001490 case CMD_SWITCH_SLOTS:
1491 request = (MainThreadRequest) msg.obj;
1492 int[] physicalSlots = (int[]) request.argument;
1493 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1494 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1495 break;
1496
1497 case EVENT_SWITCH_SLOTS_DONE:
1498 ar = (AsyncResult) msg.obj;
1499 request = (MainThreadRequest) ar.userObj;
1500 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 notifyRequester(request);
1502 break;
1503 case CMD_GET_NETWORK_SELECTION_MODE:
1504 request = (MainThreadRequest) msg.obj;
1505 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1506 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1507 break;
1508
1509 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1510 ar = (AsyncResult) msg.obj;
1511 request = (MainThreadRequest) ar.userObj;
1512 if (ar.exception != null) {
1513 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1514 } else {
1515 int mode = ((int[]) ar.result)[0];
1516 if (mode == 0) {
1517 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1518 } else {
1519 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1520 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
1523 break;
1524 case CMD_GET_CDMA_ROAMING_MODE:
1525 request = (MainThreadRequest) msg.obj;
1526 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1527 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1528 break;
1529 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 if (ar.exception != null) {
1533 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1534 } else {
1535 request.result = ((int[]) ar.result)[0];
1536 }
1537 notifyRequester(request);
1538 break;
1539 case CMD_SET_CDMA_ROAMING_MODE:
1540 request = (MainThreadRequest) msg.obj;
1541 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1542 int mode = (int) request.argument;
1543 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1544 break;
1545 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1546 ar = (AsyncResult) msg.obj;
1547 request = (MainThreadRequest) ar.userObj;
1548 request.result = ar.exception == null;
1549 notifyRequester(request);
1550 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001551 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1552 request = (MainThreadRequest) msg.obj;
1553 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1554 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1555 break;
1556 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1557 ar = (AsyncResult) msg.obj;
1558 request = (MainThreadRequest) ar.userObj;
1559 if (ar.exception != null) {
1560 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1561 } else {
1562 request.result = ((int[]) ar.result)[0];
1563 }
1564 notifyRequester(request);
1565 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001566 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1567 request = (MainThreadRequest) msg.obj;
1568 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1569 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001570 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1571 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001572 break;
1573 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1574 ar = (AsyncResult) msg.obj;
1575 request = (MainThreadRequest) ar.userObj;
1576 request.result = ar.exception == null;
1577 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001578 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001579 case CMD_GET_ALL_CELL_INFO:
1580 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001581 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001582 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001583 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001584 case EVENT_GET_ALL_CELL_INFO_DONE:
1585 ar = (AsyncResult) msg.obj;
1586 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001587 // If a timeout occurs, the response will be null
1588 request.result = (ar.exception == null && ar.result != null)
1589 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001590 synchronized (request) {
1591 request.notifyAll();
1592 }
1593 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001594 case CMD_REQUEST_CELL_INFO_UPDATE:
1595 request = (MainThreadRequest) msg.obj;
1596 request.phone.requestCellInfoUpdate(request.workSource,
1597 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1598 break;
1599 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1603 try {
1604 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001605 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001606 cb.onError(
1607 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1608 ar.exception.getClass().getName(),
1609 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001611 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001612 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001613 } else {
1614 // use the result as returned
1615 cb.onCellInfo((List<CellInfo>) ar.result);
1616 }
1617 } catch (RemoteException re) {
1618 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1619 }
1620 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001621 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001622 request = (MainThreadRequest) msg.obj;
1623 WorkSource ws = (WorkSource) request.argument;
1624 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001625 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001626 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001627 }
1628 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
1631 if (ar.exception == null) {
1632 request.result = ar.result;
1633 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001634 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001635 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001636 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001637 }
1638
1639 synchronized (request) {
1640 request.notifyAll();
1641 }
1642 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001643 }
chen xu6dac5ab2018-10-26 17:39:23 -07001644 case CMD_MODEM_REBOOT:
1645 request = (MainThreadRequest) msg.obj;
1646 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001647 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001648 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001649 case EVENT_CMD_MODEM_REBOOT_DONE:
1650 handleNullReturnEvent(msg, "rebootModem");
1651 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001652 case CMD_REQUEST_ENABLE_MODEM:
1653 request = (MainThreadRequest) msg.obj;
1654 boolean enable = (boolean) request.argument;
1655 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001656 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001657 PhoneConfigurationManager.getInstance()
1658 .enablePhone(request.phone, enable, onCompleted);
1659 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001660 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001661 ar = (AsyncResult) msg.obj;
1662 request = (MainThreadRequest) ar.userObj;
1663 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001664 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001665 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001666 if ((boolean) request.result) {
1667 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1668 updateModemStateMetrics();
1669 } else {
1670 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1671 + ar.exception);
1672 }
1673 notifyRequester(request);
1674 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001675 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001676 case CMD_GET_MODEM_STATUS:
1677 request = (MainThreadRequest) msg.obj;
1678 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1679 PhoneConfigurationManager.getInstance()
1680 .getPhoneStatusFromModem(request.phone, onCompleted);
1681 break;
1682 case EVENT_GET_MODEM_STATUS_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 int id = request.phone.getPhoneId();
1686 if (ar.exception == null && ar.result != null) {
1687 request.result = ar.result;
1688 //update the cache as modem status has changed
1689 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1690 (boolean) request.result);
1691 } else {
1692 // Return true if modem status cannot be retrieved. For most cases,
1693 // modem status is on. And for older version modems, GET_MODEM_STATUS
1694 // and disable modem are not supported. Modem is always on.
1695 // TODO: this should be fixed in R to support a third
1696 // status UNKNOWN b/131631629
1697 request.result = true;
1698 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1699 + ar.exception);
1700 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001701 notifyRequester(request);
1702 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001703 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1706 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1707 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1708 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1709 break;
1710 }
1711 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1712 ar = (AsyncResult) msg.obj;
1713 request = (MainThreadRequest) ar.userObj;
1714 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1715 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1716 args.second.accept(ar.exception == null);
1717 notifyRequester(request);
1718 break;
1719 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001720 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1721 request = (MainThreadRequest) msg.obj;
1722 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1723 Phone phone = getPhoneFromRequest(request);
1724 if (phone != null) {
1725 phone.getSystemSelectionChannels(onCompleted);
1726 } else {
1727 loge("getSystemSelectionChannels: No phone object");
1728 request.result = new ArrayList<RadioAccessSpecifier>();
1729 notifyRequester(request);
1730 }
1731 break;
1732 }
1733 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736 if (ar.exception == null && ar.result != null) {
1737 request.result = ar.result;
1738 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001739 request.result = new IllegalStateException(
1740 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001741 if (ar.result == null) {
1742 loge("getSystemSelectionChannels: Empty response");
1743 } else {
1744 loge("getSystemSelectionChannels: Unknown exception");
1745 }
1746 }
1747 notifyRequester(request);
1748 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001749 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 if (ar.exception == null && ar.result != null) {
1753 request.result = ar.result;
1754 } else {
1755 request.result = -1;
1756 loge("Failed to set Forbidden Plmns");
1757 if (ar.result == null) {
1758 loge("setForbidenPlmns: Empty response");
1759 } else if (ar.exception != null) {
1760 loge("setForbiddenPlmns: Exception: " + ar.exception);
1761 request.result = -1;
1762 } else {
1763 loge("setForbiddenPlmns: Unknown exception");
1764 }
1765 }
1766 notifyRequester(request);
1767 break;
1768 case CMD_SET_FORBIDDEN_PLMNS:
1769 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001770 uiccPort = getUiccPortFromRequest(request);
1771 if (uiccPort == null) {
1772 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001773 request.result = -1;
1774 notifyRequester(request);
1775 break;
1776 }
1777 Pair<Integer, List<String>> setFplmnsArgs =
1778 (Pair<Integer, List<String>>) request.argument;
1779 appType = setFplmnsArgs.first;
1780 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001781 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001782 if (uiccApp == null) {
1783 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1784 request.result = -1;
1785 loge("Failed to get UICC App");
1786 notifyRequester(request);
1787 } else {
1788 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1789 ((SIMRecords) uiccApp.getIccRecords())
1790 .setForbiddenPlmns(onCompleted, fplmns);
1791 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001792 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001793 case CMD_ERASE_MODEM_CONFIG:
1794 request = (MainThreadRequest) msg.obj;
1795 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1796 defaultPhone.eraseModemConfig(onCompleted);
1797 break;
1798 case EVENT_ERASE_MODEM_CONFIG_DONE:
1799 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001800 break;
zoey chene02881a2019-12-30 16:11:23 +08001801
Kai Shif70f46f2021-03-03 13:59:46 -08001802 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1803 request = (MainThreadRequest) msg.obj;
1804 request.result = defaultPhone.eraseDataInSharedPreferences();
1805 notifyRequester(request);
1806 break;
1807
zoey chene02881a2019-12-30 16:11:23 +08001808 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1809 request = (MainThreadRequest) msg.obj;
1810 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1811 Pair<String, String> changed = (Pair<String, String>) request.argument;
1812 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1813 changed.first, changed.second, onCompleted);
1814 break;
1815 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1816 ar = (AsyncResult) msg.obj;
1817 request = (MainThreadRequest) ar.userObj;
1818 if (ar.exception == null) {
1819 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001820 // If the operation is successful, update the PIN storage
1821 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1822 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001823 UiccController.getInstance().getPinStorage()
1824 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001825 } else {
1826 request.result = msg.arg1;
1827 }
1828 notifyRequester(request);
1829 break;
1830
Michele Berionne5e411512020-11-13 02:36:59 +00001831 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001832 request = (MainThreadRequest) msg.obj;
1833 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1834 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1835 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1836 enabled.first, enabled.second, onCompleted);
1837 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001838 }
zoey chene02881a2019-12-30 16:11:23 +08001839 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1840 ar = (AsyncResult) msg.obj;
1841 request = (MainThreadRequest) ar.userObj;
1842 if (ar.exception == null) {
1843 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001844 // If the operation is successful, update the PIN storage
1845 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1846 int phoneId = getPhoneFromRequest(request).getPhoneId();
1847 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001848 UiccController.getInstance().getPinStorage()
1849 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001850 } else {
1851 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1852 }
zoey chene02881a2019-12-30 16:11:23 +08001853 } else {
1854 request.result = msg.arg1;
1855 }
Michele Berionne5e411512020-11-13 02:36:59 +00001856
1857
zoey chene02881a2019-12-30 16:11:23 +08001858 notifyRequester(request);
1859 break;
1860
Peter Wangdafb9ac2020-01-15 14:13:38 -08001861 case MSG_NOTIFY_USER_ACTIVITY:
1862 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001863 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001864 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1865 getDefaultPhone().getContext().sendBroadcastAsUser(
1866 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1867 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001868
1869 case CMD_SET_DATA_THROTTLING: {
1870 request = (MainThreadRequest) msg.obj;
1871 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1872 DataThrottlingRequest dataThrottlingRequest =
1873 (DataThrottlingRequest) request.argument;
1874 Phone phone = getPhoneFromRequest(request);
1875 if (phone != null) {
1876 phone.setDataThrottling(onCompleted,
1877 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1878 dataThrottlingRequest.getCompletionDurationMillis());
1879 } else {
1880 loge("setDataThrottling: No phone object");
1881 request.result =
1882 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1883 notifyRequester(request);
1884 }
1885
1886 break;
1887 }
1888 case EVENT_SET_DATA_THROTTLING_DONE:
1889 ar = (AsyncResult) msg.obj;
1890 request = (MainThreadRequest) ar.userObj;
1891
1892 if (ar.exception == null) {
1893 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1894 } else if (ar.exception instanceof CommandException) {
1895 loge("setDataThrottling: CommandException: " + ar.exception);
1896 CommandException.Error error =
1897 ((CommandException) (ar.exception)).getCommandError();
1898
1899 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1900 request.result = TelephonyManager
1901 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1902 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1903 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001904 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1905 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001906 } else {
1907 request.result =
1908 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1909 }
1910 } else {
1911 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1912 }
1913 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1914 notifyRequester(request);
1915 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001916
1917 case CMD_SET_SIM_POWER: {
1918 request = (MainThreadRequest) msg.obj;
1919 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1920 request = (MainThreadRequest) msg.obj;
1921 int stateToSet =
1922 ((Pair<Integer, IIntegerConsumer>)
1923 request.argument).first;
1924 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1925 break;
1926 }
1927 case EVENT_SET_SIM_POWER_DONE: {
1928 ar = (AsyncResult) msg.obj;
1929 request = (MainThreadRequest) ar.userObj;
1930 IIntegerConsumer callback =
1931 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1932 if (ar.exception != null) {
1933 loge("setSimPower exception: " + ar.exception);
1934 int errorCode = TelephonyManager.CallForwardingInfoCallback
1935 .RESULT_ERROR_UNKNOWN;
1936 if (ar.exception instanceof CommandException) {
1937 CommandException.Error error =
1938 ((CommandException) (ar.exception)).getCommandError();
1939 if (error == CommandException.Error.SIM_ERR) {
1940 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1941 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1942 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1943 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1944 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1945 } else {
1946 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1947 }
1948 }
1949 try {
1950 callback.accept(errorCode);
1951 } catch (RemoteException e) {
1952 // Ignore if the remote process is no longer available to call back.
1953 Log.w(LOG_TAG, "setSimPower: callback not available.");
1954 }
1955 } else {
1956 try {
1957 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1958 } catch (RemoteException e) {
1959 // Ignore if the remote process is no longer available to call back.
1960 Log.w(LOG_TAG, "setSimPower: callback not available.");
1961 }
1962 }
1963 break;
1964 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001965 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1966 request = (MainThreadRequest) msg.obj;
1967
1968 final Phone phone = getPhoneFromRequest(request);
1969 if (phone == null || phone.getServiceStateTracker() == null) {
1970 request.result = new IllegalStateException("Phone or SST is null");
1971 notifyRequester(request);
1972 break;
1973 }
1974
1975 Pair<Integer, SignalStrengthUpdateRequest> pair =
1976 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1977 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1978 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001979 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001980 request.subId, pair.first /*callingUid*/,
1981 pair.second /*request*/, onCompleted);
1982 break;
1983 }
1984 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1985 ar = (AsyncResult) msg.obj;
1986 request = (MainThreadRequest) ar.userObj;
1987 // request.result will be the exception of ar if present, true otherwise.
1988 // Be cautious not to leave result null which will wait() forever
1989 request.result = ar.exception != null ? ar.exception : true;
1990 notifyRequester(request);
1991 break;
1992 }
1993 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1994 request = (MainThreadRequest) msg.obj;
1995
1996 Phone phone = getPhoneFromRequest(request);
1997 if (phone == null || phone.getServiceStateTracker() == null) {
1998 request.result = new IllegalStateException("Phone or SST is null");
1999 notifyRequester(request);
2000 break;
2001 }
2002
2003 Pair<Integer, SignalStrengthUpdateRequest> pair =
2004 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2005 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2006 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002007 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002008 request.subId, pair.first /*callingUid*/,
2009 pair.second /*request*/, onCompleted);
2010 break;
2011 }
2012 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2013 ar = (AsyncResult) msg.obj;
2014 request = (MainThreadRequest) ar.userObj;
2015 request.result = ar.exception != null ? ar.exception : true;
2016 notifyRequester(request);
2017 break;
2018 }
Jordan Liu109698e2020-11-24 14:50:34 -08002019
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002020 case CMD_GET_SLICING_CONFIG: {
2021 request = (MainThreadRequest) msg.obj;
2022 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2023 request.phone.getSlicingConfig(onCompleted);
2024 break;
2025 }
2026 case EVENT_GET_SLICING_CONFIG_DONE: {
2027 ar = (AsyncResult) msg.obj;
2028 request = (MainThreadRequest) ar.userObj;
2029 ResultReceiver result = (ResultReceiver) request.argument;
2030
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002031 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002032 Bundle bundle = new Bundle();
2033 int resultCode = 0;
2034 if (ar.exception != null) {
2035 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2036 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002037 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002038 } else if (ar.result == null) {
2039 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002040 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002041 } else {
2042 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002043 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2044 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002045 }
2046
2047 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002048 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002049 }
2050 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2051 result.send(resultCode, bundle);
2052 notifyRequester(request);
2053 break;
2054 }
2055
Michele Berionne5e411512020-11-13 02:36:59 +00002056 case CMD_PREPARE_UNATTENDED_REBOOT:
2057 request = (MainThreadRequest) msg.obj;
2058 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002059 UiccController.getInstance().getPinStorage()
2060 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002061 notifyRequester(request);
2062 break;
2063
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 default:
2065 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2066 break;
2067 }
2068 }
Jake Hambye994d462014-02-03 13:10:13 -08002069
Pengquan Menga1bb6272018-09-06 09:59:22 -07002070 private void notifyRequester(MainThreadRequest request) {
2071 synchronized (request) {
2072 request.notifyAll();
2073 }
2074 }
2075
Jake Hambye994d462014-02-03 13:10:13 -08002076 private void handleNullReturnEvent(Message msg, String command) {
2077 AsyncResult ar = (AsyncResult) msg.obj;
2078 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2079 if (ar.exception == null) {
2080 request.result = true;
2081 } else {
2082 request.result = false;
2083 if (ar.exception instanceof CommandException) {
2084 loge(command + ": CommandException: " + ar.exception);
2085 } else {
2086 loge(command + ": Unknown exception");
2087 }
2088 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002089 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 }
2092
2093 /**
2094 * Posts the specified command to be executed on the main thread,
2095 * waits for the request to complete, and returns the result.
2096 * @see #sendRequestAsync
2097 */
2098 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002099 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2100 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002101 }
2102
2103 /**
2104 * Posts the specified command to be executed on the main thread,
2105 * waits for the request to complete, and returns the result.
2106 * @see #sendRequestAsync
2107 */
2108 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2109 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002110 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002111 }
2112
2113 /**
2114 * Posts the specified command to be executed on the main thread,
2115 * waits for the request to complete, and returns the result.
2116 * @see #sendRequestAsync
2117 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002118 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002119 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2120 }
2121
2122 /**
2123 * Posts the specified command to be executed on the main thread,
2124 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2125 * if not timeout or null otherwise.
2126 * @see #sendRequestAsync
2127 */
2128 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2129 long timeoutInMs) {
2130 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002131 }
2132
2133 /**
2134 * Posts the specified command to be executed on the main thread,
2135 * waits for the request to complete, and returns the result.
2136 * @see #sendRequestAsync
2137 */
Nathan Harold92bed182018-10-12 18:16:49 -07002138 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002139 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002140 }
2141
2142 /**
2143 * Posts the specified command to be executed on the main thread,
2144 * waits for the request to complete, and returns the result.
2145 * @see #sendRequestAsync
2146 */
2147 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002148 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2149 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002150 }
2151
2152 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002153 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2154 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2155 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002156 * @see #sendRequestAsync
2157 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002158 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2159 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2161 throw new RuntimeException("This method will deadlock if called from the main thread.");
2162 }
2163
Nathan Harold92bed182018-10-12 18:16:49 -07002164 MainThreadRequest request = null;
2165 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2166 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2167 } else if (phone != null) {
2168 request = new MainThreadRequest(argument, phone, workSource);
2169 } else {
2170 request = new MainThreadRequest(argument, subId, workSource);
2171 }
2172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 Message msg = mMainThreadHandler.obtainMessage(command, request);
2174 msg.sendToTarget();
2175
Rambo Wang0f050d82021-02-12 11:43:36 -08002176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002178 if (timeoutInMs >= 0) {
2179 // Wait for at least timeoutInMs before returning null request result
2180 long now = SystemClock.elapsedRealtime();
2181 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002182 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002183 try {
2184 request.wait(deadline - now);
2185 } catch (InterruptedException e) {
2186 // Do nothing, go back and check if request is completed or timeout
2187 } finally {
2188 now = SystemClock.elapsedRealtime();
2189 }
2190 }
2191 } else {
2192 // Wait for the request to complete
2193 while (request.result == null) {
2194 try {
2195 request.wait();
2196 } catch (InterruptedException e) {
2197 // Do nothing, go back and wait until the request is complete
2198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200 }
2201 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002202 if (request.result == null) {
2203 Log.wtf(LOG_TAG,
2204 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2205 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 return request.result;
2207 }
2208
2209 /**
2210 * Asynchronous ("fire and forget") version of sendRequest():
2211 * Posts the specified command to be executed on the main thread, and
2212 * returns immediately.
2213 * @see #sendRequest
2214 */
2215 private void sendRequestAsync(int command) {
2216 mMainThreadHandler.sendEmptyMessage(command);
2217 }
2218
2219 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002220 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002221 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002222 */
2223 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002224 sendRequestAsync(command, argument, null, null);
2225 }
2226
2227 /**
2228 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2229 * @see {@link #sendRequest(int,Object)}
2230 */
2231 private void sendRequestAsync(
2232 int command, Object argument, Phone phone, WorkSource workSource) {
2233 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002234 Message msg = mMainThreadHandler.obtainMessage(command, request);
2235 msg.sendToTarget();
2236 }
2237
2238 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 * Initialize the singleton PhoneInterfaceManager instance.
2240 * This is only done once, at startup, from PhoneApp.onCreate().
2241 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002242 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 synchronized (PhoneInterfaceManager.class) {
2244 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002245 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 } else {
2247 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2248 }
2249 return sInstance;
2250 }
2251 }
2252
2253 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002254 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002257 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002258 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002260 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002262 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002263 mTelephonySharedPreferences =
2264 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002265 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002266 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002267 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002268 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002269
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 publish();
2271 }
2272
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002273 private Phone getDefaultPhone() {
2274 Phone thePhone = getPhone(getDefaultSubscription());
2275 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2276 }
2277
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 private void publish() {
2279 if (DBG) log("publish: " + this);
2280
Peter Wangc035ce42020-01-08 21:00:22 -08002281 TelephonyFrameworkInitializer
2282 .getTelephonyServiceManager()
2283 .getTelephonyServiceRegisterer()
2284 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286
Stuart Scott584921c2015-01-15 17:10:34 -08002287 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002288 if (request.phone != null) {
2289 return request.phone;
2290 } else {
2291 return getPhoneFromSubId(request.subId);
2292 }
2293 }
2294
2295 private Phone getPhoneFromSubId(int subId) {
2296 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2297 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002298 }
2299
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002300 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002301 Phone phone = getPhoneFromRequest(request);
2302 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002303 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002304 }
2305
Wink Saville36469e72014-06-11 15:17:00 -07002306 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002307 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002308 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310
Kai Shif70f46f2021-03-03 13:59:46 -08002311 private void sendEraseModemConfig(@NonNull Phone phone) {
2312 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2313 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2314 }
2315
2316 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2317 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2318 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002319 }
2320
Peter Wang44b186e2020-01-13 23:33:09 -08002321 private boolean isImsAvailableOnDevice() {
2322 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2323 if (pm == null) {
2324 // For some reason package manger is not available.. This will fail internally anyway,
2325 // so do not throw error and allow.
2326 return true;
2327 }
2328 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2329 }
2330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002332 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002333 }
2334
Wink Savilleb564aae2014-10-23 10:18:09 -07002335 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 if (DBG) log("dial: " + number);
2337 // No permission check needed here: This is just a wrapper around the
2338 // ACTION_DIAL intent, which is available to any app since it puts up
2339 // the UI before it does anything.
2340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 String url = createTelUrl(number);
2344 if (url == null) {
2345 return;
2346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348 // PENDING: should we just silently fail if phone is offhook or ringing?
2349 PhoneConstants.State state = mCM.getState(subId);
2350 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2351 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2352 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2353 mApp.startActivity(intent);
2354 }
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 }
2358 }
2359
2360 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002361 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002362 }
2363
Wink Savilleb564aae2014-10-23 10:18:09 -07002364 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 if (DBG) log("call: " + number);
2366
2367 // This is just a wrapper around the ACTION_CALL intent, but we still
2368 // need to do a permission check since we're calling startActivity()
2369 // from the context of the phone app.
2370 enforceCallPermission();
2371
Jordan Liu1617b712019-07-10 15:06:26 -07002372 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 != AppOpsManager.MODE_ALLOWED) {
2374 return;
2375 }
2376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 String url = createTelUrl(number);
2380 if (url == null) {
2381 return;
2382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002384 boolean isValid = false;
2385 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2386 if (slist != null) {
2387 for (SubscriptionInfo subInfoRecord : slist) {
2388 if (subInfoRecord.getSubscriptionId() == subId) {
2389 isValid = true;
2390 break;
2391 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002392 }
Wink Saville08874612014-08-31 19:19:58 -07002393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002394 if (!isValid) {
2395 return;
2396 }
Wink Saville08874612014-08-31 19:19:58 -07002397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2399 intent.putExtra(SUBSCRIPTION_KEY, subId);
2400 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2401 mApp.startActivity(intent);
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
2404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
2406
Wink Savilleb564aae2014-10-23 10:18:09 -07002407 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002408 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002409 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2410 }
2411
Wink Savilleb564aae2014-10-23 10:18:09 -07002412 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002413 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002414 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2415 }
2416
Wink Savilleb564aae2014-10-23 10:18:09 -07002417 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419
2420 final long identity = Binder.clearCallingIdentity();
2421 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002422 Phone phone = getPhone(subId);
2423 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424 checkSimPin.start();
2425 return checkSimPin.unlockSim(null, pin);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002433
2434 final long identity = Binder.clearCallingIdentity();
2435 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002436 Phone phone = getPhone(subId);
2437 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438 checkSimPuk.start();
2439 return checkSimPuk.unlockSim(puk, pin);
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
2442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444
2445 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002446 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 * a synchronous one.
2448 */
2449 private static class UnlockSim extends Thread {
2450
2451 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002452 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453
2454 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002455 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2456 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457
2458 // For replies from SimCard interface
2459 private Handler mHandler;
2460
2461 // For async handler to identify request type
2462 private static final int SUPPLY_PIN_COMPLETE = 100;
2463
Michele Berionne5e411512020-11-13 02:36:59 +00002464 UnlockSim(int phoneId, IccCard simCard) {
2465 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 mSimCard = simCard;
2467 }
2468
2469 @Override
2470 public void run() {
2471 Looper.prepare();
2472 synchronized (UnlockSim.this) {
2473 mHandler = new Handler() {
2474 @Override
2475 public void handleMessage(Message msg) {
2476 AsyncResult ar = (AsyncResult) msg.obj;
2477 switch (msg.what) {
2478 case SUPPLY_PIN_COMPLETE:
2479 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2480 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002481 mRetryCount = msg.arg1;
2482 if (ar.exception != null) {
2483 if (ar.exception instanceof CommandException &&
2484 ((CommandException)(ar.exception)).getCommandError()
2485 == CommandException.Error.PASSWORD_INCORRECT) {
2486 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002487 } //When UiccCardApp dispose,handle message and return exception
2488 else if (ar.exception instanceof CommandException &&
2489 ((CommandException) (ar.exception)).getCommandError()
2490 == CommandException.Error.ABORTED) {
2491 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002492 } else {
2493 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2494 }
2495 } else {
2496 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 mDone = true;
2499 UnlockSim.this.notifyAll();
2500 }
2501 break;
2502 }
2503 }
2504 };
2505 UnlockSim.this.notifyAll();
2506 }
2507 Looper.loop();
2508 }
2509
2510 /*
2511 * Use PIN or PUK to unlock SIM card
2512 *
2513 * If PUK is null, unlock SIM card with PIN
2514 *
2515 * If PUK is not null, unlock SIM card with PUK and set PIN code
2516 */
Wink Saville9de0f752013-10-22 19:04:03 -07002517 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518
2519 while (mHandler == null) {
2520 try {
2521 wait();
2522 } catch (InterruptedException e) {
2523 Thread.currentThread().interrupt();
2524 }
2525 }
2526 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2527
2528 if (puk == null) {
2529 mSimCard.supplyPin(pin, callback);
2530 } else {
2531 mSimCard.supplyPuk(puk, pin, callback);
2532 }
2533
2534 while (!mDone) {
2535 try {
2536 Log.d(LOG_TAG, "wait for done");
2537 wait();
2538 } catch (InterruptedException e) {
2539 // Restore the interrupted status
2540 Thread.currentThread().interrupt();
2541 }
2542 }
2543 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002544 int[] resultArray = new int[2];
2545 resultArray[0] = mResult;
2546 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002547
2548 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002549 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002550 }
2551
Wink Saville9de0f752013-10-22 19:04:03 -07002552 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554 }
2555
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002556 /**
2557 * This method has been removed due to privacy and stability concerns.
2558 */
2559 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002561 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2562 return;
Wink Saville36469e72014-06-11 15:17:00 -07002563 }
2564
Nathan Harold1f889d82020-06-04 17:05:26 -07002565 @Override
2566 public void updateServiceLocationWithPackageName(String callingPackage) {
2567 mApp.getSystemService(AppOpsManager.class)
2568 .checkPackage(Binder.getCallingUid(), callingPackage);
2569
Nathan Haroldf096d982020-11-18 17:18:06 -08002570 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002571 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2572 // Callers targeting S have no business invoking this method.
2573 return;
2574 }
2575
2576 LocationAccessPolicy.LocationPermissionResult locationResult =
2577 LocationAccessPolicy.checkLocationPermission(mApp,
2578 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2579 .setCallingPackage(callingPackage)
2580 .setCallingFeatureId(null)
2581 .setCallingPid(Binder.getCallingPid())
2582 .setCallingUid(Binder.getCallingUid())
2583 .setMethod("updateServiceLocation")
2584 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2585 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2586 .build());
2587 // Apps that lack location permission have no business calling this method;
2588 // however, because no permission was declared in the public API, denials must
2589 // all be "soft".
2590 switch (locationResult) {
2591 case DENIED_HARD: /* fall through */
2592 case DENIED_SOFT:
2593 return;
2594 }
2595
2596 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002599 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002601 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 }
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
2607
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002608 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002609 @Override
2610 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002611 return isRadioOnWithFeature(callingPackage, null);
2612 }
2613
2614
2615 @Override
2616 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2617 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2618 callingFeatureId);
2619 }
2620
2621 @Deprecated
2622 @Override
2623 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2624 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002625 }
2626
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002627 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002628 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2629 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002631 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002632 return false;
2633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 return isRadioOnForSubscriber(subId);
2638 } finally {
2639 Binder.restoreCallingIdentity(identity);
2640 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002641 }
2642
2643 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
2647 if (phone != null) {
2648 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2649 } else {
2650 return false;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 }
2656
2657 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002658 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
Wink Saville36469e72014-06-11 15:17:00 -07002660
Wink Savilleb564aae2014-10-23 10:18:09 -07002661 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663
2664 final long identity = Binder.clearCallingIdentity();
2665 try {
2666 final Phone phone = getPhone(subId);
2667 if (phone != null) {
2668 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 }
Wink Saville36469e72014-06-11 15:17:00 -07002673 }
2674
2675 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002676 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002677 }
2678
Wink Savilleb564aae2014-10-23 10:18:09 -07002679 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 final Phone phone = getPhone(subId);
2685 if (phone == null) {
2686 return false;
2687 }
2688 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2689 toggleRadioOnOffForSubscriber(subId);
2690 }
2691 return true;
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
Wink Saville36469e72014-06-11 15:17:00 -07002696
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002697 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002698 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002699 /*
2700 * If any of the Radios are available, it will need to be
2701 * shutdown. So return true if any Radio is available.
2702 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2706 Phone phone = PhoneFactory.getPhone(i);
2707 if (phone != null && phone.isRadioAvailable()) return true;
2708 }
2709 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2710 return false;
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002713 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002714 }
2715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002717 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 enforceModifyPermission();
2719
2720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2723 logv("Shutting down Phone " + i);
2724 shutdownRadioUsingPhoneId(i);
2725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002728 }
2729 }
2730
2731 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 Phone phone = PhoneFactory.getPhone(phoneId);
2733 if (phone != null && phone.isRadioAvailable()) {
2734 phone.shutdownRadio();
2735 }
2736 }
2737
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2744 if (defaultPhone != null) {
2745 defaultPhone.setRadioPower(turnOn);
2746 return true;
2747 } else {
2748 loge("There's no default phone.");
2749 return false;
2750 }
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002753 }
Wink Saville36469e72014-06-11 15:17:00 -07002754 }
2755
Wink Savilleb564aae2014-10-23 10:18:09 -07002756 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758
2759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 final Phone phone = getPhone(subId);
2762 if (phone != null) {
2763 phone.setRadioPower(turnOn);
2764 return true;
2765 } else {
2766 return false;
2767 }
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
Wink Saville36469e72014-06-11 15:17:00 -07002773 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 public boolean enableDataConnectivity() {
2776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 int subId = mSubscriptionController.getDefaultDataSubId();
2781 final Phone phone = getPhone(subId);
2782 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002783 phone.getDataEnabledSettings().setDataEnabled(
2784 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 return true;
2786 } else {
2787 return false;
2788 }
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
Wink Saville36469e72014-06-11 15:17:00 -07002794 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 public boolean disableDataConnectivity() {
2797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 int subId = mSubscriptionController.getDefaultDataSubId();
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002804 phone.getDataEnabledSettings().setDataEnabled(
2805 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 return true;
2807 } else {
2808 return false;
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 }
2814
Sanket Padawe356d7632015-06-22 14:03:32 -07002815 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002816 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 final Phone phone = getPhone(subId);
2820 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002821 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822 } else {
2823 return false;
2824 }
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 }
2829
2830 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002831 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002832 }
2833
pkanwarae03a6b2016-11-06 20:37:09 -08002834 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 enforceCallPermission();
2836
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2840 return;
2841 }
2842 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2843 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
2846 }
pkanwar32d516d2016-10-14 19:37:38 -07002847 };
2848
Wink Savilleb564aae2014-10-23 10:18:09 -07002849 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851
2852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2855 return false;
2856 }
2857 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 }
2862
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002863 /**
2864 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2865 * tag on getCallState Binder call.
2866 */
2867 @Deprecated
2868 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002870 if (CompatChanges.isChangeEnabled(
2871 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2872 Binder.getCallingUid())) {
2873 // Do not allow this API to be called on API version 31+, it should only be
2874 // called on old apps using this Binder call directly.
2875 throw new SecurityException("This method can only be used for applications "
2876 + "targeting API version 30 or less.");
2877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 final long identity = Binder.clearCallingIdentity();
2879 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002880 Phone phone = getPhone(getDefaultSubscription());
2881 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2882 PhoneConstantConversions.convertCallState(phone.getState());
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
2885 }
2886 }
2887
2888 @Override
2889 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2890 if (CompatChanges.isChangeEnabled(
2891 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2892 Binder.getCallingUid())) {
2893 // Check READ_PHONE_STATE for API version 31+
2894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2895 featureId, "getCallStateForSubscription")) {
2896 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2897 + "targeting API level 31+.");
2898 }
2899 }
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2904 PhoneConstantConversions.convertCallState(phone.getState());
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002908 }
2909
Sanket Padawe356d7632015-06-22 14:03:32 -07002910 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002911 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002912 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2913 }
2914
2915 @Override
2916 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 final long identity = Binder.clearCallingIdentity();
2918 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002919 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 if (phone != null) {
2921 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2922 } else {
2923 return PhoneConstantConversions.convertDataState(
2924 PhoneConstants.DataState.DISCONNECTED);
2925 }
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
Sanket Padawe356d7632015-06-22 14:03:32 -07002931 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002932 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002933 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2934 }
2935
2936 @Override
2937 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002940 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 if (phone != null) {
2942 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2943 } else {
2944 return TelephonyManager.DATA_ACTIVITY_NONE;
2945 }
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 }
2950
2951 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002952 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002954 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002955
2956 LocationAccessPolicy.LocationPermissionResult locationResult =
2957 LocationAccessPolicy.checkLocationPermission(mApp,
2958 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2959 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002960 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002961 .setCallingPid(Binder.getCallingPid())
2962 .setCallingUid(Binder.getCallingUid())
2963 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002964 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002965 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2966 .build());
2967 switch (locationResult) {
2968 case DENIED_HARD:
2969 throw new SecurityException("Not allowed to access cell location");
2970 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002971 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2972 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 }
2974
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002979 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002980 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
Svetoslav64fad262015-04-14 14:35:21 -07002984 }
2985
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002987 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002988 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2989 // registered cell info, so return a NULL country instead.
2990 final long identity = Binder.clearCallingIdentity();
2991 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002992 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2993 // Get default phone in this case.
2994 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2995 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002996 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002998 if (phone == null) return "";
2999 ServiceStateTracker sst = phone.getServiceStateTracker();
3000 if (sst == null) return "";
3001 LocaleTracker lt = sst.getLocaleTracker();
3002 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003003 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003007 }
3008
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003009 /**
3010 * This method was removed due to potential issues caused by performing partial
3011 * updates of service state, and lack of a credible use case.
3012 *
3013 * This has the ability to break the telephony implementation by disabling notification of
3014 * changes in device connectivity. DO NOT USE THIS!
3015 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003016 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003017 public void enableLocationUpdates() {
3018 mApp.enforceCallingOrSelfPermission(
3019 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 }
3021
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003022 /**
3023 * This method was removed due to potential issues caused by performing partial
3024 * updates of service state, and lack of a credible use case.
3025 *
3026 * This has the ability to break the telephony implementation by disabling notification of
3027 * changes in device connectivity. DO NOT USE THIS!
3028 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 @Override
3030 public void disableLocationUpdates() {
3031 mApp.enforceCallingOrSelfPermission(
3032 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 }
3034
3035 @Override
3036 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003037 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3038 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003039 try {
3040 mApp.getSystemService(AppOpsManager.class)
3041 .checkPackage(Binder.getCallingUid(), callingPackage);
3042 } catch (SecurityException e) {
3043 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3044 throw e;
3045 }
3046
Nathan Haroldf096d982020-11-18 17:18:06 -08003047 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003048 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3049 throw new SecurityException(
3050 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3051 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003052
Jordan Liu1617b712019-07-10 15:06:26 -07003053 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3055 return null;
3056 }
Svetoslav64fad262015-04-14 14:35:21 -07003057
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003058 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003060 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003061 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062
Nathan Haroldf180aac2018-06-01 18:43:55 -07003063 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3064 for (CellInfo ci : info) {
3065 if (ci instanceof CellInfoGsm) {
3066 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3067 } else if (ci instanceof CellInfoWcdma) {
3068 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003070 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003071 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 }
3073
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003074 private List<CellInfo> getCachedCellInfo() {
3075 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3076 for (Phone phone : PhoneFactory.getPhones()) {
3077 List<CellInfo> info = phone.getAllCellInfo();
3078 if (info != null) cellInfos.addAll(info);
3079 }
3080 return cellInfos;
3081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082
3083 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003084 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003085 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003086 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003087
3088 LocationAccessPolicy.LocationPermissionResult locationResult =
3089 LocationAccessPolicy.checkLocationPermission(mApp,
3090 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3091 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003092 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003093 .setCallingPid(Binder.getCallingPid())
3094 .setCallingUid(Binder.getCallingUid())
3095 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003096 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003097 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3098 .build());
3099 switch (locationResult) {
3100 case DENIED_HARD:
3101 throw new SecurityException("Not allowed to access cell info");
3102 case DENIED_SOFT:
3103 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 }
3105
Nathan Haroldf096d982020-11-18 17:18:06 -08003106 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003107 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3108 return getCachedCellInfo();
3109 }
3110
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003111 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3116 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003117 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003118 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003119 if (info != null) cellInfos.addAll(info);
3120 }
3121 return cellInfos;
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003124 }
3125 }
3126
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003127 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003128 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3129 String callingFeatureId) {
3130 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3131 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003132 }
3133
3134 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003135 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3136 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003137 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003138 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003139 }
3140
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003141 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3142 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003143 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003144 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003145
3146 LocationAccessPolicy.LocationPermissionResult locationResult =
3147 LocationAccessPolicy.checkLocationPermission(mApp,
3148 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3149 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003150 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003151 .setCallingPid(Binder.getCallingPid())
3152 .setCallingUid(Binder.getCallingUid())
3153 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003154 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3155 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003156 .build());
3157 switch (locationResult) {
3158 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003159 if (TelephonyPermissions
3160 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003161 // Safetynet logging for b/154934934
3162 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3163 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003164 throw new SecurityException("Not allowed to access cell info");
3165 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003166 if (TelephonyPermissions
3167 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003168 // Safetynet logging for b/154934934
3169 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3170 }
Nathan Harold5320c422019-05-09 10:26:08 -07003171 try {
3172 cb.onCellInfo(new ArrayList<CellInfo>());
3173 } catch (RemoteException re) {
3174 // Drop without consequences
3175 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003176 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003177 }
3178
Nathan Harolda939a962019-05-09 10:13:47 -07003179
3180 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003181 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3182
3183 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3184 }
3185
3186 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003188 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003189 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190
3191 final long identity = Binder.clearCallingIdentity();
3192 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
Shishir Agrawala9f32182016-04-12 12:00:16 -07003199 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003200 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003201 Phone phone = PhoneFactory.getPhone(slotIndex);
3202 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003203 return null;
3204 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003205 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003206 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003207 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003208 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003209 return null;
3210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211
3212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 return phone.getImei();
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003218 }
3219
3220 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003221 public String getTypeAllocationCodeForSlot(int slotIndex) {
3222 Phone phone = PhoneFactory.getPhone(slotIndex);
3223 String tac = null;
3224 if (phone != null) {
3225 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003226 try {
3227 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3228 } catch (IndexOutOfBoundsException e) {
3229 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3230 return null;
3231 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003232 }
3233 return tac;
3234 }
3235
3236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003237 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003238 try {
3239 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3240 } catch (SecurityException se) {
3241 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3242 throw new SecurityException("Package " + callingPackage + " does not belong to "
3243 + Binder.getCallingUid());
3244 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003245 Phone phone = PhoneFactory.getPhone(slotIndex);
3246 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003247 return null;
3248 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003249
Jeff Davidson913390f2018-02-23 17:11:49 -08003250 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003251 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003252 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003253 return null;
3254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255
3256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 return phone.getMeid();
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
Jack Yu2af8d712017-03-15 17:14:14 -07003262 }
3263
3264 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003265 public String getManufacturerCodeForSlot(int slotIndex) {
3266 Phone phone = PhoneFactory.getPhone(slotIndex);
3267 String manufacturerCode = null;
3268 if (phone != null) {
3269 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003270 try {
3271 manufacturerCode =
3272 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3273 } catch (IndexOutOfBoundsException e) {
3274 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3275 return null;
3276 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003277 }
3278 return manufacturerCode;
3279 }
3280
3281 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003282 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3283 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003284 Phone phone = PhoneFactory.getPhone(slotIndex);
3285 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003286 return null;
3287 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003288 int subId = phone.getSubId();
3289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003290 mApp, subId, callingPackage, callingFeatureId,
3291 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003292 return null;
3293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294
3295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 return phone.getDeviceSvn();
3298 } finally {
3299 Binder.restoreCallingIdentity(identity);
3300 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003301 }
3302
fionaxu43304da2017-11-27 22:51:16 -08003303 @Override
3304 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 final Phone phone = getPhone(subId);
3308 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
fionaxu43304da2017-11-27 22:51:16 -08003312 }
3313
3314 @Override
3315 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 final long identity = Binder.clearCallingIdentity();
3317 try {
3318 final Phone phone = getPhone(subId);
3319 return phone == null ? null : phone.getCarrierName();
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
3322 }
fionaxu43304da2017-11-27 22:51:16 -08003323 }
3324
calvinpanffe225e2018-11-01 19:43:06 +08003325 @Override
chen xu0026ca62019-03-06 15:28:50 -08003326 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 final Phone phone = getPhone(subId);
3330 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003331 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
3335 }
3336
3337 @Override
chen xu0026ca62019-03-06 15:28:50 -08003338 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003342 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
3346 }
3347
chen xu651eec72018-11-11 19:03:44 -08003348 @Override
chen xu864e11c2018-12-06 22:10:03 -08003349 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3350 if (!isSubscriptionMccMnc) {
3351 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3352 }
chen xu651eec72018-11-11 19:03:44 -08003353 final Phone phone = PhoneFactory.getPhone(slotIndex);
3354 if (phone == null) {
3355 return TelephonyManager.UNKNOWN_CARRIER_ID;
3356 }
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
3362 }
3363 }
3364
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003365 //
3366 // Internal helper methods.
3367 //
3368
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003369 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003370 * Make sure the caller is the calling package itself
3371 *
3372 * @throws SecurityException if the caller is not the calling package
3373 */
3374 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3375 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003376 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3377 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003378 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003379 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003380 } catch (PackageManager.NameNotFoundException e) {
3381 // packageUid is -1
3382 }
3383 if (packageUid != callingUid) {
3384 throw new SecurityException(message + ": Package " + callingPackage
3385 + " does not belong to " + callingUid);
3386 }
3387 }
3388
3389 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3391 *
3392 * @throws SecurityException if the caller does not have the required permission
3393 */
3394 private void enforceModifyPermission() {
3395 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3396 }
3397
Shuo Qiancd19c462020-01-16 20:51:11 -08003398 /**
3399 * Make sure the caller is system.
3400 *
3401 * @throws SecurityException if the caller is not system.
3402 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003403 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003404 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3405 throw new SecurityException("Caller must be system");
3406 }
3407 }
3408
Shuo Qian3b6ee772019-11-13 17:43:31 -08003409 private void enforceActiveEmergencySessionPermission() {
3410 mApp.enforceCallingOrSelfPermission(
3411 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3412 }
3413
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 /**
3415 * Make sure the caller has the CALL_PHONE permission.
3416 *
3417 * @throws SecurityException if the caller does not have the required permission
3418 */
3419 private void enforceCallPermission() {
3420 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3421 }
3422
paulhu5a773602019-08-23 19:17:33 +08003423 private void enforceSettingsPermission() {
3424 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003425 }
3426
Michele Berionne5e411512020-11-13 02:36:59 +00003427 private void enforceRebootPermission() {
3428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3429 }
3430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 private String createTelUrl(String number) {
3432 if (TextUtils.isEmpty(number)) {
3433 return null;
3434 }
3435
Jake Hambye994d462014-02-03 13:10:13 -08003436 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 }
3438
Ihab Awadf9e92732013-12-05 18:02:52 -08003439 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3441 }
3442
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003443 private static void logv(String msg) {
3444 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3445 }
3446
Ihab Awadf9e92732013-12-05 18:02:52 -08003447 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3449 }
3450
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003451 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003453 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003454 }
3455
Sanket Padawe356d7632015-06-22 14:03:32 -07003456 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003457 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003458 final long identity = Binder.clearCallingIdentity();
3459 try {
3460 final Phone phone = PhoneFactory.getPhone(slotIndex);
3461 if (phone == null) {
3462 return PhoneConstants.PHONE_TYPE_NONE;
3463 } else {
3464 return phone.getPhoneType();
3465 }
3466 } finally {
3467 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003469 }
3470
3471 /**
3472 * Returns the CDMA ERI icon index to display
3473 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003474 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003475 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3476 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3477 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003478 }
3479
Sanket Padawe356d7632015-06-22 14:03:32 -07003480 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003481 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3482 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003484 mApp, subId, callingPackage, callingFeatureId,
3485 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003486 return -1;
3487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 final Phone phone = getPhone(subId);
3492 if (phone != null) {
3493 return phone.getCdmaEriIconIndex();
3494 } else {
3495 return -1;
3496 }
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003500 }
3501
3502 /**
3503 * Returns the CDMA ERI icon mode,
3504 * 0 - ON
3505 * 1 - FLASHING
3506 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003507 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003508 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3509 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3510 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003511 }
3512
Sanket Padawe356d7632015-06-22 14:03:32 -07003513 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003514 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3515 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003517 mApp, subId, callingPackage, callingFeatureId,
3518 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003519 return -1;
3520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 final Phone phone = getPhone(subId);
3525 if (phone != null) {
3526 return phone.getCdmaEriIconMode();
3527 } else {
3528 return -1;
3529 }
3530 } finally {
3531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 }
3534
3535 /**
3536 * Returns the CDMA ERI text,
3537 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003539 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3540 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3541 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003542 }
3543
Sanket Padawe356d7632015-06-22 14:03:32 -07003544 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003545 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3546 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003548 mApp, subId, callingPackage, callingFeatureId,
3549 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003550 return null;
3551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003552
3553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 final Phone phone = getPhone(subId);
3556 if (phone != null) {
3557 return phone.getCdmaEriText();
3558 } else {
3559 return null;
3560 }
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003564 }
3565
3566 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003567 * Returns the CDMA MDN.
3568 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003569 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003570 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3572 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003577 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 return phone.getLine1Number();
3579 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 return null;
3582 }
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003585 }
3586 }
3587
3588 /**
3589 * Returns the CDMA MIN.
3590 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003591 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003592 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3594 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 final Phone phone = getPhone(subId);
3599 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3600 return phone.getCdmaMin();
3601 } else {
3602 return null;
3603 }
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003606 }
3607 }
3608
Hall Liud892bec2018-11-30 14:51:45 -08003609 @Override
3610 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3611 INumberVerificationCallback callback, String callingPackage) {
3612 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3613 != PERMISSION_GRANTED) {
3614 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3615 }
3616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3617
3618 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3619 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003620 throw new SecurityException("Calling package must be configured in the device config: "
3621 + "calling package: " + callingPackage
3622 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003623 }
3624
3625 if (range == null) {
3626 throw new NullPointerException("Range must be non-null");
3627 }
3628
3629 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003630 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003631
3632 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3633 }
3634
Junda Liuca05d5d2014-08-14 22:36:34 -07003635 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003636 * Returns true if CDMA provisioning needs to run.
3637 */
3638 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003641 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003645 }
3646
3647 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003648 * Sets the voice mail number of a given subId.
3649 */
3650 @Override
3651 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003652 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3653 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3658 new Pair<String, String>(alphaTag, number), new Integer(subId));
3659 return success;
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003663 }
3664
Ta-wei Yen87c49842016-05-13 21:19:52 -07003665 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003666 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003668 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3669 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003670 if (!TextUtils.equals(callingPackage, systemDialer)) {
3671 throw new SecurityException("caller must be system dialer");
3672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3677 if (phoneAccountHandle == null) {
3678 return null;
3679 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003680 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681 } finally {
3682 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003683 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003684 }
3685
3686 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003687 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3688 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003691 mApp, subId, callingPackage, callingFeatureId,
3692 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003693 return null;
3694 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003695
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003696 final long identity = Binder.clearCallingIdentity();
3697 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003698 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003702 }
3703
3704 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003705 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3706 VisualVoicemailSmsFilterSettings settings) {
3707 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708
3709 final long identity = Binder.clearCallingIdentity();
3710 try {
3711 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003716 }
3717
3718 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003719 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003725 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003729 }
3730
3731 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003732 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3733 String callingPackage, int subId) {
3734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003743 }
3744
3745 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003746 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748
3749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003756 }
3757
3758 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003759 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3760 String callingAttributionTag, int subId, String number, int port, String text,
3761 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003762 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003763 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003764 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003765 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003766 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3767 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003768 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003769
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003770 /**
fionaxu0152e512016-11-14 13:36:14 -08003771 * Sets the voice activation state of a given subId.
3772 */
3773 @Override
3774 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3776 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777
3778 final long identity = Binder.clearCallingIdentity();
3779 try {
3780 final Phone phone = getPhone(subId);
3781 if (phone != null) {
3782 phone.setVoiceActivationState(activationState);
3783 } else {
3784 loge("setVoiceActivationState fails with invalid subId: " + subId);
3785 }
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003788 }
3789 }
3790
3791 /**
3792 * Sets the data activation state of a given subId.
3793 */
3794 @Override
3795 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3797 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798
3799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 final Phone phone = getPhone(subId);
3802 if (phone != null) {
3803 phone.setDataActivationState(activationState);
3804 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003805 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 }
3807 } finally {
3808 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003809 }
3810 }
3811
3812 /**
3813 * Returns the voice activation state of a given subId.
3814 */
3815 @Override
3816 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003817 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818
fionaxu0152e512016-11-14 13:36:14 -08003819 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 if (phone != null) {
3823 return phone.getVoiceActivationState();
3824 } else {
3825 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3826 }
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003829 }
3830 }
3831
3832 /**
3833 * Returns the data activation state of a given subId.
3834 */
3835 @Override
3836 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003837 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003838
fionaxu0152e512016-11-14 13:36:14 -08003839 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 if (phone != null) {
3843 return phone.getDataActivationState();
3844 } else {
3845 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3846 }
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003849 }
3850 }
3851
3852 /**
Wink Saville36469e72014-06-11 15:17:00 -07003853 * Returns the unread count of voicemails for a subId
3854 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3857 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 mApp, subId, callingPackage, callingFeatureId,
3860 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003861 return 0;
3862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 final Phone phone = getPhone(subId);
3866 if (phone != null) {
3867 return phone.getVoiceMessageCount();
3868 } else {
3869 return 0;
3870 }
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003874 }
3875
3876 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003877 * returns true, if the device is in a state where both voice and data
3878 * are supported simultaneously. This can change based on location or network condition.
3879 */
3880 @Override
3881 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 final Phone phone = getPhone(subId);
3885 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3886 } finally {
3887 Binder.restoreCallingIdentity(identity);
3888 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003889 }
3890
3891 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003892 * Send the dialer code if called from the current default dialer or the caller has
3893 * carrier privilege.
3894 * @param inputCode The dialer code to send
3895 */
3896 @Override
3897 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003898 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003899 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003900 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3901 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003902 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003903 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003904 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906
3907 final long identity = Binder.clearCallingIdentity();
3908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910 } finally {
3911 Binder.restoreCallingIdentity(identity);
3912 }
fionaxu235cc5e2017-03-06 22:25:57 -08003913 }
3914
Pengquan Menga1bb6272018-09-06 09:59:22 -07003915 @Override
3916 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003917 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003918 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003919 mApp, subId, "getNetworkSelectionMode");
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 if (!isActiveSubscription(subId)) {
3923 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3924 }
3925 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3926 } finally {
3927 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003928 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003929 }
3930
Brad Ebinger35c841c2018-10-01 10:40:55 -07003931 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003932 public boolean isInEmergencySmsMode() {
3933 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 for (Phone phone : PhoneFactory.getPhones()) {
3937 if (phone.isInEmergencySmsMode()) {
3938 return true;
3939 }
3940 }
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
3943 }
3944 return false;
3945 }
3946
shilu366312e2019-12-17 09:28:10 -08003947 /**
3948 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3949 * @param subId The subscription to use to check the configuration.
3950 * @param c The callback that will be used to send the result.
3951 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003952 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003953 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3954 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003955 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003956 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003957
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003958 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3959 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3960 "IMS not available on device.");
3961 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 final long token = Binder.clearCallingIdentity();
3963 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003964 int slotId = getSlotIndexOrException(subId);
3965 verifyImsMmTelConfiguredOrThrow(slotId);
3966 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003967 } catch (ImsException e) {
3968 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 } finally {
3970 Binder.restoreCallingIdentity(token);
3971 }
3972 }
3973
shilu366312e2019-12-17 09:28:10 -08003974 /**
3975 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3976 * @param subId The subscription to use to check the configuration.
3977 * @param c The callback that will be used to send the result.
3978 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003980 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003981 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003982 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003983 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3984 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3985 }
Meng Wangafbc5852019-09-19 17:37:13 -07003986 final long token = Binder.clearCallingIdentity();
3987 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003988 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3989 .removeRegistrationCallbackForSubscription(c, subId);
3990 } catch (ImsException e) {
3991 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3992 + "is inactive, ignoring unregister.");
3993 // If the subscription is no longer active, just return, since the callback
3994 // will already have been removed internally.
3995 } finally {
3996 Binder.restoreCallingIdentity(token);
3997 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 }
3999
Brad Ebingera34a6c22019-10-22 17:36:18 -07004000 /**
4001 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4002 */
4003 @Override
4004 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4005 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4006 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4007 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4008 "IMS not available on device.");
4009 }
4010 final long token = Binder.clearCallingIdentity();
4011 try {
4012 Phone phone = getPhone(subId);
4013 if (phone == null) {
4014 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4015 + subId + "'");
4016 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4017 }
4018 phone.getImsRegistrationState(regState -> {
4019 try {
4020 consumer.accept((regState == null)
4021 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4022 } catch (RemoteException e) {
4023 // Ignore if the remote process is no longer available to call back.
4024 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4025 }
4026 });
4027 } finally {
4028 Binder.restoreCallingIdentity(token);
4029 }
4030 }
4031
4032 /**
4033 * Get the transport type for the IMS service registration state.
4034 */
4035 @Override
4036 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004037 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004038 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004039 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4040 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4041 "IMS not available on device.");
4042 }
4043 final long token = Binder.clearCallingIdentity();
4044 try {
4045 Phone phone = getPhone(subId);
4046 if (phone == null) {
4047 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4048 + subId + "'");
4049 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4050 }
4051 phone.getImsRegistrationTech(regTech -> {
4052 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4053 int regTechConverted = (regTech == null)
4054 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4055 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4056 regTechConverted);
4057 try {
4058 consumer.accept(regTechConverted);
4059 } catch (RemoteException e) {
4060 // Ignore if the remote process is no longer available to call back.
4061 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4062 }
4063 });
4064 } finally {
4065 Binder.restoreCallingIdentity(token);
4066 }
4067 }
4068
shilu366312e2019-12-17 09:28:10 -08004069 /**
4070 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4071 * @param subId The subscription to use to check the configuration.
4072 * @param c The callback that will be used to send the result.
4073 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004075 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4076 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004077 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004078 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004079 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4080 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4081 "IMS not available on device.");
4082 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 final long token = Binder.clearCallingIdentity();
4084 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004085 int slotId = getSlotIndexOrException(subId);
4086 verifyImsMmTelConfiguredOrThrow(slotId);
4087 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004088 } catch (ImsException e) {
4089 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 } finally {
4091 Binder.restoreCallingIdentity(token);
4092 }
4093 }
4094
shilu366312e2019-12-17 09:28:10 -08004095 /**
4096 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4097 * @param subId The subscription to use to check the configuration.
4098 * @param c The callback that will be used to send the result.
4099 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004101 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004102 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004103 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004104 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4105 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4106 }
Meng Wangafbc5852019-09-19 17:37:13 -07004107
4108 final long token = Binder.clearCallingIdentity();
4109 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004110 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004111 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004112 } catch (ImsException e) {
4113 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4114 + "is inactive, ignoring unregister.");
4115 // If the subscription is no longer active, just return, since the callback
4116 // will already have been removed internally.
4117 } finally {
4118 Binder.restoreCallingIdentity(token);
4119 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004120 }
4121
4122 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004123 public boolean isCapable(int subId, int capability, int regTech) {
4124 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 final long token = Binder.clearCallingIdentity();
4126 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004127 int slotId = getSlotIndexOrException(subId);
4128 verifyImsMmTelConfiguredOrThrow(slotId);
4129 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004130 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4132 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004133 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004134 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4135 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 } finally {
4137 Binder.restoreCallingIdentity(token);
4138 }
4139 }
4140
4141 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004142 public boolean isAvailable(int subId, int capability, int regTech) {
4143 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 final long token = Binder.clearCallingIdentity();
4145 try {
4146 Phone phone = getPhone(subId);
4147 if (phone == null) return false;
4148 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004149 } catch (com.android.ims.ImsException e) {
4150 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4151 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 } finally {
4153 Binder.restoreCallingIdentity(token);
4154 }
4155 }
4156
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004157 /**
4158 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4159 * subscription.
4160 * @param subId The subscription to use to check the configuration.
4161 * @param callback The callback that will be used to send the result.
4162 * @param capability The MmTelFeature capability that will be used to send the result.
4163 * @param transportType The transport type of the MmTelFeature capability.
4164 */
4165 @Override
4166 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4167 int transportType) {
4168 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4169 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4170 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4171 "IMS not available on device.");
4172 }
4173 final long token = Binder.clearCallingIdentity();
4174 try {
4175 int slotId = getSlotIndex(subId);
4176 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4177 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4178 + subId + "'");
4179 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4180 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004181 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004182 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4183 transportType, aBoolean -> {
4184 try {
4185 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4186 } catch (RemoteException e) {
4187 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4188 + "running. Ignore");
4189 }
4190 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004191 } catch (ImsException e) {
4192 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004193 } finally {
4194 Binder.restoreCallingIdentity(token);
4195 }
4196 }
4197
shilu366312e2019-12-17 09:28:10 -08004198 /**
4199 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4200 * @param subId The subscription to use to check the configuration.
4201 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 @Override
4203 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004204 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004205 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004206
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 final long token = Binder.clearCallingIdentity();
4208 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004209 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004210 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004211 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004212 } catch (ImsException e) {
4213 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 } finally {
4215 Binder.restoreCallingIdentity(token);
4216 }
4217 }
4218
4219 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004220 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004222 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004223 final long identity = Binder.clearCallingIdentity();
4224 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004225 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004226 // This setting doesn't require an active ImsService connection, so do not verify. The
4227 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004228 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004229 } catch (ImsException e) {
4230 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 } finally {
4232 Binder.restoreCallingIdentity(identity);
4233 }
4234 }
4235
shilu366312e2019-12-17 09:28:10 -08004236 /**
4237 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4238 * @param subId The subscription to use to check the configuration.
4239 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004241 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004242 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004243 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 final long identity = Binder.clearCallingIdentity();
4245 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004246 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004247 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004248 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004249 } catch (ImsException e) {
4250 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
4254 }
4255
4256 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004257 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004259 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004260 final long identity = Binder.clearCallingIdentity();
4261 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004262 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004263 // This setting doesn't require an active ImsService connection, so do not verify. The
4264 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004265 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004266 } catch (ImsException e) {
4267 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 } finally {
4269 Binder.restoreCallingIdentity(identity);
4270 }
4271 }
4272
shilu366312e2019-12-17 09:28:10 -08004273 /**
4274 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4275 * @param subId The subscription to use to check the configuration.
4276 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004277 @Override
4278 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004279 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004280 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 final long identity = Binder.clearCallingIdentity();
4282 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004283 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004284 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004285 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004286 } catch (ImsException e) {
4287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 } finally {
4289 Binder.restoreCallingIdentity(identity);
4290 }
4291 }
4292
4293 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004294 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004296 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004297 final long identity = Binder.clearCallingIdentity();
4298 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004300 // This setting doesn't require an active ImsService connection, so do not verify. The
4301 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004302 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004303 } catch (ImsException e) {
4304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
4308 }
4309
shilu366312e2019-12-17 09:28:10 -08004310 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004311 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4312 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4313 * @param subId The subscription to use to check the configuration.
4314 */
4315 @Override
4316 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004317 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004318 mApp, subId, "isCrossSimCallingEnabledByUser");
4319 final long identity = Binder.clearCallingIdentity();
4320 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004321 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004322 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004323 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004324 } catch (ImsException e) {
4325 throw new ServiceSpecificException(e.getCode());
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
4329 }
4330
4331 /**
4332 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4333 * Requires MODIFY_PHONE_STATE permission.
4334 * @param subId The subscription to use to check the configuration.
4335 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4336 * false otherwise
4337 */
4338 @Override
4339 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4341 "setCrossSimCallingEnabled");
4342 final long identity = Binder.clearCallingIdentity();
4343 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004344 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004345 // This setting doesn't require an active ImsService connection, so do not verify. The
4346 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004347 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004348 } catch (ImsException e) {
4349 throw new ServiceSpecificException(e.getCode());
4350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
4353 }
4354
4355 /**
shilu366312e2019-12-17 09:28:10 -08004356 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4357 * @param subId The subscription to use to check the configuration.
4358 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004360
Brad Ebinger35c841c2018-10-01 10:40:55 -07004361 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004362 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004363 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 final long identity = Binder.clearCallingIdentity();
4365 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004366 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004367 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004368 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004369 } catch (ImsException e) {
4370 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
4374 }
4375
4376 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004377 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004379 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004380 final long identity = Binder.clearCallingIdentity();
4381 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004382 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004383 // This setting doesn't require an active ImsService connection, so do not verify. The
4384 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004385 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004386 } catch (ImsException e) {
4387 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004388 } finally {
4389 Binder.restoreCallingIdentity(identity);
4390 }
4391 }
4392
4393 @Override
4394 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4396 "setVoWiFiNonPersistent");
4397 final long identity = Binder.clearCallingIdentity();
4398 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004399 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004400 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004401 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004402 } catch (ImsException e) {
4403 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004404 } finally {
4405 Binder.restoreCallingIdentity(identity);
4406 }
4407 }
4408
shilu366312e2019-12-17 09:28:10 -08004409 /**
4410 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4411 * @param subId The subscription to use to check the configuration.
4412 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004413 @Override
4414 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004415 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004416 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 final long identity = Binder.clearCallingIdentity();
4418 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004419 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004420 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004421 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004422 } catch (ImsException e) {
4423 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
4427 }
4428
4429 @Override
4430 public void setVoWiFiModeSetting(int subId, int mode) {
4431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4432 "setVoWiFiModeSetting");
4433 final long identity = Binder.clearCallingIdentity();
4434 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004435 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004436 // This setting doesn't require an active ImsService connection, so do not verify. The
4437 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004439 } catch (ImsException e) {
4440 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
4444 }
4445
4446 @Override
4447 public int getVoWiFiRoamingModeSetting(int subId) {
4448 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4449 final long identity = Binder.clearCallingIdentity();
4450 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004451 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004452 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004453 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004454 } catch (ImsException e) {
4455 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
4459 }
4460
4461 @Override
4462 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4464 "setVoWiFiRoamingModeSetting");
4465 final long identity = Binder.clearCallingIdentity();
4466 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004467 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004468 // This setting doesn't require an active ImsService connection, so do not verify. The
4469 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004471 } catch (ImsException e) {
4472 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004473 } finally {
4474 Binder.restoreCallingIdentity(identity);
4475 }
4476 }
4477
4478 @Override
4479 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4481 "setRttCapabilityEnabled");
4482 final long identity = Binder.clearCallingIdentity();
4483 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004484 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004485 // This setting doesn't require an active ImsService connection, so do not verify. The
4486 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004487 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004488 } catch (ImsException e) {
4489 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
4493 }
4494
shilu366312e2019-12-17 09:28:10 -08004495 /**
4496 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4497 * @param subId The subscription to use to check the configuration.
4498 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 @Override
4500 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004501 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004502 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 final long identity = Binder.clearCallingIdentity();
4504 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004505 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004506 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004507 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004508 } catch (ImsException e) {
4509 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
4513 }
4514
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004515 @Override
4516 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4517 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4518 final long identity = Binder.clearCallingIdentity();
4519 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004520 if (!isImsAvailableOnDevice()) {
4521 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4522 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004523 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004524 int slotId = getSlotIndexOrException(subId);
4525 verifyImsMmTelConfiguredOrThrow(slotId);
4526 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004527 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004528 } catch (ImsException e) {
4529 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
4533 }
4534
4535 @Override
4536 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4537 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4538 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004539 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4540 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4541 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004542 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004543 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004544 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004545 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004546 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4547 + "is inactive, ignoring unregister.");
4548 // If the subscription is no longer active, just return, since the callback will already
4549 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
allenwtsu99c623b2020-01-03 18:24:23 +08004555
4556 private void checkModifyPhoneStatePermission(int subId, String message) {
4557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4558 message);
4559 }
4560
4561 private boolean isImsProvisioningRequired(int subId, int capability,
4562 boolean isMmtelCapability) {
4563 Phone phone = getPhone(subId);
4564 if (phone == null) {
4565 loge("phone instance null for subid " + subId);
4566 return false;
4567 }
4568 if (isMmtelCapability) {
4569 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4570 return false;
4571 }
4572 } else {
4573 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4574 return false;
4575 }
4576 }
4577 return true;
4578 }
4579
4580 @Override
4581 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4582 boolean isProvisioned) {
4583 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4584
4585 final long identity = Binder.clearCallingIdentity();
4586 try {
4587 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4588 if (!isImsProvisioningRequired(subId, capability, false)) {
4589 return;
4590 }
4591
4592 // this capability requires provisioning, route to the correct API.
4593 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4594 switch (capability) {
4595 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4596 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4597 ims.setEabProvisioned(isProvisioned);
4598 break;
4599 default: {
4600 throw new IllegalArgumentException("Tried to set provisioning for "
4601 + "rcs capability '" + capability + "', which does not require "
4602 + "provisioning.");
4603 }
4604 }
4605 } finally {
4606 Binder.restoreCallingIdentity(identity);
4607 }
4608
4609 }
4610
4611
4612 @Override
4613 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4614 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4615 final long identity = Binder.clearCallingIdentity();
4616 try {
4617 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4618 if (!isImsProvisioningRequired(subId, capability, false)) {
4619 return true;
4620 }
4621
4622 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4623 switch (capability) {
4624 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4625 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4626 return ims.isEabProvisionedOnDevice();
4627
4628 default: {
4629 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4630 + "capability '" + capability + "', which does not require "
4631 + "provisioning.");
4632 }
4633 }
4634
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004640 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004641 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4642 boolean isProvisioned) {
4643 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004644 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4645 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4646 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004647 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4648 }
allenwtsu99c623b2020-01-03 18:24:23 +08004649 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004650 final long identity = Binder.clearCallingIdentity();
4651 try {
4652 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004653 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 return;
4655 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004656 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4657 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4658 loge("setImsProvisioningStatusForCapability: called for technology that does "
4659 + "not support provisioning - " + tech);
4660 return;
4661 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662
4663 // this capability requires provisioning, route to the correct API.
4664 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4665 switch (capability) {
4666 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4667 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4668 ims.setVolteProvisioned(isProvisioned);
4669 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4670 ims.setWfcProvisioned(isProvisioned);
4671 }
4672 break;
4673 }
4674 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4675 // There is currently no difference in VT provisioning type.
4676 ims.setVtProvisioned(isProvisioned);
4677 break;
4678 }
4679 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4680 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4681 // change the capability of the feature instead if needed.
4682 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4683 == isProvisioned) {
4684 // No change in provisioning.
4685 return;
4686 }
4687 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4688 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004689 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004690 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004691 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4692 + ", Exception" + e.getMessage());
4693 }
4694 break;
4695 }
4696 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004697 throw new IllegalArgumentException("Tried to set provisioning for "
4698 + "MmTel capability '" + capability + "', which does not require "
4699 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004700 }
4701 }
4702
4703 } finally {
4704 Binder.restoreCallingIdentity(identity);
4705 }
4706 }
4707
4708 @Override
4709 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4710 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004711 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4712 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4713 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4715 }
4716 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4717 final long identity = Binder.clearCallingIdentity();
4718 try {
4719 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004720 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004721 return true;
4722 }
4723
Brad Ebinger0d79c572021-04-17 15:20:49 -07004724 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4725 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4726 loge("getImsProvisioningStatusForCapability: called for technology that does "
4727 + "not support provisioning - " + tech);
4728 return true;
4729 }
4730
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004731 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4732 switch (capability) {
4733 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4734 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4735 return ims.isVolteProvisionedOnDevice();
4736 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4737 return ims.isWfcProvisionedOnDevice();
4738 }
4739 // This should never happen, since we are checking tech above to make sure it
4740 // is either LTE or IWLAN.
4741 throw new IllegalArgumentException("Invalid radio technology for voice "
4742 + "capability.");
4743 }
4744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4745 // There is currently no difference in VT provisioning type.
4746 return ims.isVtProvisionedOnDevice();
4747 }
4748 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4749 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4750 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4751 }
4752 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004753 throw new IllegalArgumentException(
4754 "Tried to get provisioning for MmTel capability '" + capability
4755 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004756 }
4757 }
4758
4759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
4762 }
4763
4764 @Override
4765 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4766 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4767 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4768 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4769 }
4770 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4771 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4772 return (provisionedBits & capability) > 0;
4773 }
4774
4775 @Override
4776 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4777 boolean isProvisioned) {
4778 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4779 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4780 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4781 }
4782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4783 "setProvisioningStatusForCapability");
4784 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4785 // If the current provisioning status for capability already matches isProvisioned,
4786 // do nothing.
4787 if (((provisionedBits & capability) > 0) == isProvisioned) {
4788 return;
4789 }
4790 if (isProvisioned) {
4791 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4792 } else {
4793 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4794 }
4795 }
4796
4797 /**
4798 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4799 * technology. The bitfield should mirror the bitfield defined by
4800 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4801 */
4802 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4803 String key = getMmTelProvisioningKey(subId, tech);
4804 // Default is no capabilities are provisioned.
4805 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4806 }
4807
4808 /**
4809 * Sets the MmTel capability provisioning bitfield (defined by
4810 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4811 * technology specified.
4812 *
4813 * Note: This is a synchronous command and should not be called on UI thread.
4814 */
4815 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4816 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4817 String key = getMmTelProvisioningKey(subId, tech);
4818 editor.putInt(key, newField);
4819 editor.commit();
4820 }
4821
4822 private static String getMmTelProvisioningKey(int subId, int tech) {
4823 // resulting key is provision_ims_mmtel_{subId}_{tech}
4824 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4825 }
4826
4827 /**
4828 * Query CarrierConfig to see if the specified capability requires provisioning for the
4829 * carrier associated with the subscription id.
4830 */
4831 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4832 int capability) {
4833 CarrierConfigManager configManager = new CarrierConfigManager(context);
4834 PersistableBundle c = configManager.getConfigForSubId(subId);
4835 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004836 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004837 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4838 false);
4839 boolean requireVoiceVtProvisioning = c.getBoolean(
4840 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4841
4842 // First check to make sure that the capability requires provisioning.
4843 switch (capability) {
4844 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4845 // intentional fallthrough
4846 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4847 if (requireVoiceVtProvisioning) {
4848 // Voice and Video requires provisioning
4849 return true;
4850 }
4851 break;
4852 }
4853 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4854 if (requireUtProvisioning) {
4855 // UT requires provisioning
4856 return true;
4857 }
4858 break;
4859 }
4860 }
4861 return false;
4862 }
4863
allenwtsu99c623b2020-01-03 18:24:23 +08004864 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4865 int capability) {
4866 CarrierConfigManager configManager = new CarrierConfigManager(context);
4867 PersistableBundle c = configManager.getConfigForSubId(subId);
4868
4869 boolean requireRcsProvisioning = c.getBoolean(
4870 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4871
4872 // First check to make sure that the capability requires provisioning.
4873 switch (capability) {
4874 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4875 // intentional fallthrough
4876 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4877 if (requireRcsProvisioning) {
4878 // OPTION or PRESENCE requires provisioning
4879 return true;
4880 }
4881 break;
4882 }
4883 }
4884 return false;
4885 }
4886
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004887 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004888 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4890 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4891 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004892 enforceReadPrivilegedPermission("getImsProvisioningInt");
4893 final long identity = Binder.clearCallingIdentity();
4894 try {
4895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004896 int slotId = getSlotIndex(subId);
4897 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4898 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4899 + subId + "' for key:" + key);
4900 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4901 }
calvinpanb5a34062021-02-08 19:59:36 +08004902 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004903 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004904 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4905 + subId + "' for key:" + key);
4906 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
4910 }
4911
4912 @Override
4913 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004914 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4915 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4916 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004917 enforceReadPrivilegedPermission("getImsProvisioningString");
4918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 int slotId = getSlotIndex(subId);
4922 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4923 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4924 + subId + "' for key:" + key);
4925 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4926 }
calvinpanb5a34062021-02-08 19:59:36 +08004927 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004928 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4930 + subId + "' for key:" + key);
4931 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
4937 @Override
4938 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4940 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4941 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4943 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 int slotId = getSlotIndex(subId);
4948 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4949 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4950 + subId + "' for key:" + key);
4951 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4952 }
calvinpanb5a34062021-02-08 19:59:36 +08004953 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4954 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004956 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
4961 }
4962
4963 @Override
4964 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004965 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4966 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4967 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4969 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973 int slotId = getSlotIndex(subId);
4974 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4975 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4976 + subId + "' for key:" + key);
4977 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4978 }
calvinpanb5a34062021-02-08 19:59:36 +08004979 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4980 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004981 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004982 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004983 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004984 } finally {
4985 Binder.restoreCallingIdentity(identity);
4986 }
4987 }
4988
Brad Ebinger919631e2021-06-02 17:46:35 -07004989 /**
4990 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4991 * for the given slot ID or no ImsResolver instance has been created.
4992 * @param slotId The slot ID that the IMS service is created for.
4993 * @throws ImsException If there is no ImsService configured for this slot.
4994 */
4995 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4996 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4997 ImsFeature.FEATURE_MMTEL)) {
4998 throw new ImsException("This subscription does not support MMTEL over IMS",
4999 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5000 }
5001 }
5002
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005003 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005004 int slotId = SubscriptionManager.getSlotIndex(subId);
5005 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005006 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5007 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 }
5009 return slotId;
5010 }
5011
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005012 private int getSlotIndex(int subId) {
5013 int slotId = SubscriptionManager.getSlotIndex(subId);
5014 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5015 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5016 }
5017 return slotId;
5018 }
5019
Wink Saville36469e72014-06-11 15:17:00 -07005020 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005021 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005022 */
5023 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005024 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5025 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005026 try {
5027 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5028 } catch (SecurityException se) {
5029 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5030 throw new SecurityException("Package " + callingPackage + " does not belong to "
5031 + Binder.getCallingUid());
5032 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005033 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005034 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005035 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005036 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005037 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005038 mApp, subId, callingPackage, callingFeatureId,
5039 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005040 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5041 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 final long identity = Binder.clearCallingIdentity();
5044 try {
5045 final Phone phone = getPhone(subId);
5046 if (phone != null) {
5047 return phone.getServiceState().getDataNetworkType();
5048 } else {
5049 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5050 }
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005054 }
5055
5056 /**
5057 * Returns the data network type
5058 */
5059 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005060 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005061 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5062 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005063 }
5064
5065 /**
5066 * Returns the data network type for a subId
5067 */
5068 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005069 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5070 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005072 mApp, subId, callingPackage, callingFeatureId,
5073 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005074 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5075 }
5076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 final Phone phone = getPhone(subId);
5080 if (phone != null) {
5081 return phone.getServiceState().getDataNetworkType();
5082 } else {
5083 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5084 }
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005088 }
5089
5090 /**
Wink Saville36469e72014-06-11 15:17:00 -07005091 * Returns the Voice network type for a subId
5092 */
5093 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005094 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5095 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005097 mApp, subId, callingPackage, callingFeatureId,
5098 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005099 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5100 }
5101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 final long identity = Binder.clearCallingIdentity();
5103 try {
5104 final Phone phone = getPhone(subId);
5105 if (phone != null) {
5106 return phone.getServiceState().getVoiceNetworkType();
5107 } else {
5108 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5109 }
5110 } finally {
5111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005113 }
5114
5115 /**
5116 * @return true if a ICC card is present
5117 */
5118 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005119 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005120 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5121 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005122 }
5123
5124 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005125 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005126 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005127 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005128 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 final long identity = Binder.clearCallingIdentity();
5130 try {
5131 final Phone phone = PhoneFactory.getPhone(slotIndex);
5132 if (phone != null) {
5133 return phone.getIccCard().hasIccCard();
5134 } else {
5135 return false;
5136 }
5137 } finally {
5138 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005140 }
5141
5142 /**
5143 * Return if the current radio is LTE on CDMA. This
5144 * is a tri-state return value as for a period of time
5145 * the mode may be unknown.
5146 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005147 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005148 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005149 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005150 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005151 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005152 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5153 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5154 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005155 }
5156
Sanket Padawe356d7632015-06-22 14:03:32 -07005157 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005158 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5159 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005160 try {
5161 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5162 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005163 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5164 }
5165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 final long identity = Binder.clearCallingIdentity();
5167 try {
5168 final Phone phone = getPhone(subId);
5169 if (phone == null) {
5170 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5171 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005172 return TelephonyProperties.lte_on_cdma_device()
5173 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 }
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005177 }
Wink Saville36469e72014-06-11 15:17:00 -07005178 }
5179
Wink Saville36469e72014-06-11 15:17:00 -07005180 /**
5181 * {@hide}
5182 * Returns Default subId, 0 in the case of single standby.
5183 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005184 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005185 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005186 }
5187
Shishir Agrawala9f32182016-04-12 12:00:16 -07005188 private int getSlotForDefaultSubscription() {
5189 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5190 }
5191
Wink Savilleb564aae2014-10-23 10:18:09 -07005192 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005193 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005194 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005195
Pengquan Menge92a50d2018-09-21 15:54:48 -07005196 private boolean isActiveSubscription(int subId) {
5197 return mSubscriptionController.isActiveSubId(subId);
5198 }
5199
Ihab Awadf2177b72013-11-25 13:33:23 -08005200 /**
5201 * @see android.telephony.TelephonyManager.WifiCallingChoices
5202 */
5203 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 final long identity = Binder.clearCallingIdentity();
5205 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005206 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5208 getWhenToMakeWifiCallsDefaultPreference());
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005212 }
5213
5214 /**
5215 * @see android.telephony.TelephonyManager.WifiCallingChoices
5216 */
5217 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005221 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005226 }
5227
Sailesh Nepald1e68152013-12-12 19:08:02 -08005228 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005229 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005230 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005231 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005232
Jordan Liu4c733742019-02-28 12:03:40 -08005233 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5234 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5235 if (phoneId == -1) {
5236 throw new IllegalArgumentException("Given slot index: " + slotIndex
5237 + " does not correspond to an active phone");
5238 }
5239 return PhoneFactory.getPhone(phoneId);
5240 }
5241
Shishir Agrawal566b7612013-10-28 14:41:00 -07005242 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005243 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5244 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5246 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005248 if (DBG) {
5249 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5250 }
5251 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5252 p2);
5253 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005254
Jordan Liu4c733742019-02-28 12:03:40 -08005255
5256 @Override
5257 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5258 int slotIndex, String callingPackage, String aid, int p2) {
5259 enforceModifyPermission();
5260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5261 if (DBG) {
5262 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5263 }
5264 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5265 callingPackage, aid, p2);
5266 }
5267
5268 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5269 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 if (TextUtils.equals(ISDR_AID, aid)) {
5273 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005274 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5275 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 if (bestComponent == null
5277 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5278 loge("The calling package is not allowed to access ISD-R.");
5279 throw new SecurityException(
5280 "The calling package is not allowed to access ISD-R.");
5281 }
Derek Tan740e1672017-06-27 14:56:27 -07005282 }
Derek Tan740e1672017-06-27 14:56:27 -07005283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005285 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5286 null /* workSource */);
5287 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 return response;
5289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005292 }
5293
5294 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005295 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5297 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005298 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5299 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5300 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005301
Jordan Liu4c733742019-02-28 12:03:40 -08005302 @Override
5303 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5304 enforceModifyPermission();
5305 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5306 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5307 channel);
5308 }
5309
5310 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 final long identity = Binder.clearCallingIdentity();
5312 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 if (channel < 0) {
5314 return false;
5315 }
Jordan Liu4c733742019-02-28 12:03:40 -08005316 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5317 null /* workSource */);
5318 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 return success;
5320 } finally {
5321 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005322 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005323 }
5324
5325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005326 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005327 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5329 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005330 if (DBG) {
5331 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5332 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5333 + p3 + " data=" + data);
5334 }
5335 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5336 command, p1, p2, p3, data);
5337 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005338
Jordan Liu4c733742019-02-28 12:03:40 -08005339 @Override
5340 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5341 int command, int p1, int p2, int p3, String data) {
5342 enforceModifyPermission();
5343 if (DBG) {
5344 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5345 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5346 + p3 + " data=" + data);
5347 }
5348 return iccTransmitApduLogicalChannelWithPermission(
5349 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5350 data);
5351 }
5352
5353 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5354 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 final long identity = Binder.clearCallingIdentity();
5356 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005357 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 return "";
5359 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005362 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5363 null /* workSource */);
5364 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 // Append the returned status code to the end of the response payload.
5367 String s = Integer.toHexString(
5368 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5369 if (response.payload != null) {
5370 s = IccUtils.bytesToHexString(response.payload) + s;
5371 }
5372 return s;
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005375 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005376 }
Jake Hambye994d462014-02-03 13:10:13 -08005377
Evan Charltonc66da362014-05-16 14:06:40 -07005378 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005379 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5380 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5382 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005384 if (DBG) {
5385 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5386 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5387 }
5388 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5389 cla, command, p1, p2, p3, data);
5390 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005391
Jordan Liu4c733742019-02-28 12:03:40 -08005392 @Override
5393 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5394 int command, int p1, int p2, int p3, String data) {
5395 enforceModifyPermission();
5396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5397 if (DBG) {
5398 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5399 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5400 + " data=" + data);
5401 }
5402
5403 return iccTransmitApduBasicChannelWithPermission(
5404 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5405 p2, p3, data);
5406 }
5407
5408 // open APDU basic channel assuming the caller has sufficient permissions
5409 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5410 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5414 && TextUtils.equals(ISDR_AID, data)) {
5415 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005416 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5417 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 if (bestComponent == null
5419 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5420 loge("The calling package is not allowed to select ISD-R.");
5421 throw new SecurityException(
5422 "The calling package is not allowed to select ISD-R.");
5423 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005424 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005427 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5428 null /* workSource */);
5429 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005430
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 // Append the returned status code to the end of the response payload.
5432 String s = Integer.toHexString(
5433 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5434 if (response.payload != null) {
5435 s = IccUtils.bytesToHexString(response.payload) + s;
5436 }
5437 return s;
5438 } finally {
5439 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005440 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005441 }
5442
5443 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005444 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005445 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5447 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
5451 if (DBG) {
5452 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5453 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5454 }
5455
5456 IccIoResult response =
5457 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5458 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5459 subId);
5460
5461 if (DBG) {
5462 log("Exchange SIM_IO [R]" + response);
5463 }
5464
5465 byte[] result = null;
5466 int length = 2;
5467 if (response.payload != null) {
5468 length = 2 + response.payload.length;
5469 result = new byte[length];
5470 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5471 } else {
5472 result = new byte[length];
5473 }
5474
5475 result[length - 1] = (byte) response.sw2;
5476 result[length - 2] = (byte) response.sw1;
5477 return result;
5478 } finally {
5479 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005480 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005481 }
5482
Nathan Haroldb3014052017-01-25 15:57:32 -08005483 /**
5484 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5485 * on a particular subscription
5486 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005487 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5488 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005490 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005491 return null;
5492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493
5494 final long identity = Binder.clearCallingIdentity();
5495 try {
5496 if (appType != TelephonyManager.APPTYPE_USIM
5497 && appType != TelephonyManager.APPTYPE_SIM) {
5498 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5499 return null;
5500 }
5501 Object response = sendRequest(
5502 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5503 if (response instanceof String[]) {
5504 return (String[]) response;
5505 }
yincheng zhao2737e882019-09-06 17:06:54 -07005506 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005508 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 } finally {
5510 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005511 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005512 }
5513
yincheng zhao2737e882019-09-06 17:06:54 -07005514 /**
5515 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5516 * subscription.
5517 *
5518 * @param subId the id of the subscription.
5519 * @param appType the uicc app type, must be USIM or SIM.
5520 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5521 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005522 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005523 * @return number of fplmns that is successfully written to the SIM.
5524 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005525 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5526 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5528 mApp, subId, "setForbiddenPlmns");
5529
yincheng zhao2737e882019-09-06 17:06:54 -07005530 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5531 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5532 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5533 }
5534 if (fplmns == null) {
5535 throw new IllegalArgumentException("Fplmn List provided is null");
5536 }
5537 for (String fplmn : fplmns) {
5538 if (!CellIdentity.isValidPlmn(fplmn)) {
5539 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5540 }
5541 }
5542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 Object response = sendRequest(
5545 CMD_SET_FORBIDDEN_PLMNS,
5546 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5547 subId);
5548 return (int) response;
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
5552 }
5553
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005554 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005555 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5557 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 final long identity = Binder.clearCallingIdentity();
5560 try {
5561 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5562 if (response.payload == null) {
5563 return "";
5564 }
Evan Charltonc66da362014-05-16 14:06:40 -07005565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 // Append the returned status code to the end of the response payload.
5567 String s = Integer.toHexString(
5568 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5569 s = IccUtils.bytesToHexString(response.payload) + s;
5570 return s;
5571 } finally {
5572 Binder.restoreCallingIdentity(identity);
5573 }
Evan Charltonc66da362014-05-16 14:06:40 -07005574 }
5575
Jake Hambye994d462014-02-03 13:10:13 -08005576 /**
5577 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5578 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5579 *
5580 * @param itemID the ID of the item to read
5581 * @return the NV item as a String, or null on error.
5582 */
5583 @Override
5584 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005585 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5587 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588
5589 final long identity = Binder.clearCallingIdentity();
5590 try {
5591 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005592 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5594 return value;
5595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
Jake Hambye994d462014-02-03 13:10:13 -08005598 }
5599
5600 /**
5601 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5602 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5603 *
5604 * @param itemID the ID of the item to read
5605 * @param itemValue the value to write, as a String
5606 * @return true on success; false on any failure
5607 */
5608 @Override
5609 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005610 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5612 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613
5614 final long identity = Binder.clearCallingIdentity();
5615 try {
5616 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5617 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005618 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5620 return success;
5621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
Jake Hambye994d462014-02-03 13:10:13 -08005624 }
5625
5626 /**
5627 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5628 * Used for device configuration by some CDMA operators.
5629 *
5630 * @param preferredRoamingList byte array containing the new PRL
5631 * @return true on success; false on any failure
5632 */
5633 @Override
5634 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5636 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637
5638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5641 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5642 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5643 return success;
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
Jake Hambye994d462014-02-03 13:10:13 -08005647 }
5648
5649 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005650 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005651 * Used for device configuration by some CDMA operators.
5652 *
chen xu6dac5ab2018-10-26 17:39:23 -07005653 * @param slotIndex - device slot.
5654 *
Jake Hambye994d462014-02-03 13:10:13 -08005655 * @return true on success; false on any failure
5656 */
5657 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005658 public boolean resetModemConfig(int slotIndex) {
5659 Phone phone = PhoneFactory.getPhone(slotIndex);
5660 if (phone != null) {
5661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5662 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663
chen xu6dac5ab2018-10-26 17:39:23 -07005664 final long identity = Binder.clearCallingIdentity();
5665 try {
5666 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5667 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5668 return success;
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 }
chen xu6dac5ab2018-10-26 17:39:23 -07005673 return false;
5674 }
5675
5676 /**
5677 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5678 *
5679 * @param slotIndex - device slot.
5680 *
5681 * @return true on success; false on any failure
5682 */
5683 @Override
5684 public boolean rebootModem(int slotIndex) {
5685 Phone phone = PhoneFactory.getPhone(slotIndex);
5686 if (phone != null) {
5687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5688 mApp, phone.getSubId(), "rebootModem");
5689
5690 final long identity = Binder.clearCallingIdentity();
5691 try {
5692 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5693 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5694 return success;
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
5698 }
5699 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005700 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005701
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005702 public String[] getPcscfAddress(String apnType, String callingPackage,
5703 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005704 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5706 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005707 return new String[0];
5708 }
5709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 final long identity = Binder.clearCallingIdentity();
5711 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005712 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 } finally {
5714 Binder.restoreCallingIdentity(identity);
5715 }
Wink Saville36469e72014-06-11 15:17:00 -07005716 }
5717
Brad Ebinger51f743a2017-01-23 13:50:20 -08005718 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005719 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5720 * {@link #disableIms(int)}.
5721 * @param slotIndex device slot.
5722 */
5723 public void resetIms(int slotIndex) {
5724 enforceModifyPermission();
5725
5726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 if (mImsResolver == null) {
5729 // may happen if the does not support IMS.
5730 return;
5731 }
5732 mImsResolver.disableIms(slotIndex);
5733 mImsResolver.enableIms(slotIndex);
5734 } finally {
5735 Binder.restoreCallingIdentity(identity);
5736 }
5737 }
5738
5739 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005740 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5741 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005742 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005743 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005748 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005749 // may happen if the device does not support IMS.
5750 return;
5751 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005752 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005756 }
5757
5758 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005759 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5760 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005761 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005762 public void disableIms(int slotId) {
5763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764
5765 final long identity = Binder.clearCallingIdentity();
5766 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005767 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005768 // may happen if the device does not support IMS.
5769 return;
5770 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005771 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005775 }
5776
5777 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005778 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5779 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005780 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005781 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005782 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005783 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784
5785 final long identity = Binder.clearCallingIdentity();
5786 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005787 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005788 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5789 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005790 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005791 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 } finally {
5793 Binder.restoreCallingIdentity(identity);
5794 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005795 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005796 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005797 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5798 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005799 @Override
5800 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005801 enforceModifyPermission();
5802
5803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005806 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005807 } finally {
5808 Binder.restoreCallingIdentity(identity);
5809 }
5810 }
5811
5812 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005813 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005814 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005815 */
5816 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5817 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818
5819 final long identity = Binder.clearCallingIdentity();
5820 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005822 // may happen if the device does not support IMS.
5823 return null;
5824 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005825 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 } finally {
5827 Binder.restoreCallingIdentity(identity);
5828 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005829 }
5830
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005831 /**
5832 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005833 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005834 */
5835 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837
5838 final long identity = Binder.clearCallingIdentity();
5839 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005840 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005841 // may happen if the device does not support IMS.
5842 return null;
5843 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005844 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005848 }
5849
Brad Ebinger884c07b2018-02-15 16:17:40 -08005850 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005851 * Sets the ImsService Package Name that Telephony will bind to.
5852 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005853 * @param slotIndex the slot ID that the ImsService should bind for.
5854 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005855 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005856 * @param featureTypes An integer array of feature types associated with a packageName.
5857 * @param packageName The name of the package that the current configuration will be replaced
5858 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005859 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005860 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005861 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5862 int[] featureTypes, String packageName) {
5863 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5864 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5866 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 final long identity = Binder.clearCallingIdentity();
5870 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005871 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005872 // may happen if the device does not support IMS.
5873 return false;
5874 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005875 Map<Integer, String> featureConfig = new HashMap<>();
5876 for (int featureType : featureTypes) {
5877 featureConfig.put(featureType, packageName);
5878 }
5879 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5880 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005884 }
5885
5886 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005887 * Clears any carrier ImsService overrides for the slot index specified that were previously
5888 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5889 *
5890 * This should only be used for testing.
5891 *
5892 * @param slotIndex the slot ID that the ImsService should bind for.
5893 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5894 */
5895 @Override
5896 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5897 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5899 "clearCarrierImsServiceOverride");
5900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5901 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5902 "clearCarrierImsServiceOverride");
5903
5904 final long identity = Binder.clearCallingIdentity();
5905 try {
5906 if (mImsResolver == null) {
5907 // may happen if the device does not support IMS.
5908 return false;
5909 }
5910 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
5914 }
5915
5916 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005917 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005918 *
5919 * @param slotId The slot that the ImsService is associated with.
5920 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5921 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005922 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005923 * @return the package name of the ImsService configuration.
5924 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005925 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5926 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005927 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005928 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005929 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5931 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 final long identity = Binder.clearCallingIdentity();
5934 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005935 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005936 // may happen if the device does not support IMS.
5937 return "";
5938 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005939 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005940 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5941 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005945 }
5946
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005947 /**
5948 * Get the MmTelFeature state associated with the requested subscription id.
5949 * @param subId The subscription that the MmTelFeature is associated with.
5950 * @param callback A callback with an integer containing the
5951 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5952 */
5953 @Override
5954 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5955 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5956 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5957 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5958 "IMS not available on device.");
5959 }
5960 final long token = Binder.clearCallingIdentity();
5961 try {
5962 int slotId = getSlotIndex(subId);
5963 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5964 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5965 + subId + "'");
5966 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5967 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005968 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005969 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5970 try {
5971 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5972 } catch (RemoteException e) {
5973 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5974 + "Ignore");
5975 }
5976 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005977 } catch (ImsException e) {
5978 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005979 } finally {
5980 Binder.restoreCallingIdentity(token);
5981 }
5982 }
5983
Daniel Brightbb5840b2021-01-12 15:48:18 -08005984 /**
5985 * Sets the ims registration state on all valid {@link Phone}s.
5986 */
5987 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005988 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989
5990 final long identity = Binder.clearCallingIdentity();
5991 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005992 // NOTE: Before S, this method only set the default phone.
5993 for (final Phone phone : PhoneFactory.getPhones()) {
5994 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5995 phone.setImsRegistrationState(registered);
5996 }
5997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 } finally {
5999 Binder.restoreCallingIdentity(identity);
6000 }
Wink Saville36469e72014-06-11 15:17:00 -07006001 }
6002
6003 /**
Stuart Scott54788802015-03-30 13:18:01 -07006004 * Set the network selection mode to automatic.
6005 *
6006 */
6007 @Override
6008 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6010 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011
6012 final long identity = Binder.clearCallingIdentity();
6013 try {
shilufc958392020-01-20 11:36:01 -08006014 if (!isActiveSubscription(subId)) {
6015 return;
6016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006018 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6019 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 } finally {
6021 Binder.restoreCallingIdentity(identity);
6022 }
Stuart Scott54788802015-03-30 13:18:01 -07006023 }
6024
Jack Yud10cdd42020-09-28 20:28:01 -07006025 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006026 * Ask the radio to connect to the input network and change selection mode to manual.
6027 *
6028 * @param subId the id of the subscription.
6029 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6030 * the operator to attach to.
6031 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6032 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6033 * normal network selection next time.
6034 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006035 */
6036 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006037 public boolean setNetworkSelectionModeManual(
6038 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6040 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006041
6042 if (!isActiveSubscription(subId)) {
6043 return false;
6044 }
6045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046 final long identity = Binder.clearCallingIdentity();
6047 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006048 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006050 if (DBG) {
6051 log("setNetworkSelectionModeManual: subId: " + subId
6052 + " operator: " + operatorInfo);
6053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6055 } finally {
6056 Binder.restoreCallingIdentity(identity);
6057 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006058 }
shilu84f6e8b2019-12-19 13:58:01 -08006059 /**
6060 * Get the manual network selection
6061 *
6062 * @param subId the id of the subscription.
6063 *
6064 * @return the previously saved user selected PLMN
6065 */
6066 @Override
6067 public String getManualNetworkSelectionPlmn(int subId) {
6068 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006069 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006070 mApp, subId, "getManualNetworkSelectionPlmn");
6071
6072 final long identity = Binder.clearCallingIdentity();
6073 try {
6074 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006075 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006076 }
6077
6078 final Phone phone = getPhone(subId);
6079 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006080 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006081 }
6082 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6083 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6084 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6085 } finally {
6086 Binder.restoreCallingIdentity(identity);
6087 }
6088 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006089
6090 /**
6091 * Scans for available networks.
6092 */
6093 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006094 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6095 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6097 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006098 LocationAccessPolicy.LocationPermissionResult locationResult =
6099 LocationAccessPolicy.checkLocationPermission(mApp,
6100 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6101 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006102 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006103 .setCallingPid(Binder.getCallingPid())
6104 .setCallingUid(Binder.getCallingUid())
6105 .setMethod("getCellNetworkScanResults")
6106 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006107 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6108 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006109 .build());
6110 switch (locationResult) {
6111 case DENIED_HARD:
6112 throw new SecurityException("Not allowed to access scan results -- location");
6113 case DENIED_SOFT:
6114 return null;
6115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116
Pengquan Menga1bb6272018-09-06 09:59:22 -07006117 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 try {
6119 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006120 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 } finally {
6123 Binder.restoreCallingIdentity(identity);
6124 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006125 }
6126
6127 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006128 * Get the call forwarding info, given the call forwarding reason.
6129 */
6130 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006131 public void getCallForwarding(int subId, int callForwardingReason,
6132 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006133 enforceReadPrivilegedPermission("getCallForwarding");
6134 long identity = Binder.clearCallingIdentity();
6135 try {
6136 if (DBG) {
6137 log("getCallForwarding: subId " + subId
6138 + " callForwardingReason" + callForwardingReason);
6139 }
Hall Liu27d24262020-09-18 19:04:59 -07006140
6141 Phone phone = getPhone(subId);
6142 if (phone == null) {
6143 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006144 callback.onError(
6145 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006146 } catch (RemoteException e) {
6147 // ignore
6148 }
6149 return;
6150 }
6151
6152 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6153 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6154 @Override
6155 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6156 try {
6157 callback.onCallForwardingInfoAvailable(info);
6158 } catch (RemoteException e) {
6159 // ignore
6160 }
6161 }
6162
6163 @Override
6164 public void onError(int error) {
6165 try {
6166 callback.onError(error);
6167 } catch (RemoteException e) {
6168 // ignore
6169 }
6170 }
6171 });
6172 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006173 } finally {
6174 Binder.restoreCallingIdentity(identity);
6175 }
6176 }
6177
6178 /**
6179 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6180 * reason, the number to forward, and the timeout before the forwarding is attempted.
6181 */
6182 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006183 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6184 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006185 enforceModifyPermission();
6186 long identity = Binder.clearCallingIdentity();
6187 try {
6188 if (DBG) {
6189 log("setCallForwarding: subId " + subId
6190 + " callForwardingInfo" + callForwardingInfo);
6191 }
Hall Liu27d24262020-09-18 19:04:59 -07006192
6193 Phone phone = getPhone(subId);
6194 if (phone == null) {
6195 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006196 callback.accept(
6197 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006198 } catch (RemoteException e) {
6199 // ignore
6200 }
6201 return;
6202 }
6203
6204 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6205 FunctionalUtils.ignoreRemoteException(callback::accept));
6206
6207 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006208 } finally {
6209 Binder.restoreCallingIdentity(identity);
6210 }
6211 }
6212
6213 /**
Hall Liu27d24262020-09-18 19:04:59 -07006214 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006215 */
6216 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006217 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006218 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006219 long identity = Binder.clearCallingIdentity();
6220 try {
Hall Liu27d24262020-09-18 19:04:59 -07006221 Phone phone = getPhone(subId);
6222 if (phone == null) {
6223 try {
6224 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6225 } catch (RemoteException e) {
6226 // ignore
6227 }
6228 return;
6229 }
SongFerngWang0e767992021-03-31 22:08:45 +08006230 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6231 PersistableBundle c = configManager.getConfigForSubId(subId);
6232 boolean requireUssd = c.getBoolean(
6233 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006234
Shuo Qian4a594052020-01-23 11:59:30 -08006235 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006236 if (requireUssd) {
6237 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6238 getSubscriptionCarrierId(subId));
6239 String newUssdCommand = "";
6240 try {
6241 newUssdCommand = carrierXmlParser.getFeature(
6242 CarrierXmlParser.FEATURE_CALL_WAITING)
6243 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6244 } catch (NullPointerException e) {
6245 loge("Failed to generate USSD number" + e);
6246 }
6247 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6248 mMainThreadHandler, callback, carrierXmlParser,
6249 CarrierXmlParser.SsEntry.SSAction.QUERY);
6250 final String ussdCommand = newUssdCommand;
6251 Executors.newSingleThreadExecutor().execute(() -> {
6252 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6253 });
6254 } else {
6255 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6256 callback::accept);
6257 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6258 }
Shuo Qian4a594052020-01-23 11:59:30 -08006259 } finally {
6260 Binder.restoreCallingIdentity(identity);
6261 }
6262 }
6263
6264 /**
Hall Liu27d24262020-09-18 19:04:59 -07006265 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006266 */
6267 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006268 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006269 enforceModifyPermission();
6270 long identity = Binder.clearCallingIdentity();
6271 try {
Hall Liu27d24262020-09-18 19:04:59 -07006272 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6273
6274 Phone phone = getPhone(subId);
6275 if (phone == null) {
6276 try {
6277 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6278 } catch (RemoteException e) {
6279 // ignore
6280 }
6281 return;
6282 }
6283
SongFerngWang0e767992021-03-31 22:08:45 +08006284 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6285 PersistableBundle c = configManager.getConfigForSubId(subId);
6286 boolean requireUssd = c.getBoolean(
6287 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006288
SongFerngWang0e767992021-03-31 22:08:45 +08006289 if (DBG) log("getCallWaitingStatus: subId " + subId);
6290 if (requireUssd) {
6291 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6292 getSubscriptionCarrierId(subId));
6293 CarrierXmlParser.SsEntry.SSAction ssAction =
6294 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6295 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6296 String newUssdCommand = "";
6297 try {
6298 newUssdCommand = carrierXmlParser.getFeature(
6299 CarrierXmlParser.FEATURE_CALL_WAITING)
6300 .makeCommand(ssAction, null);
6301 } catch (NullPointerException e) {
6302 loge("Failed to generate USSD number" + e);
6303 }
6304 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6305 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6306 final String ussdCommand = newUssdCommand;
6307 Executors.newSingleThreadExecutor().execute(() -> {
6308 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6309 });
6310 } else {
6311 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6312 FunctionalUtils.ignoreRemoteException(callback::accept));
6313
6314 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6315 }
Shuo Qian4a594052020-01-23 11:59:30 -08006316 } finally {
6317 Binder.restoreCallingIdentity(identity);
6318 }
6319 }
6320
6321 /**
yinxub1bed742017-04-17 11:45:04 -07006322 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006323 *
yinxub1bed742017-04-17 11:45:04 -07006324 * @param subId id of the subscription
6325 * @param request contains the radio access networks with bands/channels to scan
6326 * @param messenger callback messenger for scan results or errors
6327 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006328 * @return the id of the requested scan which can be used to stop the scan.
6329 */
6330 @Override
6331 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006332 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6334 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006335 LocationAccessPolicy.LocationPermissionResult locationResult =
6336 LocationAccessPolicy.checkLocationPermission(mApp,
6337 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6338 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006339 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006340 .setCallingPid(Binder.getCallingPid())
6341 .setCallingUid(Binder.getCallingUid())
6342 .setMethod("requestNetworkScan")
6343 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006344 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6345 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006346 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006347 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006348 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6349 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006350 if (e != null) {
6351 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6352 throw e;
6353 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006354 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006355 return TelephonyScanManager.INVALID_SCAN_ID;
6356 }
6357 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 }
Hall Liu912dfd32019-04-25 14:02:26 -07006359 int callingUid = Binder.getCallingUid();
6360 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006361 final long identity = Binder.clearCallingIdentity();
6362 try {
6363 return mNetworkScanRequestTracker.startNetworkScan(
6364 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006365 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006366 } finally {
6367 Binder.restoreCallingIdentity(identity);
6368 }
yinxu504e1392017-04-12 16:03:22 -07006369 }
6370
Hall Liub2ac8ef2019-02-28 15:56:23 -08006371 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006372 NetworkScanRequest request, int subId, String callingPackage) {
6373 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006374 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6375 boolean hasNetworkScanPermission =
6376 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6377 == PERMISSION_GRANTED;
6378
6379 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6380 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6381 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006382 }
6383
6384 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6385 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006386 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6387 return new SecurityException("Specific channels must not be"
6388 + " scanned without location access.");
6389 }
6390 }
6391 }
6392
Hall Liub2ac8ef2019-02-28 15:56:23 -08006393 return null;
6394 }
6395
yinxu504e1392017-04-12 16:03:22 -07006396 /**
6397 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006398 *
6399 * @param subId id of the subscription
6400 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006401 */
6402 @Override
6403 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6405 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406
Hall Liu912dfd32019-04-25 14:02:26 -07006407 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408 final long identity = Binder.clearCallingIdentity();
6409 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006410 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
yinxu504e1392017-04-12 16:03:22 -07006414 }
6415
6416 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006417 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006418 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006419 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006420 */
6421 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006422 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006423 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006424 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006425 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426
6427 final long identity = Binder.clearCallingIdentity();
6428 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006429 if (DBG) log("getAllowedNetworkTypesBitmask");
6430 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6431 int networkTypesBitmask = (result != null ? result[0] : -1);
6432 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6433 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006437 }
6438
6439 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006440 * Get the allowed network types for certain reason.
6441 *
6442 * @param subId the id of the subscription.
6443 * @param reason the reason the allowed network type change is taking place
6444 * @return the allowed network types.
6445 */
6446 @Override
6447 public long getAllowedNetworkTypesForReason(int subId,
6448 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006449 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006450 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006451 final long identity = Binder.clearCallingIdentity();
6452 try {
6453 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
6456 }
6457 }
6458
6459 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006460 * Enable/Disable E-UTRA-NR Dual Connectivity
6461 * @param subId subscription id of the sim card
6462 * @param nrDualConnectivityState expected NR dual connectivity state
6463 * This can be passed following states
6464 * <ol>
6465 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6466 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6467 * <li>Disable NR dual connectivity and force secondary cell to be released
6468 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6469 * </ol>
6470 * @return operation result.
6471 */
6472 @Override
6473 public int setNrDualConnectivityState(int subId,
6474 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6476 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006477 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006478 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6479 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6480 }
6481
Sooraj Sasindran37444802020-08-11 10:40:43 -07006482 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6483 final long identity = Binder.clearCallingIdentity();
6484 try {
6485 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6486 nrDualConnectivityState, subId,
6487 workSource);
6488 if (DBG) log("enableNRDualConnectivity result: " + result);
6489 return result;
6490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
6493 }
6494
6495 /**
6496 * Is E-UTRA-NR Dual Connectivity enabled
6497 * @return true if dual connectivity is enabled else false
6498 */
6499 @Override
6500 public boolean isNrDualConnectivityEnabled(int subId) {
6501 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006502 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006503 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006504 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006505 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6506 return false;
6507 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006508 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6509 final long identity = Binder.clearCallingIdentity();
6510 try {
6511 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6512 null, subId, workSource);
6513 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6514 return isEnabled;
6515 } finally {
6516 Binder.restoreCallingIdentity(identity);
6517 }
6518 }
6519
6520 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006521 * Set the allowed network types of the device and
6522 * provide the reason triggering the allowed network change.
6523 *
6524 * @param subId the id of the subscription.
6525 * @param reason the reason the allowed network type change is taking place
6526 * @param allowedNetworkTypes the allowed network types.
6527 * @return true on success; false on any failure.
6528 */
6529 @Override
6530 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006531 @TelephonyManager.AllowedNetworkTypesReason int reason,
6532 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6534 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006535 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006536 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6537 return false;
6538 }
6539 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6540 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 return false;
6542 }
6543
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006544 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6545 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6546
6547
6548 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6549 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6550 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006551 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006552
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006553 final long identity = Binder.clearCallingIdentity();
6554 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006555 Boolean success = (Boolean) sendRequest(
6556 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6557 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6558
6559 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6560 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006561 } finally {
6562 Binder.restoreCallingIdentity(identity);
6563 }
6564 }
6565
6566 /**
Miaoa84611c2019-03-15 09:21:10 +08006567 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006568 *
Miaoa84611c2019-03-15 09:21:10 +08006569 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006570 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006571 * @hide
6572 */
6573 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006574 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006577 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 try {
Miaoa84611c2019-03-15 09:21:10 +08006579 if (phone != null) {
6580 return phone.hasMatchedTetherApnSetting();
6581 } else {
6582 return false;
6583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 } finally {
6585 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006586 }
Junda Liu475951f2014-11-07 16:45:03 -08006587 }
6588
6589 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006590 * Enable or disable always reporting signal strength changes from radio.
6591 *
6592 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6593 */
6594 @Override
6595 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6596 enforceModifyPermission();
6597 enforceSystemCaller();
6598
6599 final long identity = Binder.clearCallingIdentity();
6600 final Phone phone = getPhone(subId);
6601 try {
6602 if (phone != null) {
6603 if (DBG) {
6604 log("setAlwaysReportSignalStrength: subId=" + subId
6605 + " isEnable=" + isEnable);
6606 }
6607 phone.setAlwaysReportSignalStrength(isEnable);
6608 } else {
6609 loge("setAlwaysReportSignalStrength: no phone found for subId="
6610 + subId);
6611 }
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
6615 }
6616
6617 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006618 * Get the user enabled state of Mobile Data.
6619 *
6620 * TODO: remove and use isUserDataEnabled.
6621 * This can't be removed now because some vendor codes
6622 * calls through ITelephony directly while they should
6623 * use TelephonyManager.
6624 *
6625 * @return true on enabled
6626 */
6627 @Override
6628 public boolean getDataEnabled(int subId) {
6629 return isUserDataEnabled(subId);
6630 }
6631
6632 /**
6633 * Get whether mobile data is enabled per user setting.
6634 *
6635 * There are other factors deciding whether mobile data is actually enabled, but they are
6636 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006637 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006638 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006639 *
6640 * @return {@code true} if data is enabled else {@code false}
6641 */
6642 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006643 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006644 try {
6645 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6646 null);
6647 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6649 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651
6652 final long identity = Binder.clearCallingIdentity();
6653 try {
6654 int phoneId = mSubscriptionController.getPhoneId(subId);
6655 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6656 Phone phone = PhoneFactory.getPhone(phoneId);
6657 if (phone != null) {
6658 boolean retVal = phone.isUserDataEnabled();
6659 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6660 return retVal;
6661 } else {
6662 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6663 return false;
6664 }
6665 } finally {
6666 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006667 }
6668 }
6669
6670 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006671 * Checks if the device is capable of mobile data by considering whether whether the
6672 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6673 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006674 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006675 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006676 */
6677 @Override
6678 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006679 try {
6680 try {
6681 mApp.enforceCallingOrSelfPermission(
6682 android.Manifest.permission.ACCESS_NETWORK_STATE,
6683 null);
6684 } catch (Exception e) {
6685 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6686 "isDataEnabled");
6687 }
6688 } catch (Exception e) {
6689 enforceReadPrivilegedPermission("isDataEnabled");
6690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006691
6692 final long identity = Binder.clearCallingIdentity();
6693 try {
6694 int phoneId = mSubscriptionController.getPhoneId(subId);
6695 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6696 Phone phone = PhoneFactory.getPhone(phoneId);
6697 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006698 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6700 return retVal;
6701 } else {
6702 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6703 return false;
6704 }
6705 } finally {
6706 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006707 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006708 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006709
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006710 /**
6711 * Check if data is enabled for a specific reason
6712 * @param subId Subscription index
6713 * @param reason the reason the data enable change is taking place
6714 * @return {@code true} if the overall data is enabled; {@code false} if not.
6715 */
6716 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006717 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006718 @TelephonyManager.DataEnabledReason int reason) {
6719 try {
6720 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6721 null);
6722 } catch (Exception e) {
6723 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006724 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006725 }
6726
6727
6728 final long identity = Binder.clearCallingIdentity();
6729 try {
6730 int phoneId = mSubscriptionController.getPhoneId(subId);
6731 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006732 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006733 + " reason=" + reason);
6734 }
6735 Phone phone = PhoneFactory.getPhone(phoneId);
6736 if (phone != null) {
6737 boolean retVal;
6738 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6739 retVal = phone.isUserDataEnabled();
6740 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006741 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006742 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006743 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006744 return retVal;
6745 } else {
6746 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006747 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006748 + subId + " retVal=false");
6749 }
6750 return false;
6751 }
6752 } finally {
6753 Binder.restoreCallingIdentity(identity);
6754 }
6755 }
6756
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006757 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006758 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006759 if (uid == Process.PHONE_UID) {
6760 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6761 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006762 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6763 }
6764
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006765 //load access rules from carrier configs, and check those as well: b/139133814
6766 SubscriptionController subController = SubscriptionController.getInstance();
6767 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6768 || subController == null) return privilegeFromSim;
6769
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006770 PackageManager pkgMgr = phone.getContext().getPackageManager();
6771 String[] packages = pkgMgr.getPackagesForUid(uid);
6772
6773 final long identity = Binder.clearCallingIdentity();
6774 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006775 int subId = phone.getSubId();
6776 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6777 // A test override is in place for the privileges for this subId, so don't try to
6778 // read the subscription privileges.
6779 return privilegeFromSim;
6780 }
6781 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006782 SubscriptionManager subManager = (SubscriptionManager)
6783 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6784 for (String pkg : packages) {
6785 if (subManager.canManageSubscription(subInfo, pkg)) {
6786 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6787 }
6788 }
6789 return privilegeFromSim;
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
6793 }
6794
6795 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6796 String pkgName) {
6797 //load access rules from carrier configs, and check those as well: b/139133814
6798 SubscriptionController subController = SubscriptionController.getInstance();
6799 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6800 || subController == null) return privilegeFromSim;
6801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006804 int subId = phone.getSubId();
6805 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6806 // A test override is in place for the privileges for this subId, so don't try to
6807 // read the subscription privileges.
6808 return privilegeFromSim;
6809 }
6810 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006811 SubscriptionManager subManager = (SubscriptionManager)
6812 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6813 return subManager.canManageSubscription(subInfo, pkgName)
6814 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6815 } finally {
6816 Binder.restoreCallingIdentity(identity);
6817 }
6818 }
6819
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006820 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006821 public int getCarrierPrivilegeStatus(int subId) {
6822 final Phone phone = getPhone(subId);
6823 if (phone == null) {
6824 loge("getCarrierPrivilegeStatus: Invalid subId");
6825 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6826 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006827 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6828 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006829 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006830 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6831 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006832
6833 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006834 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006835 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006836 }
Junda Liu29340342014-07-10 15:23:27 -07006837
6838 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006839 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006840 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006841 final Phone phone = getPhone(subId);
6842 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006843 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006844 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6845 }
6846 UiccProfile profile =
6847 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6848 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006849 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6851 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006852 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006853 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006854 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006855 }
6856
6857 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006858 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006859 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006860 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006861 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006862 }
6863
6864 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006865 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6866 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006867 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006868 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6869 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006870 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006871 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006872 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006873 }
6874
6875 @Override
6876 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006877 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006878 if (TextUtils.isEmpty(pkgName))
6879 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006880 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6881 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006882 UiccPort port = UiccController.getInstance().getUiccPort(i);
6883 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006884 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006885 continue;
6886 }
6887
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006888 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006889 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006890 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006891 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6892 break;
6893 }
6894 }
6895
6896 return result;
Junda Liu29340342014-07-10 15:23:27 -07006897 }
Derek Tan89e89d42014-07-08 17:00:10 -07006898
6899 @Override
Junda Liue64de782015-04-16 17:19:16 -07006900 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006901 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006902 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6903 loge("phoneId " + phoneId + " is not valid.");
6904 return null;
6905 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006906 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6907 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006908 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006909 return null ;
6910 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006911 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006912 }
6913
Amith Yamasani6e118872016-02-19 12:53:51 -08006914 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006915 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006916 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006917 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006918 List<String> privilegedPackages = new ArrayList<>();
6919 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006920 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006921 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006922 if (port != null) {
6923 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006924 if (packages == null) {
6925 // Only check packages in user 0 for now
6926 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006927 PackageManager.MATCH_DISABLED_COMPONENTS
6928 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006929 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006930 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006931 }
6932 for (int p = packages.size() - 1; p >= 0; p--) {
6933 PackageInfo pkgInfo = packages.get(p);
6934 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006935 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6936 port.getCarrierPrivilegeStatus(pkgInfo),
6937 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006938 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006939 privilegedPackages.add(pkgInfo.packageName);
6940 }
6941 }
6942 }
6943 }
6944 return privilegedPackages;
6945 }
6946
chen xuf7e9fe82019-05-09 19:31:02 -07006947 @Override
6948 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006949 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6950
6951 final long identity = Binder.clearCallingIdentity();
6952
chen xuf7e9fe82019-05-09 19:31:02 -07006953 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006954 try {
6955 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6956 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6957 }
6958 } finally {
6959 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006960 }
6961 return privilegedPackages;
6962 }
6963
Wink Savilleb564aae2014-10-23 10:18:09 -07006964 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006965 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006966 UiccPort port = phone == null ? null : phone.getUiccPort();
6967 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006968 return null;
6969 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006970 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006971 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006972 return null;
6973 }
6974 return iccId;
6975 }
6976
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006977 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006978 public void setCallComposerStatus(int subId, int status) {
6979 enforceModifyPermission();
6980
6981 final long identity = Binder.clearCallingIdentity();
6982 try {
6983 Phone phone = getPhone(subId);
6984 if (phone != null) {
6985 Phone defaultPhone = phone.getImsPhone();
6986 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6987 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6988 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006989 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6990 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006991 }
6992 }
Shuo Qian284ae752020-12-22 19:10:14 -08006993 } catch (ImsException e) {
6994 throw new ServiceSpecificException(e.getCode());
6995 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006996 Binder.restoreCallingIdentity(identity);
6997 }
6998 }
6999
7000 @Override
7001 public int getCallComposerStatus(int subId) {
7002 enforceReadPrivilegedPermission("getCallComposerStatus");
7003
7004 final long identity = Binder.clearCallingIdentity();
7005 try {
7006 Phone phone = getPhone(subId);
7007 if (phone != null) {
7008 Phone defaultPhone = phone.getImsPhone();
7009 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7010 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7011 return imsPhone.getCallComposerStatus();
7012 }
7013 }
7014 } finally {
7015 Binder.restoreCallingIdentity(identity);
7016 }
7017 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7018 }
7019
7020 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007021 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7022 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007023 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007024 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 final String iccId = getIccId(subId);
7029 final Phone phone = getPhone(subId);
7030 if (phone == null) {
7031 return false;
7032 }
7033 final String subscriberId = phone.getSubscriberId();
7034
7035 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007036 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037 + subscriberId + " to " + number);
7038 }
7039
7040 if (TextUtils.isEmpty(iccId)) {
7041 return false;
7042 }
7043
7044 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7045
7046 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7047 if (alphaTag == null) {
7048 editor.remove(alphaTagPrefKey);
7049 } else {
7050 editor.putString(alphaTagPrefKey, alphaTag);
7051 }
7052
7053 // Record both the line number and IMSI for this ICCID, since we need to
7054 // track all merged IMSIs based on line number
7055 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7056 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7057 if (number == null) {
7058 editor.remove(numberPrefKey);
7059 editor.remove(subscriberPrefKey);
7060 } else {
7061 editor.putString(numberPrefKey, number);
7062 editor.putString(subscriberPrefKey, subscriberId);
7063 }
7064
7065 editor.commit();
7066 return true;
7067 } finally {
7068 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007069 }
Derek Tan7226c842014-07-02 17:42:23 -07007070 }
7071
7072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007073 public String getLine1NumberForDisplay(int subId, String callingPackage,
7074 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007075 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007077 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007078 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007079 return null;
7080 }
Derek Tan97ebb422014-09-05 16:55:38 -07007081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 final long identity = Binder.clearCallingIdentity();
7083 try {
7084 String iccId = getIccId(subId);
7085 if (iccId != null) {
7086 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7087 if (DBG_MERGE) {
7088 log("getLine1NumberForDisplay returning "
7089 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7090 }
7091 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007092 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7094 return null;
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007097 }
Derek Tan7226c842014-07-02 17:42:23 -07007098 }
7099
7100 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007101 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7102 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007104 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007105 return null;
7106 }
Derek Tan97ebb422014-09-05 16:55:38 -07007107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108 final long identity = Binder.clearCallingIdentity();
7109 try {
7110 String iccId = getIccId(subId);
7111 if (iccId != null) {
7112 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7113 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7114 }
7115 return null;
7116 } finally {
7117 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007118 }
Derek Tan7226c842014-07-02 17:42:23 -07007119 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007120
7121 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007122 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7123 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007124 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7125 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007126 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007127 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007128 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007129 return null;
7130 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007131
Jordan Liub49b04b2019-05-06 14:45:15 -07007132 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7133 // the process, where TelephonyManager was instantiated.
7134 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007135 final long identity = Binder.clearCallingIdentity();
7136 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007137 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 final TelephonyManager tele = TelephonyManager.from(context);
7139 final SubscriptionManager sub = SubscriptionManager.from(context);
7140
7141 // Figure out what subscribers are currently active
7142 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143
Jordan Liub49b04b2019-05-06 14:45:15 -07007144 // Only consider subs which match the current subId
7145 // This logic can be simplified. See b/131189269 for progress.
7146 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007147 activeSubscriberIds.add(tele.getSubscriberId(subId));
7148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149
7150 // First pass, find a number override for an active subscriber
7151 String mergeNumber = null;
7152 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7153 for (String key : prefs.keySet()) {
7154 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7155 final String subscriberId = (String) prefs.get(key);
7156 if (activeSubscriberIds.contains(subscriberId)) {
7157 final String iccId = key.substring(
7158 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7159 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7160 mergeNumber = (String) prefs.get(numberKey);
7161 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007162 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 + " for active subscriber " + subscriberId);
7164 }
7165 if (!TextUtils.isEmpty(mergeNumber)) {
7166 break;
7167 }
7168 }
7169 }
7170 }
7171
7172 // Shortcut when no active merged subscribers
7173 if (TextUtils.isEmpty(mergeNumber)) {
7174 return null;
7175 }
7176
7177 // Second pass, find all subscribers under that line override
7178 final ArraySet<String> result = new ArraySet<>();
7179 for (String key : prefs.keySet()) {
7180 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7181 final String number = (String) prefs.get(key);
7182 if (mergeNumber.equals(number)) {
7183 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7184 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7185 final String subscriberId = (String) prefs.get(subscriberKey);
7186 if (!TextUtils.isEmpty(subscriberId)) {
7187 result.add(subscriberId);
7188 }
7189 }
7190 }
7191 }
7192
7193 final String[] resultArray = result.toArray(new String[result.size()]);
7194 Arrays.sort(resultArray);
7195 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007196 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7198 }
7199 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007200 } finally {
7201 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007202 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007203 }
7204
7205 @Override
zoey chen38003472019-12-13 17:16:31 +08007206 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7207 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007208
7209 final long identity = Binder.clearCallingIdentity();
7210 try {
7211 final TelephonyManager telephonyManager = mApp.getSystemService(
7212 TelephonyManager.class);
7213 String subscriberId = telephonyManager.getSubscriberId(subId);
7214 if (subscriberId == null) {
7215 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007216 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007217 + subId);
7218 }
7219 return null;
7220 }
7221
7222 final SubscriptionInfo info = SubscriptionController.getInstance()
7223 .getSubscriptionInfo(subId);
7224 final ParcelUuid groupUuid = info.getGroupUuid();
7225 // If it doesn't belong to any group, return just subscriberId of itself.
7226 if (groupUuid == null) {
7227 return new String[]{subscriberId};
7228 }
7229
7230 // Get all subscriberIds from the group.
7231 final List<String> mergedSubscriberIds = new ArrayList<>();
7232 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007233 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007234 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007235 for (SubscriptionInfo subInfo : groupInfos) {
7236 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7237 if (subscriberId != null) {
7238 mergedSubscriberIds.add(subscriberId);
7239 }
7240 }
7241
7242 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7243 } finally {
7244 Binder.restoreCallingIdentity(identity);
7245
7246 }
7247 }
7248
7249 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007250 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007251 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007252 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253
7254 final long identity = Binder.clearCallingIdentity();
7255 try {
7256 final Phone phone = getPhone(subId);
7257 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7258 } finally {
7259 Binder.restoreCallingIdentity(identity);
7260 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007261 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007262
7263 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007264 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007265 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7266 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007267 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7268 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269
7270 final long identity = Binder.clearCallingIdentity();
7271 try {
7272 final Phone phone = getPhone(subId);
7273 if (phone == null) {
7274 return false;
7275 }
7276 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7277 cdmaNonRoamingList);
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007280 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007281 }
7282
7283 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007284 @Deprecated
7285 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7286 enforceModifyPermission();
7287
7288 int returnValue = 0;
7289 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007290 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007291 if(result.exception == null) {
7292 if (result.result != null) {
7293 byte[] responseData = (byte[])(result.result);
7294 if(responseData.length > oemResp.length) {
7295 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7296 responseData.length + "bytes. Buffer Size is " +
7297 oemResp.length + "bytes.");
7298 }
7299 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7300 returnValue = responseData.length;
7301 }
7302 } else {
7303 CommandException ex = (CommandException) result.exception;
7304 returnValue = ex.getCommandError().ordinal();
7305 if(returnValue > 0) returnValue *= -1;
7306 }
7307 } catch (RuntimeException e) {
7308 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7309 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7310 if(returnValue > 0) returnValue *= -1;
7311 }
7312
7313 return returnValue;
7314 }
7315
7316 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007317 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007318 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007319 try {
7320 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007321 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007322 mApp, phone.getSubId(), "getRadioAccessFamily");
7323 } catch (SecurityException e) {
7324 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7325 throw e;
7326 }
chen xub97461a2018-10-26 14:17:57 -07007327 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007328 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007329 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007330 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007331 final long identity = Binder.clearCallingIdentity();
7332 try {
chen xub97461a2018-10-26 14:17:57 -07007333 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007334 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007335 mApp, phone.getSubId(), "getRadioAccessFamily");
7336 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
chen xub97461a2018-10-26 14:17:57 -07007340 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007341 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007342
7343 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007344 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007345 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007346 try {
7347 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7348 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007349 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007350 }
7351 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007352 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007353 }
7354 RoleManager rm = mApp.getSystemService(RoleManager.class);
7355 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7356 if (!dialerRoleHolders.contains(callingPackage)) {
7357 throw new SecurityException("App must be the dialer role holder to"
7358 + " upload a call composer pic");
7359 }
7360
7361 Executors.newSingleThreadExecutor().execute(() -> {
7362 ByteArrayOutputStream output = new ByteArrayOutputStream(
7363 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7364 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7365 boolean readUntilEnd = false;
7366 int totalBytesRead = 0;
7367 byte[] buffer = new byte[16 * 1024];
7368 while (true) {
7369 int numRead;
7370 try {
7371 numRead = input.read(buffer);
7372 } catch (IOException e) {
7373 try {
7374 fd.checkError();
7375 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7376 null);
7377 } catch (IOException e1) {
7378 // This means that the other side closed explicitly with an error. If this
7379 // happens, log and ignore.
7380 loge("Remote end of call composer picture pipe closed: " + e1);
7381 }
7382 break;
7383 }
7384 if (numRead == -1) {
7385 readUntilEnd = true;
7386 break;
7387 }
7388 totalBytesRead += numRead;
7389 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7390 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7391 try {
7392 input.close();
7393 } catch (IOException e) {
7394 // ignore
7395 }
7396 break;
7397 }
7398 output.write(buffer, 0, numRead);
7399 }
7400 // Generally, the remote end will close the file descriptors. The only case where we
7401 // close is above, where the picture size is too big.
7402
7403 try {
7404 fd.checkError();
7405 } catch (IOException e) {
7406 loge("Remote end for call composer closed with an error: " + e);
7407 return;
7408 }
7409
Hall Liuaa4211e2021-01-20 15:43:39 -08007410 if (!readUntilEnd) {
7411 loge("Did not finish reading entire image; aborting");
7412 return;
7413 }
Hall Liu82694d52020-12-11 18:22:04 -08007414
Hall Liuaa4211e2021-01-20 15:43:39 -08007415 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7416 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7417 new CallComposerPictureTransfer.Factory() {},
7418 imageData,
7419 (result) -> {
7420 if (result.first != null) {
7421 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7422 Bundle outputResult = new Bundle();
7423 outputResult.putParcelable(
7424 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7425 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7426 outputResult);
7427 } else {
7428 callback.send(result.second, null);
7429 }
7430 }
7431 );
Hall Liu82694d52020-12-11 18:22:04 -08007432 });
7433 }
7434
7435 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007436 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007437 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007438 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439
7440 final long identity = Binder.clearCallingIdentity();
7441 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007442 ImsManager.getInstance(defaultPhone.getContext(),
7443 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 } finally {
7445 Binder.restoreCallingIdentity(identity);
7446 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007447 }
7448
7449 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007450 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007451 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7453 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007454 return false;
7455 }
Svet Ganovb320e182015-04-16 12:30:10 -07007456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 final long identity = Binder.clearCallingIdentity();
7458 try {
7459 // Check the user preference and the system-level IMS setting. Even if the user has
7460 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7461 // In the long run, we may instead need to check if there exists a connection service
7462 // which can support video calling.
7463 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 return imsManager.isVtEnabledByPlatform()
7466 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7467 && imsManager.isVtEnabledByUser();
7468 } finally {
7469 Binder.restoreCallingIdentity(identity);
7470 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007471 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007472
Andrew Leea1239f22015-03-02 17:44:07 -08007473 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007474 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7475 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007477 mApp, subId, callingPackage, callingFeatureId,
7478 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 return false;
7480 }
7481
7482 final long identity = Binder.clearCallingIdentity();
7483 try {
7484 CarrierConfigManager configManager =
7485 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007486 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Andrew Leea1239f22015-03-02 17:44:07 -08007491 }
7492
7493 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007494 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007496 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 return false;
7498 }
7499
7500 final long identity = Binder.clearCallingIdentity();
7501 try {
7502 CarrierConfigManager configManager =
7503 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007504 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7506 } finally {
7507 Binder.restoreCallingIdentity(identity);
7508 }
Andrew Leea1239f22015-03-02 17:44:07 -08007509 }
7510
Andrew Lee9431b832015-03-09 18:46:45 -07007511 @Override
7512 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007513 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007514 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007515 }
7516
7517 @Override
7518 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519 final long identity = Binder.clearCallingIdentity();
7520 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007521 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 } finally {
7523 Binder.restoreCallingIdentity(identity);
7524 }
Andrew Lee9431b832015-03-09 18:46:45 -07007525 }
7526
Hall Liuf6668912018-10-31 17:05:23 -07007527 /**
7528 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7529 * support for the feature and device firmware support.
7530 *
7531 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7532 */
7533 @Override
7534 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007536 final Phone phone = getPhone(subscriptionId);
7537 if (phone == null) {
7538 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7539 return false;
7540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007542 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7544 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007545 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007546 return isCarrierSupported && isDeviceSupported;
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
Hall Liu98187582018-01-22 19:15:32 -08007550 }
7551
Hall Liuf6668912018-10-31 17:05:23 -07007552 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007553 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7554 * RTT setting, will return true if the device and carrier both support RTT.
7555 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007556 */
7557 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 final long identity = Binder.clearCallingIdentity();
7559 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007560 boolean isRttSupported = isRttSupported(subscriptionId);
7561 boolean isUserRttSettingOn = Settings.Secure.getInt(
7562 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7563 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7564 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7565 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 } finally {
7567 Binder.restoreCallingIdentity(identity);
7568 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007569 }
7570
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007571 @Deprecated
7572 @Override
7573 public String getDeviceId(String callingPackage) {
7574 return getDeviceIdWithFeature(callingPackage, null);
7575 }
7576
Sanket Padawe7310cc72015-01-14 09:53:20 -08007577 /**
7578 * Returns the unique device ID of phone, for example, the IMEI for
7579 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7580 *
7581 * <p>Requires Permission:
7582 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7583 */
7584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007585 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007586 try {
7587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7588 } catch (SecurityException se) {
7589 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7590 throw new SecurityException("Package " + callingPackage + " does not belong to "
7591 + Binder.getCallingUid());
7592 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007593 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007594 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007595 return null;
7596 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007597 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007598 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007599 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007600 return null;
7601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602
7603 final long identity = Binder.clearCallingIdentity();
7604 try {
7605 return phone.getDeviceId();
7606 } finally {
7607 Binder.restoreCallingIdentity(identity);
7608 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007609 }
7610
Ping Sunc67b7c22016-03-02 19:16:45 +08007611 /**
7612 * {@hide}
7613 * Returns the IMS Registration Status on a particular subid
7614 *
7615 * @param subId
7616 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007617 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007618 Phone phone = getPhone(subId);
7619 if (phone != null) {
7620 return phone.isImsRegistered();
7621 } else {
7622 return false;
7623 }
7624 }
7625
Santos Cordon7a1885b2015-02-03 11:15:19 -08007626 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007627 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007628 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007630 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007631 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7632 }
7633 final long identity = Binder.clearCallingIdentity();
7634 try {
7635 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7636 } finally {
7637 Binder.restoreCallingIdentity(identity);
7638 }
7639 }
7640
7641 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007642 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007643 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007644 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007645 mApp,
7646 subscriptionId,
7647 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 Phone phone = getPhone(subscriptionId);
7651 if (phone == null) {
7652 return null;
7653 }
7654 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
7657 }
7658 }
7659
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007660 /**
7661 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007662 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007663 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664 final long identity = Binder.clearCallingIdentity();
7665 try {
7666 Phone phone = getPhone(subId);
7667 if (phone != null) {
7668 return phone.isWifiCallingEnabled();
7669 } else {
7670 return false;
7671 }
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007674 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007675 }
7676
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007677 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007678 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007679 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007680 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681 final long identity = Binder.clearCallingIdentity();
7682 try {
7683 Phone phone = getPhone(subId);
7684 if (phone != null) {
7685 return phone.isVideoEnabled();
7686 } else {
7687 return false;
7688 }
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007691 }
7692 }
7693
7694 /**
7695 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7696 * defined in {@link ImsRegistrationImplBase}.
7697 */
7698 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 final long identity = Binder.clearCallingIdentity();
7700 try {
7701 Phone phone = getPhone(subId);
7702 if (phone != null) {
7703 return phone.getImsRegistrationTech();
7704 } else {
7705 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7706 }
7707 } finally {
7708 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007709 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007710 }
7711
Stuart Scott8eef64f2015-04-08 15:13:54 -07007712 @Override
7713 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007714 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007715 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7716 return;
7717 }
Kai Shif70f46f2021-03-03 13:59:46 -08007718 Phone defaultPhone = getDefaultPhone();
7719 if (defaultPhone != null) {
7720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7721 mApp, getDefaultPhone().getSubId(), "factoryReset");
7722 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007723 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007724
Svet Ganovcc087f82015-05-12 20:35:54 -07007725 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007726 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7727 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007728 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007729 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007730 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007731 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007732 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007733 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007734 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007735 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007736 // There has been issues when Sms raw table somehow stores orphan
7737 // fragments. They lead to garbled message when new fragments come
7738 // in and combined with those stale ones. In case this happens again,
7739 // user can reset all network settings which will clean up this table.
7740 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007741 // Clean up IMS settings as well here.
7742 int slotId = getSlotIndex(subId);
7743 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7744 ImsManager.getInstance(mApp, slotId).factoryReset();
7745 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007746
Kai Shif70f46f2021-03-03 13:59:46 -08007747 if (defaultPhone == null) {
7748 return;
7749 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007750 // Erase modem config if erase modem on network setting is enabled.
7751 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7752 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7753 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007754 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007755 }
Kai Shif70f46f2021-03-03 13:59:46 -08007756
7757 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007758 } finally {
7759 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007760 }
7761 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007762
SongFerngWangfd89b102021-05-27 22:44:54 +08007763 @VisibleForTesting
7764 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7765 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7766 return;
7767 }
7768 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7769 RILConstants.PREFERRED_NETWORK_MODE);
7770 SubscriptionManager.setSubscriptionProperty(subId,
7771 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7772 "user=" + defaultNetworkType);
7773 phone.loadAllowedNetworksFromSubscriptionDatabase();
7774 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7775 defaultNetworkType, null);
7776 }
7777
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007778 private void cleanUpSmsRawTable(Context context) {
7779 ContentResolver resolver = context.getContentResolver();
7780 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7781 resolver.delete(uri, null, null);
7782 }
7783
Narayan Kamath1c496c22015-04-16 14:40:19 +01007784 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007785 public String getSimLocaleForSubscriber(int subId) {
7786 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7787 final Phone phone = getPhone(subId);
7788 if (phone == null) {
7789 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007790 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 final long identity = Binder.clearCallingIdentity();
7793 try {
chen xu5d3637b2019-01-21 23:31:38 -08007794 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007795 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007796 if (info == null) {
7797 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7798 return null;
7799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 // Try and fetch the locale from the carrier properties or from the SIM language
7801 // preferences (EF-PL and EF-LI)...
7802 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007804 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7805 if (localeFromDefaultSim != null) {
7806 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7807 if (DBG) log("Using locale from subId: " + subId + " locale: "
7808 + localeFromDefaultSim);
7809 return localeFromDefaultSim.toLanguageTag();
7810 } else {
7811 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 }
7813 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 // The SIM language preferences only store a language (e.g. fr = French), not an
7816 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7817 // the SIM and carrier preferences does not include a country we add the country
7818 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007819 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007821 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 return mccLocale.toLanguageTag();
7823 }
7824
7825 if (DBG) log("No locale found - returning null");
7826 return null;
7827 } finally {
7828 Binder.restoreCallingIdentity(identity);
7829 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007830 }
7831
7832 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007833 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007834 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007835 }
7836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 /**
7838 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7839 */
7840 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007841 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007842 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007843 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007844
Chenjie Yu1ba97252018-01-11 18:16:20 -08007845 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007846 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007847
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007848 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007849 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7850 * representing the state of the modem.
7851 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007852 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7853 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007854 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007855 */
7856 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007857 public void requestModemActivityInfo(ResultReceiver result) {
7858 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007859 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007863 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 } finally {
7865 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007866 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007867 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007868
Siddharth Rayb8114062018-06-17 15:02:38 -07007869 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7870 // less than total activity duration.
7871 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7872 if (info == null) {
7873 return false;
7874 }
7875 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007876 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7877 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7878
Siddharth Rayb8114062018-06-17 15:02:38 -07007879 return (info.isValid()
7880 && (info.getSleepTimeMillis() <= activityDurationMs)
7881 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007882 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007883 && (totalTxTimeMs <= activityDurationMs));
7884 }
7885
Jack Yu85bd38a2015-11-09 11:34:32 -08007886 /**
7887 * {@hide}
7888 * Returns the service state information on specified subscription.
7889 */
7890 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007891 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7892 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007894 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007895 return null;
7896 }
7897
Hall Liuf19c44f2018-11-27 14:38:17 -08007898 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7899 LocationAccessPolicy.checkLocationPermission(mApp,
7900 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7901 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007902 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007903 .setCallingPid(Binder.getCallingPid())
7904 .setCallingUid(Binder.getCallingUid())
7905 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007906 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007907 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007908 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7909 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007910 .build());
7911
7912 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7913 LocationAccessPolicy.checkLocationPermission(mApp,
7914 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7915 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007916 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007917 .setCallingPid(Binder.getCallingPid())
7918 .setCallingUid(Binder.getCallingUid())
7919 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007920 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007921 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007922 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7923 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007924 .build());
7925 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7926 boolean hasFinePermission =
7927 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7928 boolean hasCoarsePermission =
7929 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7930
Jack Yu479f40e2020-10-27 21:29:25 -07007931 final Phone phone = getPhone(subId);
7932 if (phone == null) {
7933 return null;
7934 }
7935
Jordan Liu0f2bc442020-11-18 16:47:37 -08007936 final long identity = Binder.clearCallingIdentity();
7937
Jack Yu479f40e2020-10-27 21:29:25 -07007938 boolean isCallingPackageDataService = phone.getDataServicePackages()
7939 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007941 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7942 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7943 Rlog.d(LOG_TAG,
7944 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7945 return null;
7946 }
7947
Hall Liuf19c44f2018-11-27 14:38:17 -08007948 ServiceState ss = phone.getServiceState();
7949
7950 // Scrub out the location info in ServiceState depending on what level of access
7951 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007952 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007953 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7954 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 } finally {
7956 Binder.restoreCallingIdentity(identity);
7957 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007958 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007959
7960 /**
7961 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7962 *
7963 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7964 * voicemail ringtone.
7965 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7966 * PhoneAccount.
7967 */
7968 @Override
7969 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007970 final long identity = Binder.clearCallingIdentity();
7971 try {
7972 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7973 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007974 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7978 } finally {
7979 Binder.restoreCallingIdentity(identity);
7980 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007981 }
7982
7983 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007984 * Sets the per-account voicemail ringtone.
7985 *
7986 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7987 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7988 *
7989 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7990 * voicemail ringtone.
7991 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7992 * PhoneAccount.
7993 */
7994 @Override
7995 public void setVoicemailRingtoneUri(String callingPackage,
7996 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007997 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007999 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8000 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8002 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8003 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005
8006 final long identity = Binder.clearCallingIdentity();
8007 try {
8008 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8009 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008010 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 }
8012 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8013 } finally {
8014 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008015 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008016 }
8017
8018 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008019 * Returns whether vibration is set for voicemail notification in Phone settings.
8020 *
8021 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8022 * voicemail vibration setting.
8023 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8024 */
8025 @Override
8026 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008027 final long identity = Binder.clearCallingIdentity();
8028 try {
8029 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8030 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008031 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008034 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
8037 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008038 }
8039
Youhan Wange64578a2016-05-02 15:32:42 -07008040 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008041 * Sets the per-account voicemail vibration.
8042 *
8043 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8044 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8045 *
8046 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8047 * voicemail vibration setting.
8048 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8049 * specific PhoneAccount.
8050 */
8051 @Override
8052 public void setVoicemailVibrationEnabled(String callingPackage,
8053 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008054 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008055 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008056 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8057 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8059 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8060 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008061 }
8062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 final long identity = Binder.clearCallingIdentity();
8064 try {
8065 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8066 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008067 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008068 }
8069 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008072 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008073 }
8074
8075 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008076 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8077 *
8078 * @throws SecurityException if the caller does not have the required permission
8079 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008080 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008081 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008082 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008083 }
8084
8085 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008086 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8087 * permission.
8088 *
8089 * @throws SecurityException if the caller does not have the required permission
8090 */
8091 private void enforceSendSmsPermission() {
8092 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8093 }
8094
8095 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008096 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008097 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008098 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008099 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008100 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101 final long identity = Binder.clearCallingIdentity();
8102 try {
8103 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008104 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105 if (componentName == null) {
8106 throw new SecurityException(
8107 "Caller not current active visual voicemail package[null]");
8108 }
8109 String vvmPackage = componentName.getPackageName();
8110 if (!callingPackage.equals(vvmPackage)) {
8111 throw new SecurityException("Caller not current active visual voicemail package["
8112 + vvmPackage + "]");
8113 }
8114 } finally {
8115 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008116 }
8117 }
8118
8119 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008120 * Return the application ID for the app type.
8121 *
8122 * @param subId the subscription ID that this request applies to.
8123 * @param appType the uicc app type.
8124 * @return Application ID for specificied app type, or null if no uicc.
8125 */
8126 @Override
8127 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008128 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008129 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130
8131 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008132 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133 if (phone == null) {
8134 return null;
8135 }
8136 String aid = null;
8137 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008138 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 .getApplicationByType(appType).getAid();
8140 } catch (Exception e) {
8141 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8142 }
8143 return aid;
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008146 }
Youhan Wange64578a2016-05-02 15:32:42 -07008147 }
8148
Youhan Wang4001d252016-05-11 10:29:41 -07008149 /**
8150 * Return the Electronic Serial Number.
8151 *
8152 * @param subId the subscription ID that this request applies to.
8153 * @return ESN or null if error.
8154 */
8155 @Override
8156 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008157 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008158 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159
8160 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008161 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 if (phone == null) {
8163 return null;
8164 }
8165 String esn = null;
8166 try {
8167 esn = phone.getEsn();
8168 } catch (Exception e) {
8169 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8170 }
8171 return esn;
8172 } finally {
8173 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008174 }
Youhan Wang4001d252016-05-11 10:29:41 -07008175 }
8176
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008177 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008178 * Return the Preferred Roaming List Version.
8179 *
8180 * @param subId the subscription ID that this request applies to.
8181 * @return PRLVersion or null if error.
8182 */
8183 @Override
8184 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008185 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008186 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187
8188 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008189 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190 if (phone == null) {
8191 return null;
8192 }
8193 String cdmaPrlVersion = null;
8194 try {
8195 cdmaPrlVersion = phone.getCdmaPrlVersion();
8196 } catch (Exception e) {
8197 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8198 }
8199 return cdmaPrlVersion;
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008202 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008203 }
8204
8205 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008206 * Get snapshot of Telephony histograms
8207 * @return List of Telephony histograms
8208 * @hide
8209 */
8210 @Override
8211 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8213 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214
8215 final long identity = Binder.clearCallingIdentity();
8216 try {
8217 return RIL.getTelephonyRILTimingHistograms();
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
8220 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008221 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008222
8223 /**
8224 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008225 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8226 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008227 * Require system privileges. In the future we may add this to carrier APIs.
8228 *
Michele Berionne482f8202018-11-27 18:57:59 -08008229 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008230 */
8231 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008232 @TelephonyManager.SetCarrierRestrictionResult
8233 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008234 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008235 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008236
Michele Berionne482f8202018-11-27 18:57:59 -08008237 if (carrierRestrictionRules == null) {
8238 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008239 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 final long identity = Binder.clearCallingIdentity();
8242 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008243 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008244 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008248 }
8249
8250 /**
8251 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008252 * Get the allowed carrier list and the excluded carrier list, including the priority between
8253 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008254 * Require system privileges. In the future we may add this to carrier APIs.
8255 *
Michele Berionne482f8202018-11-27 18:57:59 -08008256 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008257 */
8258 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008259 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008260 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008261 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262
8263 final long identity = Binder.clearCallingIdentity();
8264 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008265 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8266 if (response instanceof CarrierRestrictionRules) {
8267 return (CarrierRestrictionRules) response;
8268 }
8269 // Response is an Exception of some kind,
8270 // which is signalled to the user as a NULL retval
8271 return null;
8272 } catch (Exception e) {
8273 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8274 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 } finally {
8276 Binder.restoreCallingIdentity(identity);
8277 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008278 }
8279
fionaxu59545b42016-05-25 15:53:37 -07008280 /**
fionaxu59545b42016-05-25 15:53:37 -07008281 * Action set from carrier signalling broadcast receivers to enable/disable radio
8282 * @param subId the subscription ID that this action applies to.
8283 * @param enabled control enable or disable radio.
8284 * {@hide}
8285 */
8286 @Override
8287 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8288 enforceModifyPermission();
8289 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008290
8291 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008292 if (phone == null) {
8293 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8294 return;
8295 }
8296 try {
8297 phone.carrierActionSetRadioEnabled(enabled);
8298 } catch (Exception e) {
8299 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 } finally {
8301 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008302 }
8303 }
8304
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008305 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008306 * Enable or disable Voice over NR (VoNR)
8307 * @param subId the subscription ID that this action applies to.
8308 * @param enabled enable or disable VoNR.
8309 * @return operation result.
8310 */
8311 @Override
8312 public int setVoNrEnabled(int subId, boolean enabled) {
8313 enforceModifyPermission();
8314 final Phone phone = getPhone(subId);
8315
8316 final long identity = Binder.clearCallingIdentity();
8317 if (phone == null) {
8318 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8319 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8320 }
8321
8322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8323 try {
8324 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8325 workSource);
8326 if (DBG) log("setVoNrEnabled result: " + result);
8327 return result;
8328 } finally {
8329 Binder.restoreCallingIdentity(identity);
8330 }
8331 }
8332
8333 /**
8334 * Is voice over NR enabled
8335 * @return true if VoNR is enabled else false
8336 */
8337 @Override
8338 public boolean isVoNrEnabled(int subId) {
8339 enforceReadPrivilegedPermission("isVoNrEnabled");
8340 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8341 final long identity = Binder.clearCallingIdentity();
8342 try {
8343 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8344 null, subId, workSource);
8345 if (DBG) log("isVoNrEnabled: " + isEnabled);
8346 return isEnabled;
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
8349 }
8350 }
8351
8352 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008353 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8354 * network status based on which carrier apps could apply actions accordingly,
8355 * enable/disable default url handler for example.
8356 *
8357 * @param subId the subscription ID that this action applies to.
8358 * @param report control start/stop reporting the default network status.
8359 * {@hide}
8360 */
8361 @Override
8362 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8363 enforceModifyPermission();
8364 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365
8366 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008367 if (phone == null) {
8368 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8369 return;
8370 }
8371 try {
8372 phone.carrierActionReportDefaultNetworkStatus(report);
8373 } catch (Exception e) {
8374 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375 } finally {
8376 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008377 }
8378 }
8379
8380 /**
fionaxud9622282017-07-17 17:51:30 -07008381 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8382 * @param subId the subscription ID that this action applies to.
8383 * {@hide}
8384 */
8385 @Override
8386 public void carrierActionResetAll(int subId) {
8387 enforceModifyPermission();
8388 final Phone phone = getPhone(subId);
8389 if (phone == null) {
8390 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8391 return;
8392 }
8393 try {
8394 phone.carrierActionResetAll();
8395 } catch (Exception e) {
8396 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8397 }
8398 }
8399
8400 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008401 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8402 * bug report is being generated.
8403 */
8404 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008405 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008406 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8407 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008408 writer.println("Permission Denial: can't dump Phone from pid="
8409 + Binder.getCallingPid()
8410 + ", uid=" + Binder.getCallingUid()
8411 + "without permission "
8412 + android.Manifest.permission.DUMP);
8413 return;
8414 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008415 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008416 }
Jack Yueb89b242016-06-22 13:27:47 -07008417
Brad Ebingerdac2f002018-04-03 15:17:52 -07008418 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008419 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8420 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8421 @NonNull String[] args) {
8422 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8423 this, in.getFileDescriptor(), out.getFileDescriptor(),
8424 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008425 }
8426
Jack Yueb89b242016-06-22 13:27:47 -07008427 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008428 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008429 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008430 * @param reason the reason the data enable change is taking place
8431 * @param enabled True if enabling the data, otherwise disabling.
8432 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008433 */
8434 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008435 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008436 boolean enabled) {
8437 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8438 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8439 try {
8440 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008441 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008442 } catch (SecurityException se) {
8443 enforceModifyPermission();
8444 }
8445 } else {
8446 enforceModifyPermission();
8447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008448
8449 final long identity = Binder.clearCallingIdentity();
8450 try {
8451 Phone phone = getPhone(subId);
8452 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008453 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8454 phone.carrierActionSetMeteredApnsEnabled(enabled);
8455 } else {
8456 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458 }
8459 } finally {
8460 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008461 }
8462 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008463
8464 /**
8465 * Get Client request stats
8466 * @return List of Client Request Stats
8467 * @hide
8468 */
8469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008470 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8471 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008473 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008474 return null;
8475 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008476 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 if (phone != null) {
8481 return phone.getClientRequestStats();
8482 }
8483
8484 return null;
8485 } finally {
8486 Binder.restoreCallingIdentity(identity);
8487 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008488 }
8489
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008490 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008491 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008492 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008493 }
Jack Yueb4124c2017-02-16 15:32:43 -08008494
8495 /**
Grace Chen70990072017-03-24 17:21:30 -07008496 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008497 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008498 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008499 * @param state State of SIM (power down, power up, pass through)
8500 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8501 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8502 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008503 *
8504 **/
8505 @Override
Grace Chen70990072017-03-24 17:21:30 -07008506 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008507 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008508 Phone phone = PhoneFactory.getPhone(slotIndex);
8509
vagdeviaf9a5b92018-08-15 16:01:53 -07008510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008512 final long identity = Binder.clearCallingIdentity();
8513 try {
8514 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008515 phone.setSimPowerState(state, null, workSource);
8516 }
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
8520 }
8521
8522 /**
8523 * Set SIM card power state.
8524 *
8525 * @param slotIndex SIM slot id.
8526 * @param state State of SIM (power down, power up, pass through)
8527 * @param callback callback to trigger after success or failure
8528 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8529 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8530 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8531 *
8532 **/
8533 @Override
8534 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8535 IIntegerConsumer callback) {
8536 enforceModifyPermission();
8537 Phone phone = PhoneFactory.getPhone(slotIndex);
8538
8539 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8540
8541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 if (phone != null) {
8544 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8545 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546 }
8547 } finally {
8548 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008549 }
8550 }
Shuo Qiandd210312017-04-12 22:11:33 +00008551
Tyler Gunn65d45c22017-06-05 11:22:26 -07008552 private boolean isUssdApiAllowed(int subId) {
8553 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008554 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008555 if (configManager == null) {
8556 return false;
8557 }
8558 PersistableBundle pb = configManager.getConfigForSubId(subId);
8559 if (pb == null) {
8560 return false;
8561 }
8562 return pb.getBoolean(
8563 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8564 }
8565
Shuo Qiandd210312017-04-12 22:11:33 +00008566 /**
8567 * Check if phone is in emergency callback mode
8568 * @return true if phone is in emergency callback mode
8569 * @param subId sub id
8570 */
goneil9c5f4872017-12-05 14:07:56 -08008571 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008572 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008573 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008574 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008575
8576 final long identity = Binder.clearCallingIdentity();
8577 try {
8578 if (phone != null) {
8579 return phone.isInEcm();
8580 } else {
8581 return false;
8582 }
8583 } finally {
8584 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008585 }
8586 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008587
8588 /**
8589 * Get the current signal strength information for the given subscription.
8590 * Because this information is not updated when the device is in a low power state
8591 * it should not be relied-upon to be current.
8592 * @param subId Subscription index
8593 * @return the most recent cached signal strength info from the modem
8594 */
8595 @Override
8596 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597 final long identity = Binder.clearCallingIdentity();
8598 try {
8599 Phone p = getPhone(subId);
8600 if (p == null) {
8601 return null;
8602 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008604 return p.getSignalStrength();
8605 } finally {
8606 Binder.restoreCallingIdentity(identity);
8607 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008608 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008609
Pengquan Meng77b7f132018-08-22 14:49:57 -07008610 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008611 * Get the current modem radio state for the given slot.
8612 * @param slotIndex slot index.
8613 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008614 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008615 * @return the current radio power state from the modem
8616 */
8617 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008618 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008619 Phone phone = PhoneFactory.getPhone(slotIndex);
8620 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8622 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008623 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8624 }
8625
8626 final long identity = Binder.clearCallingIdentity();
8627 try {
8628 return phone.getRadioPowerState();
8629 } finally {
8630 Binder.restoreCallingIdentity(identity);
8631 }
8632 }
8633 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8634 }
8635
8636 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008637 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8638 *
8639 * <p>Requires one of the following permissions:
8640 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8641 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8642 * privileges.
8643 *
8644 * @param subId subscription id
8645 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8646 * {@code false}.
8647 */
8648 @Override
8649 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008650 try {
8651 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8652 null);
8653 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008654 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008655 mApp, subId, "isDataRoamingEnabled");
8656 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008657
Pengquan Menga1bb6272018-09-06 09:59:22 -07008658 boolean isEnabled = false;
8659 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008660 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008661 Phone phone = getPhone(subId);
8662 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008663 } finally {
8664 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008665 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008666 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008667 }
8668
8669
8670 /**
8671 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8672 *
8673 * <p> Requires permission:
8674 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8675 * privileges.
8676 *
8677 * @param subId subscription id
8678 * @param isEnabled {@code true} means enable, {@code false} means disable.
8679 */
8680 @Override
8681 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8683 mApp, subId, "setDataRoamingEnabled");
8684
Pengquan Menga1bb6272018-09-06 09:59:22 -07008685 final long identity = Binder.clearCallingIdentity();
8686 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008687 Phone phone = getPhone(subId);
8688 if (phone != null) {
8689 phone.setDataRoamingEnabled(isEnabled);
8690 }
8691 } finally {
8692 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008693 }
8694 }
8695
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008696 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008697 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008698 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008699 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008700 mApp, subId, "isManualNetworkSelectionAllowed");
8701
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008702 boolean isAllowed = true;
8703 final long identity = Binder.clearCallingIdentity();
8704 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008705 Phone phone = getPhone(subId);
8706 if (phone != null) {
8707 isAllowed = phone.isCspPlmnEnabled();
8708 }
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
8711 }
8712 return isAllowed;
8713 }
8714
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008715 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8716 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8717 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8718 // Update each UiccPort object based on privilege access
8719 UiccPort[] uiccPorts = card.getUiccPortList();
8720 for (UiccPort port : uiccPorts) {
8721 UiccProfile profile = port.getUiccProfile();
8722 if (profile == null ||
8723 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8724 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8725 return false;
8726 }
8727 }
8728 return true;
8729 }
8730
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008731 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008732 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008733 // Verify that tha callingPackage belongs to the calling UID
8734 mApp.getSystemService(AppOpsManager.class)
8735 .checkPackage(Binder.getCallingUid(), callingPackage);
8736
Jordan Liu1e142fc2019-04-22 15:10:43 -07008737 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008738 try {
8739 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008740 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008741 } catch (SecurityException e) {
8742 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8743 // has carrier privileges on an active UICC
8744 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8745 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008746 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008747 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008748 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008749
8750 final long identity = Binder.clearCallingIdentity();
8751 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008752 UiccController uiccController = UiccController.getInstance();
8753 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008754 if (hasReadPermission) {
8755 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008756 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008757
8758 // Remove private info if the caller doesn't have access
8759 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8760 for (UiccCardInfo cardInfo : cardInfos) {
8761 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8762 // is available
8763 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008764 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8765 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8766 if (card == null || card.getUiccPortList().length == 0) {
8767 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008768 filteredInfos.add(cardInfo.getUnprivileged());
8769 continue;
8770 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008771
8772 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008773 filteredInfos.add(cardInfo);
8774 } else {
8775 filteredInfos.add(cardInfo.getUnprivileged());
8776 }
8777 }
8778 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008779 } finally {
8780 Binder.restoreCallingIdentity(identity);
8781 }
8782 }
8783
8784 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008785 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008786 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008788 final long identity = Binder.clearCallingIdentity();
8789 try {
8790 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8791 if (slots == null) {
8792 Rlog.i(LOG_TAG, "slots is null.");
8793 return null;
8794 }
8795
8796 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8797 for (int i = 0; i < slots.length; i++) {
8798 UiccSlot slot = slots[i];
8799 if (slot == null) {
8800 continue;
8801 }
8802
Jordan Liu7be7e652019-05-06 18:55:02 +00008803 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008804 UiccCard card = slot.getUiccCard();
8805 if (card != null) {
8806 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008807 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008808 cardId = slot.getEid();
8809 if (TextUtils.isEmpty(cardId)) {
8810 cardId = slot.getIccId();
8811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008812 }
8813
Jordan Liu857451f2019-05-09 16:35:35 -07008814 if (cardId != null) {
8815 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8816 // if cardId is an EID, it's all digits so this is fine
8817 cardId = IccUtils.stripTrailingFs(cardId);
8818 }
8819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008820 int cardState = 0;
8821 switch (slot.getCardState()) {
8822 case CARDSTATE_ABSENT:
8823 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8824 break;
8825 case CARDSTATE_PRESENT:
8826 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8827 break;
8828 case CARDSTATE_ERROR:
8829 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8830 break;
8831 case CARDSTATE_RESTRICTED:
8832 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8833 break;
8834 default:
8835 break;
8836
8837 }
8838
8839 infos[i] = new UiccSlotInfo(
8840 slot.isActive(),
8841 slot.isEuicc(),
8842 cardId,
8843 cardState,
8844 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008845 slot.isExtendedApduSupported(),
8846 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008847 }
8848 return infos;
8849 } finally {
8850 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008851 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008852 }
8853
8854 @Override
8855 public boolean switchSlots(int[] physicalSlots) {
8856 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008857
8858 final long identity = Binder.clearCallingIdentity();
8859 try {
8860 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8861 } finally {
8862 Binder.restoreCallingIdentity(identity);
8863 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008864 }
Jack Yu4c988042018-02-27 15:30:01 -08008865
8866 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008867 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008868 final long identity = Binder.clearCallingIdentity();
8869 try {
8870 return UiccController.getInstance().getCardIdForDefaultEuicc();
8871 } finally {
8872 Binder.restoreCallingIdentity(identity);
8873 }
8874 }
8875
Pengquan Meng85728fb2018-03-12 16:31:21 -07008876 /**
goneil47ffb6e2018-04-06 15:40:58 -07008877 * A test API to reload the UICC profile.
8878 *
8879 * <p>Requires that the calling app has permission
8880 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8881 * @hide
8882 */
8883 @Override
8884 public void refreshUiccProfile(int subId) {
8885 enforceModifyPermission();
8886
8887 final long identity = Binder.clearCallingIdentity();
8888 try {
8889 Phone phone = getPhone(subId);
8890 if (phone == null) {
8891 return;
8892 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008893 UiccPort uiccPort = phone.getUiccPort();
8894 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008895 return;
8896 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008897 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008898 if (uiccProfile == null) {
8899 return;
8900 }
8901 uiccProfile.refresh();
8902 } finally {
8903 Binder.restoreCallingIdentity(identity);
8904 }
8905 }
8906
8907 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008908 * Returns false if the mobile data is disabled by default, otherwise return true.
8909 */
8910 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008911 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008912 }
8913
8914 /**
8915 * Returns true if the data roaming is enabled by default, i.e the system property
8916 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8917 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8918 */
8919 private boolean getDefaultDataRoamingEnabled(int subId) {
8920 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008921 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008922 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008923 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8924 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8925 return isDataRoamingEnabled;
8926 }
8927
8928 /**
8929 * Returns the default network type for the given {@code subId}, if the default network type is
8930 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8931 */
8932 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008933 List<Integer> list = TelephonyProperties.default_network();
8934 int phoneId = mSubscriptionController.getPhoneId(subId);
8935 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8936 return list.get(phoneId);
8937 }
8938 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008939 }
fionaxua13278b2018-03-21 00:08:13 -07008940
8941 @Override
8942 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008943 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945
8946 final long identity = Binder.clearCallingIdentity();
8947 try {
8948 final Phone phone = getPhone(subId);
8949 if (phone == null) {
8950 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8951 return;
8952 }
chen xueaba88a2019-03-15 13:15:10 -07008953 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8954 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008955 if (carrierPrivilegeRules == null) {
8956 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8957 } else {
8958 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008960 } finally {
8961 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008962 }
fionaxua13278b2018-03-21 00:08:13 -07008963 }
8964
8965 @Override
8966 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008967 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008968
8969 final long identity = Binder.clearCallingIdentity();
8970 try {
8971 final Phone phone = getPhone(subId);
8972 if (phone == null) {
8973 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8974 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8975 }
8976 return phone.getCarrierIdListVersion();
8977 } finally {
8978 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008979 }
fionaxua13278b2018-03-21 00:08:13 -07008980 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008981
8982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008983 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8984 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008986 mApp, subId, callingPackage, callingFeatureId,
8987 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008988 return -1;
8989 }
8990
8991 final long identity = Binder.clearCallingIdentity();
8992 try {
8993 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008998
8999 @Override
9000 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009001 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009002 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009003 mApp, subId, "getCdmaRoamingMode");
9004
9005 final long identity = Binder.clearCallingIdentity();
9006 try {
9007 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9008 } finally {
9009 Binder.restoreCallingIdentity(identity);
9010 }
9011 }
9012
9013 @Override
9014 public boolean setCdmaRoamingMode(int subId, int mode) {
9015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9016 mApp, subId, "setCdmaRoamingMode");
9017
9018 final long identity = Binder.clearCallingIdentity();
9019 try {
9020 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 }
9025
9026 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009027 public int getCdmaSubscriptionMode(int subId) {
9028 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009029 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009030 mApp, subId, "getCdmaSubscriptionMode");
9031
9032 final long identity = Binder.clearCallingIdentity();
9033 try {
9034 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9035 } finally {
9036 Binder.restoreCallingIdentity(identity);
9037 }
9038 }
9039
9040 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009041 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9043 mApp, subId, "setCdmaSubscriptionMode");
9044
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
9051 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009052
sqianc5eccab2018-10-19 18:46:41 -07009053 @Override
sqian8c685422019-02-22 15:55:18 -08009054 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009055 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009057 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9058 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009059 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9060 }
9061 final long identity = Binder.clearCallingIdentity();
9062 try {
sqian854d44b2018-12-12 16:48:18 -08009063 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9064 for (Phone phone: PhoneFactory.getPhones()) {
9065 if (phone.getEmergencyNumberTracker() != null
9066 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9067 emergencyNumberListInternal.put(
9068 phone.getSubId(),
9069 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9070 }
sqian11b7a0e2018-12-05 18:48:28 -08009071 }
sqian854d44b2018-12-12 16:48:18 -08009072 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009073 } finally {
9074 Binder.restoreCallingIdentity(identity);
9075 }
sqianc5eccab2018-10-19 18:46:41 -07009076 }
9077
9078 @Override
sqian8c685422019-02-22 15:55:18 -08009079 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009080 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009081 if (!exactMatch) {
9082 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009083 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009084 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009085 }
9086 final long identity = Binder.clearCallingIdentity();
9087 try {
sqian854d44b2018-12-12 16:48:18 -08009088 for (Phone phone: PhoneFactory.getPhones()) {
9089 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009090 && phone.getEmergencyNumberTracker()
9091 .isEmergencyNumber(number, exactMatch)) {
9092 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009093 }
sqian11b7a0e2018-12-05 18:48:28 -08009094 }
9095 return false;
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
9100
sqianf4ca7ed2019-01-15 18:32:07 -08009101 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009102 * Start emergency callback mode for GsmCdmaPhone for testing.
9103 */
9104 @Override
9105 public void startEmergencyCallbackMode() {
9106 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9107 "startEmergencyCallbackMode");
9108 enforceModifyPermission();
9109 final long identity = Binder.clearCallingIdentity();
9110 try {
9111 for (Phone phone : PhoneFactory.getPhones()) {
9112 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9113 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9114 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9115 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9116 gsmCdmaPhone.obtainMessage(
9117 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9118 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9119 }
9120 }
9121 } finally {
9122 Binder.restoreCallingIdentity(identity);
9123 }
9124 }
9125
9126 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009127 * Update emergency number list for test mode.
9128 */
9129 @Override
9130 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9131 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9132 "updateEmergencyNumberListTestMode");
9133
9134 final long identity = Binder.clearCallingIdentity();
9135 try {
9136 for (Phone phone: PhoneFactory.getPhones()) {
9137 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9138 if (tracker != null) {
9139 tracker.executeEmergencyNumberTestModeCommand(action, num);
9140 }
9141 }
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
9144 }
9145 }
9146
9147 /**
9148 * Get the full emergency number list for test mode.
9149 */
9150 @Override
9151 public List<String> getEmergencyNumberListTestMode() {
9152 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9153 "getEmergencyNumberListTestMode");
9154
9155 final long identity = Binder.clearCallingIdentity();
9156 try {
9157 Set<String> emergencyNumbers = new HashSet<>();
9158 for (Phone phone: PhoneFactory.getPhones()) {
9159 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9160 if (tracker != null) {
9161 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9162 emergencyNumbers.add(num.getNumber());
9163 }
9164 }
9165 }
9166 return new ArrayList<>(emergencyNumbers);
9167 } finally {
9168 Binder.restoreCallingIdentity(identity);
9169 }
9170 }
9171
chen xud6b45bd2018-10-30 22:27:10 -07009172 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009173 public int getEmergencyNumberDbVersion(int subId) {
9174 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9175
9176 final long identity = Binder.clearCallingIdentity();
9177 try {
9178 final Phone phone = getPhone(subId);
9179 if (phone == null) {
9180 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9181 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9182 }
9183 return phone.getEmergencyNumberDbVersion();
9184 } finally {
9185 Binder.restoreCallingIdentity(identity);
9186 }
9187 }
9188
9189 @Override
9190 public void notifyOtaEmergencyNumberDbInstalled() {
9191 enforceModifyPermission();
9192
9193 final long identity = Binder.clearCallingIdentity();
9194 try {
9195 for (Phone phone: PhoneFactory.getPhones()) {
9196 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9197 if (tracker != null) {
9198 tracker.updateOtaEmergencyNumberDatabase();
9199 }
9200 }
9201 } finally {
9202 Binder.restoreCallingIdentity(identity);
9203 }
9204 }
9205
9206 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009207 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009208 enforceActiveEmergencySessionPermission();
9209
9210 final long identity = Binder.clearCallingIdentity();
9211 try {
9212 for (Phone phone: PhoneFactory.getPhones()) {
9213 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9214 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009215 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9216 }
9217 }
9218 } finally {
9219 Binder.restoreCallingIdentity(identity);
9220 }
9221 }
9222
9223 @Override
9224 public void resetOtaEmergencyNumberDbFilePath() {
9225 enforceActiveEmergencySessionPermission();
9226
9227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 for (Phone phone: PhoneFactory.getPhones()) {
9230 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9231 if (tracker != null) {
9232 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009233 }
9234 }
9235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 }
9239
9240 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009241 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9242 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9243 Phone phone = getPhone(subId);
9244 if (phone == null) {
9245 return null;
9246 }
9247 final long identity = Binder.clearCallingIdentity();
9248 try {
9249 UiccProfile profile = UiccController.getInstance()
9250 .getUiccProfileForPhone(phone.getPhoneId());
9251 if (profile != null) {
9252 return profile.getCertsFromCarrierPrivilegeAccessRules();
9253 }
9254 } finally {
9255 Binder.restoreCallingIdentity(identity);
9256 }
9257 return null;
9258 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009259
9260 /**
9261 * Enable or disable a modem stack.
9262 */
9263 @Override
9264 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9265 enforceModifyPermission();
9266
9267 final long identity = Binder.clearCallingIdentity();
9268 try {
9269 Phone phone = PhoneFactory.getPhone(slotIndex);
9270 if (phone == null) {
9271 return false;
9272 } else {
9273 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9274 }
9275 } finally {
9276 Binder.restoreCallingIdentity(identity);
9277 }
9278 }
Michelecea4cf22018-12-21 15:00:11 -08009279
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009280 /**
9281 * Whether a modem stack is enabled or not.
9282 */
9283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009284 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9285 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009286 Phone phone = PhoneFactory.getPhone(slotIndex);
9287 if (phone == null) return false;
9288
9289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009290 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9291 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009292 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9293 }
9294
9295 final long identity = Binder.clearCallingIdentity();
9296 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009297 try {
9298 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9299 } catch (NoSuchElementException ex) {
9300 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9301 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
9306
Michelecea4cf22018-12-21 15:00:11 -08009307 @Override
Michele0ea7d782019-03-19 14:58:42 -07009308 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009309 enforceModifyPermission();
9310
9311 final long identity = Binder.clearCallingIdentity();
9312 try {
9313 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009314 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009315 .commit();
9316 } finally {
9317 Binder.restoreCallingIdentity(identity);
9318 }
9319 }
9320
9321 @Override
Michele0ea7d782019-03-19 14:58:42 -07009322 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009323 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009325 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9326 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009327 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009328 }
Michelecea4cf22018-12-21 15:00:11 -08009329
9330 final long identity = Binder.clearCallingIdentity();
9331 try {
Michele0ea7d782019-03-19 14:58:42 -07009332 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009333 } finally {
9334 Binder.restoreCallingIdentity(identity);
9335 }
9336 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009337
Michele0ea7d782019-03-19 14:58:42 -07009338 @TelephonyManager.IsMultiSimSupportedResult
9339 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009340 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9341 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9342 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009343 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9344 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009345 }
9346 // Check if the hardware supports multisim functionality. If usage of multisim is not
9347 // supported by the modem, indicate that it is restricted.
9348 PhoneCapability staticCapability =
9349 mPhoneConfigurationManager.getStaticPhoneCapability();
9350 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009351 loge("isMultiSimSupportedInternal: no static configuration available");
9352 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009353 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009354 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009355 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9356 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009357 }
9358 // Check if support of multiple SIMs is restricted by carrier
9359 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009360 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009361 }
9362
Michele0ea7d782019-03-19 14:58:42 -07009363 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009364 }
9365
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009366 /**
9367 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009368 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9369 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9370 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009371 * @param numOfSims number of active sims we want to switch to
9372 */
9373 @Override
9374 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009375 if (numOfSims == 1) {
9376 enforceModifyPermission();
9377 } else {
9378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9379 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9380 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009381 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009382
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009383 try {
Michele30b57b22019-03-01 12:01:14 -08009384 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009385 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009386 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9387 return;
9388 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009389 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9390 } finally {
9391 Binder.restoreCallingIdentity(identity);
9392 }
9393 }
9394
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009395 @Override
9396 public boolean isApplicationOnUicc(int subId, int appType) {
9397 enforceReadPrivilegedPermission("isApplicationOnUicc");
9398 Phone phone = getPhone(subId);
9399 if (phone == null) {
9400 return false;
9401 }
9402 final long identity = Binder.clearCallingIdentity();
9403 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009404 UiccPort uiccPort = phone.getUiccPort();
9405 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009406 return false;
9407 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009408 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009409 if (uiccProfile == null) {
9410 return false;
9411 }
9412 if (TelephonyManager.APPTYPE_SIM <= appType
9413 && appType <= TelephonyManager.APPTYPE_ISIM) {
9414 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9415 }
9416 return false;
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
9420 }
9421
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009422 /**
chen xub4baa772019-04-03 10:23:41 -07009423 * Get whether making changes to modem configurations will trigger reboot.
9424 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009425 */
9426 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009427 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9428 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009430 mApp, subId, callingPackage, callingFeatureId,
9431 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009432 return false;
9433 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009434 final long identity = Binder.clearCallingIdentity();
9435 try {
9436 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 }
9441
Nathan Harold29f5f052019-02-15 13:41:57 -08009442 private void updateModemStateMetrics() {
9443 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9444 // TODO: check the state for each modem if the api is ready.
9445 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9446 }
9447
Pengquan Meng3889a572019-01-23 11:16:29 -08009448 @Override
9449 public int[] getSlotsMapping() {
9450 enforceReadPrivilegedPermission("getSlotsMapping");
9451
9452 final long identity = Binder.clearCallingIdentity();
9453 try {
9454 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9455 // All logical slots should have a mapping to a physical slot.
9456 int[] logicalSlotsMapping = new int[phoneCount];
9457 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9458 for (int i = 0; i < slotInfos.length; i++) {
9459 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9460 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9461 }
9462 }
9463 return logicalSlotsMapping;
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009468
9469 /**
9470 * Get the IRadio HAL Version
9471 */
9472 @Override
9473 public int getRadioHalVersion() {
9474 Phone phone = getDefaultPhone();
9475 if (phone == null) return -1;
9476 HalVersion hv = phone.getHalVersion();
9477 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9478 return hv.major * 100 + hv.minor;
9479 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009480
9481 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009482 * Get the current calling package name.
9483 * @return the current calling package name
9484 */
9485 @Override
9486 public String getCurrentPackageName() {
9487 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9488 }
9489
9490 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009491 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9492 * corresponding network requests on a subId.
9493 *
9494 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009495 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009496 * 2) APN is un-metered for this subscription, or
9497 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009498 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009499 *
9500 * @return whether data is allowed for a apn type.
9501 *
9502 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009503 */
9504 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009505 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009506 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9507 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009508
9509 // Now that all security checks passes, perform the operation as ourselves.
9510 final long identity = Binder.clearCallingIdentity();
9511 try {
9512 Phone phone = getPhone(subId);
9513 if (phone == null) return false;
9514
Jack Yu41407ee2019-05-13 16:54:09 -07009515 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009516 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9517 } finally {
9518 Binder.restoreCallingIdentity(identity);
9519 }
9520 }
9521
9522 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009523 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009524 enforceReadPrivilegedPermission("isApnMetered");
9525
9526 // Now that all security checks passes, perform the operation as ourselves.
9527 final long identity = Binder.clearCallingIdentity();
9528 try {
9529 Phone phone = getPhone(subId);
9530 if (phone == null) return true; // By default return true.
9531
Jack Yu41407ee2019-05-13 16:54:09 -07009532 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009537
9538 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009539 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9540 int subscriptionId, IBooleanConsumer resultCallback) {
9541 enforceModifyPermission();
9542 long token = Binder.clearCallingIdentity();
9543 try {
9544 Phone phone = getPhone(subscriptionId);
9545 if (phone == null) {
9546 try {
9547 if (resultCallback != null) {
9548 resultCallback.accept(false);
9549 }
9550 } catch (RemoteException e) {
9551 // ignore
9552 }
9553 return;
9554 }
9555 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9556 Pair.create(specifiers, (x) -> {
9557 try {
9558 if (resultCallback != null) {
9559 resultCallback.accept(x);
9560 }
9561 } catch (RemoteException e) {
9562 // ignore
9563 }
9564 });
9565 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9566 } finally {
9567 Binder.restoreCallingIdentity(token);
9568 }
9569 }
9570
9571 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009572 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9573 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009574 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009575 mApp, subId, "getSystemSelectionChannels");
9576 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9577 final long identity = Binder.clearCallingIdentity();
9578 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009579 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9580 if (result instanceof IllegalStateException) {
9581 throw (IllegalStateException) result;
9582 }
9583 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009584 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9585 return specifiers;
9586 } finally {
9587 Binder.restoreCallingIdentity(identity);
9588 }
9589 }
9590
9591 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009592 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009593 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009594 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9595 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9596 if (iccRecords == null) {
9597 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9598 return false;
9599 }
9600 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9601 }
9602
9603 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009604 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9605 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009606 if (callingPackage == null) {
9607 callingPackage = getCurrentPackageName();
9608 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009609 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9610 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009611 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9612 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009613 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9614 }
9615 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9616 Intent intent = new Intent();
9617 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9618 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9619 // Bring up choose default SMS subscription dialog right now
9620 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9621 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9622 mApp.startActivity(intent);
9623 }
chen xud5ca2d52019-05-28 15:20:57 -07009624
9625 @Override
9626 public String getMmsUAProfUrl(int subId) {
9627 //TODO investigate if this API should require proper permission check in R b/133791609
9628 final long identity = Binder.clearCallingIdentity();
9629 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009630 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9631 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9632 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9633 return carrierUAProfUrl;
9634 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009635 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9636 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009637 } finally {
9638 Binder.restoreCallingIdentity(identity);
9639 }
9640 }
9641
9642 @Override
9643 public String getMmsUserAgent(int subId) {
9644 //TODO investigate if this API should require proper permission check in R b/133791609
9645 final long identity = Binder.clearCallingIdentity();
9646 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009647 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9648 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9649 if (!TextUtils.isEmpty(carrierUserAgent)) {
9650 return carrierUserAgent;
9651 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009652 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9653 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009654 } finally {
9655 Binder.restoreCallingIdentity(identity);
9656 }
9657 }
Jack Yub07d4972019-05-28 16:12:25 -07009658
9659 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009660 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9661 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009662
Jack Yub07d4972019-05-28 16:12:25 -07009663 final long identity = Binder.clearCallingIdentity();
9664 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009665 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009666 if (phone == null) return false;
9667
Hall Liua62f5da2020-09-25 10:42:19 -07009668 switch (policy) {
9669 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9670 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9671 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9672 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9673 default:
9674 throw new IllegalArgumentException(policy + " is not a valid policy");
9675 }
Jack Yub07d4972019-05-28 16:12:25 -07009676 } finally {
9677 Binder.restoreCallingIdentity(identity);
9678 }
9679 }
9680
9681 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009682 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009683 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009684 enforceModifyPermission();
9685
changbettyd5c246e2019-12-24 15:40:37 +08009686 final long identity = Binder.clearCallingIdentity();
9687 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009688 Phone phone = getPhone(subscriptionId);
9689 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009690
Hall Liua62f5da2020-09-25 10:42:19 -07009691 switch (policy) {
9692 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9693 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9694 break;
9695 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9696 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9697 break;
9698 default:
9699 throw new IllegalArgumentException(policy + " is not a valid policy");
9700 }
changbettyd5c246e2019-12-24 15:40:37 +08009701 } finally {
9702 Binder.restoreCallingIdentity(identity);
9703 }
9704 }
9705
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009706 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009707 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009708 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9709 * otherwise.
9710 */
9711 @Override
9712 public void setCepEnabled(boolean isCepEnabled) {
9713 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9714
9715 final long identity = Binder.clearCallingIdentity();
9716 try {
9717 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9718 for (Phone phone : PhoneFactory.getPhones()) {
9719 Phone defaultPhone = phone.getImsPhone();
9720 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9721 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9722 ImsPhoneCallTracker imsPhoneCallTracker =
9723 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9724 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9725 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9726 + imsPhone.getMsisdn());
9727 }
9728 }
9729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
allenwtsu46dcc572020-01-08 18:24:03 +08009733
9734 /**
9735 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9736 *
9737 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9738 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9739 * before being read.
9740 */
9741 @Override
9742 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9743 isCompressed) {
9744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9745 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9747 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9748 }
9749 if (!isImsAvailableOnDevice()) {
9750 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9751 "IMS not available on device.");
9752 }
9753
9754 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009755 try {
Hui Wang761a6682020-10-31 05:12:53 +00009756 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9757 } finally {
9758 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009759 }
9760 }
zoey chene02881a2019-12-30 16:11:23 +08009761
9762 @Override
9763 public boolean isIccLockEnabled(int subId) {
9764 enforceReadPrivilegedPermission("isIccLockEnabled");
9765
9766 // Now that all security checks passes, perform the operation as ourselves.
9767 final long identity = Binder.clearCallingIdentity();
9768 try {
9769 Phone phone = getPhone(subId);
9770 if (phone != null && phone.getIccCard() != null) {
9771 return phone.getIccCard().getIccLockEnabled();
9772 } else {
9773 return false;
9774 }
9775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 }
9779
9780 /**
9781 * Set the ICC pin lock enabled or disabled.
9782 *
9783 * @return an integer representing the status of IccLock enabled or disabled in the following
9784 * three cases:
9785 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9786 * successfully.
9787 * - Positive number and zero for remaining password attempts.
9788 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9789 *
9790 */
9791 @Override
9792 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9793 enforceModifyPermission();
9794
9795 Phone phone = getPhone(subId);
9796 if (phone == null) {
9797 return 0;
9798 }
9799 // Now that all security checks passes, perform the operation as ourselves.
9800 final long identity = Binder.clearCallingIdentity();
9801 try {
9802 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9803 new Pair<Boolean, String>(enabled, password), phone, null);
9804 return attemptsRemaining;
9805
9806 } catch (Exception e) {
9807 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9808 } finally {
9809 Binder.restoreCallingIdentity(identity);
9810 }
9811 return 0;
9812 }
9813
9814 /**
9815 * Change the ICC password used in ICC pin lock.
9816 *
9817 * @return an integer representing the status of IccLock changed in the following three cases:
9818 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9819 * - Positive number and zero for remaining password attempts.
9820 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9821 *
9822 */
9823 @Override
9824 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9825 enforceModifyPermission();
9826
9827 Phone phone = getPhone(subId);
9828 if (phone == null) {
9829 return 0;
9830 }
9831 // Now that all security checks passes, perform the operation as ourselves.
9832 final long identity = Binder.clearCallingIdentity();
9833 try {
9834 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9835 new Pair<String, String>(oldPassword, newPassword), phone, null);
9836 return attemptsRemaining;
9837
9838 } catch (Exception e) {
9839 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9840 } finally {
9841 Binder.restoreCallingIdentity(identity);
9842 }
9843 return 0;
9844 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009845
9846 /**
9847 * Request for receiving user activity notification
9848 */
9849 @Override
9850 public void requestUserActivityNotification() {
9851 if (!mNotifyUserActivity.get()
9852 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9853 mNotifyUserActivity.set(true);
9854 }
9855 }
9856
9857 /**
9858 * Called when userActivity is signalled in the power manager.
9859 * This is safe to call from any thread, with any window manager locks held or not.
9860 */
9861 @Override
9862 public void userActivity() {
9863 // ***************************************
9864 // * Inherited from PhoneWindowManager *
9865 // ***************************************
9866 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9867 // WITH ITS LOCKS HELD.
9868 //
9869 // This code must be VERY careful about the locks
9870 // it acquires.
9871 // In fact, the current code acquires way too many,
9872 // and probably has lurking deadlocks.
9873
9874 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9875 throw new SecurityException("Only the OS may call notifyUserActivity()");
9876 }
9877
9878 if (mNotifyUserActivity.getAndSet(false)) {
9879 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9880 USER_ACTIVITY_NOTIFICATION_DELAY);
9881 }
9882 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009883
9884 @Override
9885 public boolean canConnectTo5GInDsdsMode() {
9886 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9887 }
Jack Yud10cdd42020-09-28 20:28:01 -07009888
9889 @Override
9890 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9891 String callingFeatureId) {
9892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9893 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9894 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9895 }
9896
9897 Phone phone = getPhone(subId);
9898 if (phone == null) {
9899 throw new RuntimeException("phone is not available");
9900 }
9901 // Now that all security checks passes, perform the operation as ourselves.
9902 final long identity = Binder.clearCallingIdentity();
9903 try {
9904 return phone.getEquivalentHomePlmns();
9905 } finally {
9906 Binder.restoreCallingIdentity(identity);
9907 }
9908 }
Daniel Bright59e67312020-11-13 11:49:37 -08009909
9910 @Override
9911 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009912 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9913 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009914 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009915 if (radioInterfaceCapabilities == null) {
9916 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009917 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009918 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009919 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009920
Hui Wang641e81c2020-10-12 12:14:23 -07009921 @Override
9922 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9923 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009924 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9925 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9926 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9927 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9928 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009929 if (DBG) {
9930 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9931 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9932 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9933 }
9934
9935 if (!SubscriptionManager.isValidSubscriptionId(subId)
9936 || appType < TelephonyManager.APPTYPE_UNKNOWN
9937 || appType > TelephonyManager.APPTYPE_ISIM
9938 || nafUrl == null || securityProtocol == null || callback == null) {
9939 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9940 if (callback != null) {
9941 try {
9942 callback.onAuthenticationFailure(
9943 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9944 } catch (RemoteException exception) {
9945 log("Fail to notify onAuthenticationFailure due to " + exception);
9946 }
9947 return;
9948 }
9949 }
9950
9951 final long token = Binder.clearCallingIdentity();
9952 try {
9953 getGbaManager(subId).bootstrapAuthenticationRequest(
9954 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9955 forceBootStrapping, callback));
9956 } finally {
9957 Binder.restoreCallingIdentity(token);
9958 }
9959 }
9960
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009961 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009962 * Attempts to set the radio power state for all phones for thermal reason.
9963 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009964 * requested radio power state will actually be set. See {@link
9965 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9966 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009967 * @param enable {@code true} if trying to turn radio on.
9968 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9969 * false}.
9970 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009971 private boolean setRadioPowerForThermal(boolean enable) {
9972 boolean isPhoneAvailable = false;
9973 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9974 Phone phone = PhoneFactory.getPhone(i);
9975 if (phone != null) {
9976 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9977 isPhoneAvailable = true;
9978 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009979 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009980
9981 // return true if successfully informed the phone object about the thermal radio power
9982 // request.
9983 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009984 }
9985
9986 private int handleDataThrottlingRequest(int subId,
9987 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009988 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9989 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9990 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9991 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9992 throw new IllegalArgumentException("modem does not support data throttling");
9993 }
9994
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009995 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9996 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009997 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009998 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9999 }
10000
10001 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10002
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010003 if (isDataThrottlingSupported) {
10004 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010005 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010006 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10007 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10008 } else if (thermalMitigationResult
10009 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010010 log("Modem likely does not support data throttling on secondary carrier. Data " +
10011 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10012 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010013 }
10014 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010015 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010016
10017 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010018 }
10019
Jack Nudelman644b91a2021-03-12 14:09:48 -080010020 private static List<String> getThermalMitigationAllowlist(Context context) {
10021 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10022 for (String pckg : context.getResources()
10023 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10024 sThermalMitigationAllowlistedPackages.add(pckg);
10025 }
10026 }
10027
10028 return sThermalMitigationAllowlistedPackages;
10029 }
10030
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010031 private boolean isAnyPhoneInEmergencyState() {
10032 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10033 if (tm.isInEmergencyCall()) {
10034 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10035 return true;
10036 }
10037 for (Phone phone : PhoneFactory.getPhones()) {
10038 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10039 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10040 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10041 + phone.isInEcm());
10042 return true;
10043 }
10044 }
10045
10046 return false;
10047 }
10048
Jack Nudelman644b91a2021-03-12 14:09:48 -080010049 /**
10050 * Used by shell commands to add an authorized package name for thermal mitigation.
10051 * @param packageName name of package to be allowlisted
10052 * @param context
10053 */
10054 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10055 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10056 sThermalMitigationAllowlistedPackages.add(packageName);
10057 }
10058
10059 /**
10060 * Used by shell commands to remove an authorized package name for thermal mitigation.
10061 * @param packageName name of package to remove from allowlist
10062 * @param context
10063 */
10064 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10065 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10066 sThermalMitigationAllowlistedPackages.remove(packageName);
10067 }
10068
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010069 /**
10070 * Thermal mitigation request to control functionalities at modem.
10071 *
10072 * @param subId the id of the subscription.
10073 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010074 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010075 *
10076 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10077 */
10078 @Override
10079 @ThermalMitigationResult
10080 public int sendThermalMitigationRequest(
10081 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010082 ThermalMitigationRequest thermalMitigationRequest,
10083 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010084 enforceModifyPermission();
10085
Jack Nudelman644b91a2021-03-12 14:09:48 -080010086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10087 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10088 .contains(callingPackage)) {
10089 throw new SecurityException("Calling package must be configured in the device config. "
10090 + "calling package: " + callingPackage);
10091 }
10092
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010093 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10094 final long identity = Binder.clearCallingIdentity();
10095
10096 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10097 try {
10098 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10099 switch (thermalMitigationAction) {
10100 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10101 thermalMitigationResult =
10102 handleDataThrottlingRequest(subId,
10103 thermalMitigationRequest.getDataThrottlingRequest());
10104 break;
10105 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10106 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10107 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10108 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10109 }
10110
10111 // Ensure that radio is on. If not able to power on due to phone being
10112 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010113 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010114 thermalMitigationResult =
10115 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10116 break;
10117 }
10118
10119 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10120 false);
10121 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10122 break;
10123 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10124 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10125 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10126 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10127 }
10128
10129 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10130 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010131 Phone phone = getPhone(subId);
10132 if (phone == null) {
10133 thermalMitigationResult =
10134 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10135 break;
10136 }
10137
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010138 TelephonyConnectionService service =
10139 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010140 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010141 Log.e(LOG_TAG, "An emergency call is pending");
10142 thermalMitigationResult =
10143 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10144 break;
10145 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010146 thermalMitigationResult =
10147 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10148 break;
10149 }
10150 } else {
10151 thermalMitigationResult =
10152 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10153 break;
10154 }
10155
10156 // Turn radio off. If not able to power off due to phone being unavailable,
10157 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010158 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010159 thermalMitigationResult =
10160 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10161 break;
10162 }
10163 thermalMitigationResult =
10164 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10165 break;
10166 default:
10167 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10168 + "not exist. Requested action: " + thermalMitigationAction);
10169 }
10170 } catch (IllegalArgumentException e) {
10171 throw e;
10172 } catch (Exception e) {
10173 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10174 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10175 } finally {
10176 Binder.restoreCallingIdentity(identity);
10177 }
10178
10179 if (DBG) {
10180 log("thermalMitigationRequest returning with thermalMitigationResult: "
10181 + thermalMitigationResult);
10182 }
10183
10184 return thermalMitigationResult;
10185 }
Hui Wang641e81c2020-10-12 12:14:23 -070010186
10187 /**
10188 * Set the GbaService Package Name that Telephony will bind to.
10189 *
10190 * @param subId The sim that the GbaService is associated with.
10191 * @param packageName The name of the package to be replaced with.
10192 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10193 */
10194 @Override
10195 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10196 enforceModifyPermission();
10197
10198 final long identity = Binder.clearCallingIdentity();
10199 try {
10200 return getGbaManager(subId).overrideServicePackage(packageName);
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
10203 }
10204 }
10205
10206 /**
10207 * Return the package name of the currently bound GbaService.
10208 *
10209 * @param subId The sim that the GbaService is associated with.
10210 * @return the package name of the GbaService configuration, null if GBA is not supported.
10211 */
10212 @Override
10213 public String getBoundGbaService(int subId) {
10214 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10215
10216 final long identity = Binder.clearCallingIdentity();
10217 try {
10218 return getGbaManager(subId).getServicePackage();
10219 } finally {
10220 Binder.restoreCallingIdentity(identity);
10221 }
10222 }
10223
10224 /**
10225 * Set the release time for telephony to unbind GbaService.
10226 *
10227 * @param subId The sim that the GbaService is associated with.
10228 * @param interval The release time to unbind GbaService by millisecond.
10229 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10230 */
10231 @Override
10232 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10233 enforceModifyPermission();
10234
10235 final long identity = Binder.clearCallingIdentity();
10236 try {
10237 return getGbaManager(subId).overrideReleaseTime(interval);
10238 } finally {
10239 Binder.restoreCallingIdentity(identity);
10240 }
10241 }
10242
10243 /**
10244 * Return the release time for telephony to unbind GbaService.
10245 *
10246 * @param subId The sim that the GbaService is associated with.
10247 * @return The release time to unbind GbaService by millisecond.
10248 */
10249 @Override
10250 public int getGbaReleaseTime(int subId) {
10251 enforceReadPrivilegedPermission("getGbaReleaseTime");
10252
10253 final long identity = Binder.clearCallingIdentity();
10254 try {
10255 return getGbaManager(subId).getReleaseTime();
10256 } finally {
10257 Binder.restoreCallingIdentity(identity);
10258 }
10259 }
10260
10261 private GbaManager getGbaManager(int subId) {
10262 GbaManager instance = GbaManager.getInstance(subId);
10263 if (instance == null) {
10264 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10265 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10266 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10267 }
10268 return instance;
10269 }
Hui Wang761a6682020-10-31 05:12:53 +000010270
10271 /**
10272 * indicate whether the device and the carrier can support
10273 * RCS VoLTE single registration.
10274 */
10275 @Override
10276 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010277 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10278 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10279 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10280 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010281
10282 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10283 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10284 }
10285
10286 final long identity = Binder.clearCallingIdentity();
10287 try {
10288 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10289 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010290 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10291 if (isCapable != null) {
10292 return isCapable;
10293 }
Hui Wang761a6682020-10-31 05:12:53 +000010294 }
Hui Wang67af90e2021-06-04 16:57:15 -070010295 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10296 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010297 } finally {
10298 Binder.restoreCallingIdentity(identity);
10299 }
10300 }
10301
10302 /**
10303 * Register RCS provisioning callback.
10304 */
10305 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010306 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010307 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010308 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010309 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010310 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10311 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010312
10313 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10314 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10315 }
10316 if (!isImsAvailableOnDevice()) {
10317 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10318 "IMS not available on device.");
10319 }
10320
10321 final long identity = Binder.clearCallingIdentity();
10322 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010323 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010324 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010325 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10326 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010327 }
Hui Wang761a6682020-10-31 05:12:53 +000010328 } finally {
10329 Binder.restoreCallingIdentity(identity);
10330 }
10331 }
10332
10333 /**
10334 * Unregister RCS provisioning callback.
10335 */
10336 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010337 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010338 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010339 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010340 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010341 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10342 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010343
10344 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10345 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10346 }
10347 if (!isImsAvailableOnDevice()) {
10348 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10349 "IMS not available on device.");
10350 }
10351
10352 final long identity = Binder.clearCallingIdentity();
10353 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010354 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010355 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010356 } finally {
10357 Binder.restoreCallingIdentity(identity);
10358 }
10359 }
10360
10361 /**
10362 * trigger RCS reconfiguration.
10363 */
10364 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010365 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10366 "triggerRcsReconfiguration",
10367 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010368
10369 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10370 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10371 }
10372 if (!isImsAvailableOnDevice()) {
10373 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10374 "IMS not available on device.");
10375 }
10376
10377 final long identity = Binder.clearCallingIdentity();
10378 try {
10379 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10380 } finally {
10381 Binder.restoreCallingIdentity(identity);
10382 }
10383 }
10384
10385 /**
10386 * Provide the client configuration parameters of the RCS application.
10387 */
10388 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010389 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10390 "setRcsClientConfiguration",
10391 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010392
10393 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10394 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10395 }
10396 if (!isImsAvailableOnDevice()) {
10397 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10398 "IMS not available on device.");
10399 }
10400
10401 final long identity = Binder.clearCallingIdentity();
10402
10403 try {
10404 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10405 if (configBinder == null) {
10406 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010407 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10408 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010409 } else {
10410 configBinder.setRcsClientConfiguration(rcc);
10411 }
10412 } catch (RemoteException e) {
10413 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010414 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10415 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010416 } finally {
10417 Binder.restoreCallingIdentity(identity);
10418 }
10419 }
10420
10421 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010422 * Enables or disables the test mode for RCS VoLTE single registration.
10423 */
10424 @Override
10425 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10426 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10427 "setRcsSingleRegistrationTestModeEnabled");
10428
10429 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10430 }
10431
10432 /**
10433 * Gets the test mode for RCS VoLTE single registration.
10434 */
10435 @Override
10436 public boolean getRcsSingleRegistrationTestModeEnabled() {
10437 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10438 "getRcsSingleRegistrationTestModeEnabled");
10439
10440 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10441 }
10442
10443 /**
Hui Wang761a6682020-10-31 05:12:53 +000010444 * Overrides the config of RCS VoLTE single registration enabled for the device.
10445 */
10446 @Override
10447 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10448 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10449 "setDeviceSingleRegistrationEnabledOverride");
10450 enforceModifyPermission();
10451
10452 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10453 : Boolean.parseBoolean(enabledStr);
10454 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010455 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010456 }
10457
10458 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010459 * Sends a device to device communication message. Only usable via shell.
10460 * @param message message to send.
10461 * @param value message value.
10462 */
10463 @Override
10464 public void sendDeviceToDeviceMessage(int message, int value) {
10465 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010466 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010467 enforceModifyPermission();
10468
10469 final long identity = Binder.clearCallingIdentity();
10470 try {
10471 TelephonyConnectionService service =
10472 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10473 if (service == null) {
10474 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10475 return;
10476 }
10477 service.sendTestDeviceToDeviceMessage(message, value);
10478 } finally {
10479 Binder.restoreCallingIdentity(identity);
10480 }
10481 }
10482
Tyler Gunnbabbda02021-02-10 11:05:02 -080010483 /**
10484 * Sets the specified device to device transport active.
10485 * @param transport The transport to set active.
10486 */
10487 @Override
10488 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10489 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10490 "setActiveDeviceToDeviceTransport");
10491 enforceModifyPermission();
10492
10493 final long identity = Binder.clearCallingIdentity();
10494 try {
10495 TelephonyConnectionService service =
10496 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10497 if (service == null) {
10498 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10499 return;
10500 }
10501 service.setActiveDeviceToDeviceTransport(transport);
10502 } finally {
10503 Binder.restoreCallingIdentity(identity);
10504 }
10505 }
Tyler Gunn92479152021-01-20 16:30:10 -080010506
Tyler Gunnd4339262021-05-03 14:46:49 -070010507 @Override
10508 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10509 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10510 "setDeviceToDeviceForceEnabled");
10511
10512 final long identity = Binder.clearCallingIdentity();
10513 try {
10514 Arrays.stream(PhoneFactory.getPhones()).forEach(
10515 p -> {
10516 Phone thePhone = p.getImsPhone();
10517 if (thePhone != null && thePhone instanceof ImsPhone) {
10518 ImsPhone imsPhone = (ImsPhone) thePhone;
10519 CallTracker tracker = imsPhone.getCallTracker();
10520 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10521 ImsPhoneCallTracker imsPhoneCallTracker =
10522 (ImsPhoneCallTracker) tracker;
10523 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10524 }
10525 }
10526 }
10527 );
10528 } finally {
10529 Binder.restoreCallingIdentity(identity);
10530 }
10531 }
10532
Tyler Gunn92479152021-01-20 16:30:10 -080010533 /**
Hui Wang761a6682020-10-31 05:12:53 +000010534 * Gets the config of RCS VoLTE single registration enabled for the device.
10535 */
10536 @Override
10537 public boolean getDeviceSingleRegistrationEnabled() {
10538 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10539 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10540 }
10541
10542 /**
10543 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10544 */
10545 @Override
10546 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10547 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10548 "setCarrierSingleRegistrationEnabledOverride");
10549 enforceModifyPermission();
10550
10551 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10552 : Boolean.parseBoolean(enabledStr);
10553 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10554 subId, enabled);
10555 }
10556
10557 /**
10558 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10559 */
10560 @Override
10561 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10562 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10563 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10564 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010565
10566 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010567 * Overrides the ims feature validation result
10568 */
10569 @Override
10570 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10571 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10572 "setImsFeatureValidationOverride");
10573
10574 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10575 : Boolean.parseBoolean(enabledStr);
10576 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10577 subId, enabled);
10578 }
10579
10580 /**
10581 * Gets the ims feature validation override value
10582 */
10583 @Override
10584 public boolean getImsFeatureValidationOverride(int subId) {
10585 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10586 "getImsFeatureValidationOverride");
10587 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10588 }
10589
10590 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010591 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10592 * their mobile plan.
10593 */
10594 @Override
10595 public String getMobileProvisioningUrl() {
10596 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10597 final long identity = Binder.clearCallingIdentity();
10598 try {
10599 return getDefaultPhone().getMobileProvisioningUrl();
10600 } finally {
10601 Binder.restoreCallingIdentity(identity);
10602 }
10603 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010604
James.cf Linbcdf8b32021-01-14 16:44:13 +080010605 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010606 * Get the EAB contact from the EAB database.
10607 */
10608 @Override
10609 public String getContactFromEab(String contact) {
10610 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10611 enforceModifyPermission();
10612 final long identity = Binder.clearCallingIdentity();
10613 try {
10614 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10615 } finally {
10616 Binder.restoreCallingIdentity(identity);
10617 }
10618 }
10619
10620 /**
Calvin Pana1434322021-07-01 19:27:01 +080010621 * Get the EAB capability from the EAB database.
10622 */
10623 @Override
10624 public String getCapabilityFromEab(String contact) {
10625 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10626 enforceModifyPermission();
10627 final long identity = Binder.clearCallingIdentity();
10628 try {
10629 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10630 } finally {
10631 Binder.restoreCallingIdentity(identity);
10632 }
10633 }
10634
10635 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010636 * Remove the EAB contacts from the EAB database.
10637 */
10638 @Override
10639 public int removeContactFromEab(int subId, String contacts) {
10640 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10641 enforceModifyPermission();
10642 final long identity = Binder.clearCallingIdentity();
10643 try {
10644 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10645 } finally {
10646 Binder.restoreCallingIdentity(identity);
10647 }
10648 }
10649
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010650 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010651 public boolean getDeviceUceEnabled() {
10652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10653 final long identity = Binder.clearCallingIdentity();
10654 try {
10655 return mApp.getDeviceUceEnabled();
10656 } finally {
10657 Binder.restoreCallingIdentity(identity);
10658 }
10659 }
10660
10661 @Override
10662 public void setDeviceUceEnabled(boolean isEnabled) {
10663 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10664 final long identity = Binder.clearCallingIdentity();
10665 try {
10666 mApp.setDeviceUceEnabled(isEnabled);
10667 } finally {
10668 Binder.restoreCallingIdentity(identity);
10669 }
10670 }
10671
Brad Ebinger14d467f2021-02-12 06:18:28 +000010672 /**
10673 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10674 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10675 */
10676 // Used for SHELL command only right now.
10677 @Override
10678 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10679 List<String> featureTags) {
10680 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10681 "addUceRegistrationOverrideShell");
10682 final long identity = Binder.clearCallingIdentity();
10683 try {
10684 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10685 new ArraySet<>(featureTags));
10686 } catch (ImsException e) {
10687 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10688 } finally {
10689 Binder.restoreCallingIdentity(identity);
10690 }
10691 }
10692
10693 /**
10694 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10695 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10696 */
10697 // Used for SHELL command only right now.
10698 @Override
10699 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10700 List<String> featureTags) {
10701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10702 "removeUceRegistrationOverrideShell");
10703 final long identity = Binder.clearCallingIdentity();
10704 try {
10705 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10706 new ArraySet<>(featureTags));
10707 } catch (ImsException e) {
10708 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10709 } finally {
10710 Binder.restoreCallingIdentity(identity);
10711 }
10712 }
10713
10714 /**
10715 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10716 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10717 */
10718 // Used for SHELL command only right now.
10719 @Override
10720 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10721 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10722 "clearUceRegistrationOverrideShell");
10723 final long identity = Binder.clearCallingIdentity();
10724 try {
10725 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10726 } catch (ImsException e) {
10727 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10728 } finally {
10729 Binder.restoreCallingIdentity(identity);
10730 }
10731 }
10732
10733 /**
10734 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10735 */
10736 // Used for SHELL command only right now.
10737 @Override
10738 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10740 "getLatestRcsContactUceCapabilityShell");
10741 final long identity = Binder.clearCallingIdentity();
10742 try {
10743 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10744 } catch (ImsException e) {
10745 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10746 } finally {
10747 Binder.restoreCallingIdentity(identity);
10748 }
10749 }
10750
10751 /**
10752 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10753 * device does not have an active PUBLISH.
10754 */
10755 // Used for SHELL command only right now.
10756 @Override
10757 public String getLastUcePidfXmlShell(int subId) {
10758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10759 final long identity = Binder.clearCallingIdentity();
10760 try {
10761 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10762 } catch (ImsException e) {
10763 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10764 } finally {
10765 Binder.restoreCallingIdentity(identity);
10766 }
10767 }
10768
James.cf Line8713a42021-04-29 16:04:26 +080010769 /**
10770 * Remove UCE requests cannot be sent to the network status.
10771 */
10772 // Used for SHELL command only right now.
10773 @Override
10774 public boolean removeUceRequestDisallowedStatus(int subId) {
10775 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10776 final long identity = Binder.clearCallingIdentity();
10777 try {
10778 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10779 } catch (ImsException e) {
10780 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10781 } finally {
10782 Binder.restoreCallingIdentity(identity);
10783 }
10784 }
10785
James.cf Lin18bb9002021-05-25 01:37:38 +080010786 /**
10787 * Remove UCE requests cannot be sent to the network status.
10788 */
10789 // Used for SHELL command only.
10790 @Override
10791 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10793 final long identity = Binder.clearCallingIdentity();
10794 try {
10795 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10796 } catch (ImsException e) {
10797 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10798 } finally {
10799 Binder.restoreCallingIdentity(identity);
10800 }
10801 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010802
James.cf Lin4b784aa2021-01-31 03:25:15 +080010803 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010804 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10805 String callingPackage) {
10806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10807 mApp, subId, "setSignalStrengthUpdateRequest");
10808
10809 final int callingUid = Binder.getCallingUid();
10810 // Verify that tha callingPackage belongs to the calling UID
10811 mApp.getSystemService(AppOpsManager.class)
10812 .checkPackage(callingUid, callingPackage);
10813
10814 validateSignalStrengthUpdateRequest(request, callingUid);
10815
10816 final long identity = Binder.clearCallingIdentity();
10817 try {
10818 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10819 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10820
10821 if (result instanceof IllegalStateException) {
10822 throw (IllegalStateException) result;
10823 }
10824 } finally {
10825 Binder.restoreCallingIdentity(identity);
10826 }
10827 }
10828
10829 @Override
10830 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10831 String callingPackage) {
10832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10833 mApp, subId, "clearSignalStrengthUpdateRequest");
10834
10835 final int callingUid = Binder.getCallingUid();
10836 // Verify that tha callingPackage belongs to the calling UID
10837 mApp.getSystemService(AppOpsManager.class)
10838 .checkPackage(callingUid, callingPackage);
10839
10840 final long identity = Binder.clearCallingIdentity();
10841 try {
10842 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10843 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10844
10845 if (result instanceof IllegalStateException) {
10846 throw (IllegalStateException) result;
10847 }
10848 } finally {
10849 Binder.restoreCallingIdentity(identity);
10850 }
10851 }
10852
10853 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10854 int callingUid) {
10855 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10856 // phone/system process do not have further restriction on request
10857 return;
10858 }
10859
10860 // Applications has restrictions on how to use the request:
10861 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10862 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10863 // This is not system caller which has been checked above
10864 throw new IllegalArgumentException(
10865 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10866 }
10867
10868 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10869 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10870 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10871 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10872 || info.isEnabled()) {
10873 throw new IllegalArgumentException(
10874 "Only system can set hide fields in SignalThresholdInfo");
10875 }
10876
10877 // Thresholds length for each RAN need in range. This has been validated in
10878 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10879 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10880 final int[] thresholds = info.getThresholds();
10881 Objects.requireNonNull(thresholds);
10882 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10883 || thresholds.length
10884 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10885 throw new IllegalArgumentException(
10886 "thresholds length is out of range: " + thresholds.length);
10887 }
10888 }
10889 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010890
10891 /**
10892 * Gets the current phone capability.
10893 *
10894 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10895 * @return the PhoneCapability which describes the data connection capability of modem.
10896 * It's used to evaluate possible phone config change, for example from single
10897 * SIM device to multi-SIM device.
10898 */
10899 @Override
10900 public PhoneCapability getPhoneCapability() {
10901 enforceReadPrivilegedPermission("getPhoneCapability");
10902 final long identity = Binder.clearCallingIdentity();
10903 try {
10904 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10905 } finally {
10906 Binder.restoreCallingIdentity(identity);
10907 }
10908 }
Michele Berionne5e411512020-11-13 02:36:59 +000010909
10910 /**
10911 * Prepare TelephonyManager for an unattended reboot. The reboot is
10912 * required to be done shortly after the API is invoked.
10913 */
10914 @Override
10915 @TelephonyManager.PrepareUnattendedRebootResult
10916 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010917 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010918 enforceRebootPermission();
10919
10920 final long identity = Binder.clearCallingIdentity();
10921 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010922 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010923 } finally {
10924 Binder.restoreCallingIdentity(identity);
10925 }
10926 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010927
10928 /**
10929 * Request to get the current slicing configuration including URSP rules and
10930 * NSSAIs (configured, allowed and rejected).
10931 *
10932 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10933 */
10934 @Override
10935 public void getSlicingConfig(ResultReceiver callback) {
10936 enforceReadPrivilegedPermission("getSlicingConfig");
10937
10938 final long identity = Binder.clearCallingIdentity();
10939 try {
10940 Phone phone = getDefaultPhone();
10941 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10942 } finally {
10943 Binder.restoreCallingIdentity(identity);
10944 }
10945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010946}