blob: 9eccd10f1eb34b3150dd3e753d7d26ba6d0bfbc7 [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;
Shuo Qian4a594052020-01-23 11:59:30 -0800140import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700142import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700143import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800144import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700145import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700146import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800147import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700149import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800150import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800151import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800152import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700153import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700154import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800155import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800157import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700158import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700159import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700160import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700162import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800163import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700164import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700165import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700166import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700167import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800168import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800169import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700170import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700171import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700172import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800173import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800174import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800175import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700176import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800177import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700178import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800179import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700180import com.android.internal.telephony.imsphone.ImsPhone;
181import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800182import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700183import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800185import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700186import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800187import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700188import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800191import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000192import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800193import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700194import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700195import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800196import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800197import com.android.phone.callcomposer.CallComposerPictureManager;
198import com.android.phone.callcomposer.CallComposerPictureTransfer;
199import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700200import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700201import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800202import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700203import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700204import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800205import com.android.services.telephony.TelecomAccountRegistry;
206import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800207import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800208
Hall Liu82694d52020-12-11 18:22:04 -0800209import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700210import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800211import java.io.IOException;
212import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700213import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800215import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800216import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800217import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800218import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100219import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800220import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700221import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800223import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800225import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800226import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227
228/**
229 * Implementation of the ITelephony interface.
230 */
Santos Cordon117fee72014-05-16 17:56:12 -0700231public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232 private static final String LOG_TAG = "PhoneInterfaceManager";
233 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
234 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800235 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236
237 // Message codes used with mMainThreadHandler
238 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700239 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
240 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700241 private static final int CMD_OPEN_CHANNEL = 9;
242 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
243 private static final int CMD_CLOSE_CHANNEL = 11;
244 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800245 private static final int CMD_NV_READ_ITEM = 13;
246 private static final int EVENT_NV_READ_ITEM_DONE = 14;
247 private static final int CMD_NV_WRITE_ITEM = 15;
248 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
249 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
250 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700251 private static final int CMD_RESET_MODEM_CONFIG = 19;
252 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800253 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
254 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800255 private static final int CMD_SEND_ENVELOPE = 25;
256 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000257 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
258 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700259 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
260 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
261 private static final int CMD_EXCHANGE_SIM_IO = 31;
262 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800263 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
264 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700265 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
266 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700267 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
268 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700269 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
270 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
271 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
272 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700273 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
274 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
275 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
276 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700277 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800278 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
279 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000280 private static final int CMD_SWITCH_SLOTS = 50;
281 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700282 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
283 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
284 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
285 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
286 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
287 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
288 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
289 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700290 private static final int CMD_GET_ALL_CELL_INFO = 60;
291 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
292 private static final int CMD_GET_CELL_LOCATION = 62;
293 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700294 private static final int CMD_MODEM_REBOOT = 64;
295 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700296 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
297 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800298 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
299 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700300 private static final int CMD_GET_MODEM_STATUS = 70;
301 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700302 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
303 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700304 private static final int CMD_ERASE_MODEM_CONFIG = 74;
305 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800306 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
307 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
308 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
309 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800310 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
311 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800313 private static final int CMD_GET_CALL_FORWARDING = 83;
314 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
315 private static final int CMD_SET_CALL_FORWARDING = 85;
316 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
317 private static final int CMD_GET_CALL_WAITING = 87;
318 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
319 private static final int CMD_SET_CALL_WAITING = 89;
320 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700321 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
322 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
323 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
324 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700325 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
326 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800327 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
328 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800329 private static final int CMD_SET_DATA_THROTTLING = 99;
330 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800331 private static final int CMD_SET_SIM_POWER = 101;
332 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800333 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
334 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
335 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
336 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800337 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
338 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000339 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800340 private static final int CMD_GET_SLICING_CONFIG = 110;
341 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800342 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800344 // Parameters of select command.
345 private static final int SELECT_COMMAND = 0xA4;
346 private static final int SELECT_P1 = 0x04;
347 private static final int SELECT_P2 = 0;
348 private static final int SELECT_P3 = 0x10;
349
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 /** The singleton instance. */
351 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800352 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Wink Saville3ab207e2014-11-20 13:07:20 -0800354 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800355 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800356 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700357 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800358 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700359 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800361 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800362 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700363 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800364 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
Peter Wangdafb9ac2020-01-15 14:13:38 -0800366 /** User Activity */
367 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800368 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
369
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700370 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
371
Derek Tan97ebb422014-09-05 16:55:38 -0700372 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
373 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800374 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800375 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700376
Michelecea4cf22018-12-21 15:00:11 -0800377 // String to store multi SIM allowed
378 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
379
Derek Tan740e1672017-06-27 14:56:27 -0700380 // The AID of ISD-R.
381 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
382
yinxub1bed742017-04-17 11:45:04 -0700383 private NetworkScanRequestTracker mNetworkScanRequestTracker;
384
David Kelly5e06a7f2018-03-12 14:10:59 +0000385 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
386 private static final int MANUFACTURER_CODE_LENGTH = 8;
387
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800388 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800389 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800390
Derek Tan89e89d42014-07-08 17:00:10 -0700391 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700392 * Experiment flag to enable erase modem config on reset network, default value is false
393 */
394 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
395 "reset_network_erase_modem_config_enabled";
396
Rambo Wang0f050d82021-02-12 11:43:36 -0800397 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
398
Naina Nallurid63128d2019-09-17 14:10:30 -0700399 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700400 * A request object to use for transmitting data to an ICC.
401 */
402 private static final class IccAPDUArgument {
403 public int channel, cla, command, p1, p2, p3;
404 public String data;
405
406 public IccAPDUArgument(int channel, int cla, int command,
407 int p1, int p2, int p3, String data) {
408 this.channel = channel;
409 this.cla = cla;
410 this.command = command;
411 this.p1 = p1;
412 this.p2 = p2;
413 this.p3 = p3;
414 this.data = data;
415 }
416 }
417
418 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700419 * A request object to use for transmitting data to an ICC.
420 */
421 private static final class ManualNetworkSelectionArgument {
422 public OperatorInfo operatorInfo;
423 public boolean persistSelection;
424
425 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
426 this.operatorInfo = operatorInfo;
427 this.persistSelection = persistSelection;
428 }
429 }
430
431 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
433 * request after sending. The main thread will notify the request when it is complete.
434 */
435 private static final class MainThreadRequest {
436 /** The argument to use for the request */
437 public Object argument;
438 /** The result of the request that is run on the main thread */
439 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800440 // The subscriber id that this request applies to. Defaults to
441 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
442 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443
Nathan Harold92bed182018-10-12 18:16:49 -0700444 // In cases where subId is unavailable, the caller needs to specify the phone.
445 public Phone phone;
446
vagdeviaf9a5b92018-08-15 16:01:53 -0700447 public WorkSource workSource;
448
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 public MainThreadRequest(Object argument) {
450 this.argument = argument;
451 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800452
Nathan Harold92bed182018-10-12 18:16:49 -0700453 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
454 this.argument = argument;
455 if (phone != null) {
456 this.phone = phone;
457 }
458 this.workSource = workSource;
459 }
460
vagdeviaf9a5b92018-08-15 16:01:53 -0700461 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800462 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800463 if (subId != null) {
464 this.subId = subId;
465 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700466 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 }
469
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800470 private static final class IncomingThirdPartyCallArgs {
471 public final ComponentName component;
472 public final String callId;
473 public final String callerDisplayName;
474
475 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
476 String callerDisplayName) {
477 this.component = component;
478 this.callId = callId;
479 this.callerDisplayName = callerDisplayName;
480 }
481 }
482
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 /**
484 * A handler that processes messages on the main thread in the phone process. Since many
485 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
486 * inbound binder threads to the main thread in the phone process. The Binder thread
487 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
488 * on, which will be notified when the operation completes and will contain the result of the
489 * request.
490 *
491 * <p>If a MainThreadRequest object is provided in the msg.obj field,
492 * note that request.result must be set to something non-null for the calling thread to
493 * unblock.
494 */
495 private final class MainThreadHandler extends Handler {
496 @Override
497 public void handleMessage(Message msg) {
498 MainThreadRequest request;
499 Message onCompleted;
500 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800503 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504
505 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 case CMD_HANDLE_USSD_REQUEST: {
507 request = (MainThreadRequest) msg.obj;
508 final Phone phone = getPhoneFromRequest(request);
509 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
510 String ussdRequest = ussdObject.first;
511 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700512
Pengquan Menga1bb6272018-09-06 09:59:22 -0700513 if (!isUssdApiAllowed(request.subId)) {
514 // Carrier does not support use of this API, return failure.
515 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
516 UssdResponse response = new UssdResponse(ussdRequest, null);
517 Bundle returnData = new Bundle();
518 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
519 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700520
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 request.result = true;
522 notifyRequester(request);
523 return;
524 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700525
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 try {
527 request.result = phone != null
528 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
529 } catch (CallStateException cse) {
530 request.result = false;
531 }
532 // Wake up the requesting thread
533 notifyRequester(request);
534 break;
pkanwar32d516d2016-10-14 19:37:38 -0700535 }
536
Yorke Lee716f67e2015-06-17 15:39:16 -0700537 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700539 final Phone phone = getPhoneFromRequest(request);
540 request.result = phone != null ?
541 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
542 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700547
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700550 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 if (uiccCard == null) {
553 loge("iccTransmitApduLogicalChannel: No UICC");
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
558 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 iccArgument.channel, iccArgument.cla, iccArgument.command,
561 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 break;
565
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 ar = (AsyncResult) msg.obj;
568 request = (MainThreadRequest) ar.userObj;
569 if (ar.exception == null && ar.result != null) {
570 request.result = ar.result;
571 } else {
572 request.result = new IccIoResult(0x6F, 0, (byte[])null);
573 if (ar.result == null) {
574 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800575 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800577 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 } else {
579 loge("iccTransmitApduLogicalChannel: Unknown exception");
580 }
581 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 break;
584
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
586 request = (MainThreadRequest) msg.obj;
587 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800588 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 if (uiccCard == null) {
590 loge("iccTransmitApduBasicChannel: No UICC");
591 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 } else {
594 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
595 request);
596 uiccCard.iccTransmitApduBasicChannel(
597 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
598 iccArgument.p3, iccArgument.data, onCompleted);
599 }
600 break;
601
602 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
605 if (ar.exception == null && ar.result != null) {
606 request.result = ar.result;
607 } else {
608 request.result = new IccIoResult(0x6F, 0, (byte[])null);
609 if (ar.result == null) {
610 loge("iccTransmitApduBasicChannel: Empty response");
611 } else if (ar.exception instanceof CommandException) {
612 loge("iccTransmitApduBasicChannel: CommandException: " +
613 ar.exception);
614 } else {
615 loge("iccTransmitApduBasicChannel: Unknown exception");
616 }
617 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 break;
620
621 case CMD_EXCHANGE_SIM_IO:
622 request = (MainThreadRequest) msg.obj;
623 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 if (uiccCard == null) {
626 loge("iccExchangeSimIO: No UICC");
627 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
631 request);
632 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
633 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
634 iccArgument.data, onCompleted);
635 }
636 break;
637
638 case EVENT_EXCHANGE_SIM_IO_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
641 if (ar.exception == null && ar.result != null) {
642 request.result = ar.result;
643 } else {
644 request.result = new IccIoResult(0x6f, 0, (byte[])null);
645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 break;
648
Derek Tan4d5e5c12014-02-04 11:54:58 -0800649 case CMD_SEND_ENVELOPE:
650 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800651 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 if (uiccCard == null) {
653 loge("sendEnvelopeWithStatus: No UICC");
654 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 } else {
657 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
658 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
659 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800660 break;
661
662 case EVENT_SEND_ENVELOPE_DONE:
663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800667 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700668 request.result = new IccIoResult(0x6F, 0, (byte[])null);
669 if (ar.result == null) {
670 loge("sendEnvelopeWithStatus: Empty response");
671 } else if (ar.exception instanceof CommandException) {
672 loge("sendEnvelopeWithStatus: CommandException: " +
673 ar.exception);
674 } else {
675 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
676 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800677 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800679 break;
680
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 case CMD_OPEN_CHANNEL:
682 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800683 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800684 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 if (uiccCard == null) {
686 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800687 request.result = new IccOpenLogicalChannelResponse(-1,
688 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 } else {
691 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800692 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
693 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 break;
696
697 case EVENT_OPEN_CHANNEL_DONE:
698 ar = (AsyncResult) msg.obj;
699 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700702 int[] result = (int[]) ar.result;
703 int channelId = result[0];
704 byte[] selectResponse = null;
705 if (result.length > 1) {
706 selectResponse = new byte[result.length - 1];
707 for (int i = 1; i < result.length; ++i) {
708 selectResponse[i - 1] = (byte) result[i];
709 }
710 }
711 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700712 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 if (ar.result == null) {
715 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 if (ar.exception != null) {
718 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
719 }
720
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700721 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700722 if (ar.exception instanceof CommandException) {
723 CommandException.Error error =
724 ((CommandException) (ar.exception)).getCommandError();
725 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700726 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700727 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700728 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 }
730 }
731 openChannelResp = new IccOpenLogicalChannelResponse(
732 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700733 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700734 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700736 break;
737
738 case CMD_CLOSE_CHANNEL:
739 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800740 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700741 if (uiccCard == null) {
742 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900743 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700745 } else {
746 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
747 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
748 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700749 break;
750
751 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800752 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
753 break;
754
755 case CMD_NV_READ_ITEM:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800758 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
759 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800760 break;
761
762 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 ar = (AsyncResult) msg.obj;
764 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800765 if (ar.exception == null && ar.result != null) {
766 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800768 request.result = "";
769 if (ar.result == null) {
770 loge("nvReadItem: Empty response");
771 } else if (ar.exception instanceof CommandException) {
772 loge("nvReadItem: CommandException: " +
773 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800775 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 }
777 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 break;
780
Jake Hambye994d462014-02-03 13:10:13 -0800781 case CMD_NV_WRITE_ITEM:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
784 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800785 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700786 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800787 break;
788
789 case EVENT_NV_WRITE_ITEM_DONE:
790 handleNullReturnEvent(msg, "nvWriteItem");
791 break;
792
793 case CMD_NV_WRITE_CDMA_PRL:
794 request = (MainThreadRequest) msg.obj;
795 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800796 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800797 break;
798
799 case EVENT_NV_WRITE_CDMA_PRL_DONE:
800 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
801 break;
802
chen xu6dac5ab2018-10-26 17:39:23 -0700803 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800804 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700805 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800806 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800807 break;
808
chen xu6dac5ab2018-10-26 17:39:23 -0700809 case EVENT_RESET_MODEM_CONFIG_DONE:
810 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800811 break;
812
Sooraj Sasindran37444802020-08-11 10:40:43 -0700813 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
816 request);
817 Phone phone = getPhoneFromRequest(request);
818 if (phone != null) {
819 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
820 } else {
821 loge("isNRDualConnectivityEnabled: No phone object");
822 request.result = false;
823 notifyRequester(request);
824 }
825 break;
826 }
827
828 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
829 ar = (AsyncResult) msg.obj;
830 request = (MainThreadRequest) ar.userObj;
831 if (ar.exception == null && ar.result != null) {
832 request.result = ar.result;
833 } else {
834 // request.result must be set to something non-null
835 // for the calling thread to unblock
836 if (request.result != null) {
837 request.result = ar.result;
838 } else {
839 request.result = false;
840 }
841 if (ar.result == null) {
842 loge("isNRDualConnectivityEnabled: Empty response");
843 } else if (ar.exception instanceof CommandException) {
844 loge("isNRDualConnectivityEnabled: CommandException: "
845 + ar.exception);
846 } else {
847 loge("isNRDualConnectivityEnabled: Unknown exception");
848 }
849 }
850 notifyRequester(request);
851 break;
852
853 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
854 request = (MainThreadRequest) msg.obj;
855 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
856 Phone phone = getPhoneFromRequest(request);
857 if (phone != null) {
858 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
859 request.workSource);
860 } else {
861 loge("enableNrDualConnectivity: No phone object");
862 request.result =
863 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
864 notifyRequester(request);
865 }
866 break;
867 }
868
869 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null) {
873 request.result =
874 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
875 } else {
876 request.result =
877 TelephonyManager
878 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
879 if (ar.exception instanceof CommandException) {
880 CommandException.Error error =
881 ((CommandException) (ar.exception)).getCommandError();
882 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
883 request.result =
884 TelephonyManager
885 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000886 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
887 request.result =
888 TelephonyManager
889 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700890 }
891 loge("enableNrDualConnectivity" + ": CommandException: "
892 + ar.exception);
893 } else {
894 loge("enableNrDualConnectivity" + ": Unknown exception");
895 }
896 }
897 notifyRequester(request);
898 break;
899 }
900
SongFerngWang3ef3e072020-12-21 16:41:52 +0800901 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800903 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
904 request);
905 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 break;
907
SongFerngWang3ef3e072020-12-21 16:41:52 +0800908 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result; // Integer
913 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530914 // request.result must be set to something non-null
915 // for the calling thread to unblock
916 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800918 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800920 loge("getAllowedNetworkTypesBitmask: CommandException: "
921 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800922 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800923 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800924 }
925 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700926 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800927 break;
928
SongFerngWang3ef3e072020-12-21 16:41:52 +0800929 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800930 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800931 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
932 request);
933 Pair<Integer, Long> reasonWithNetworkTypes =
934 (Pair<Integer, Long>) request.argument;
935 getPhoneFromRequest(request).setAllowedNetworkTypes(
936 reasonWithNetworkTypes.first,
937 reasonWithNetworkTypes.second,
938 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800939 break;
940
SongFerngWang3ef3e072020-12-21 16:41:52 +0800941 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
942 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800943 break;
944
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000945 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
946 request = (MainThreadRequest)msg.obj;
947 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800948 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000949 break;
950
951 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
952 ar = (AsyncResult)msg.obj;
953 request = (MainThreadRequest)ar.userObj;
954 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000956 break;
957
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800958 case CMD_SET_VOICEMAIL_NUMBER:
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
961 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800962 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
963 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800964 break;
965
966 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
967 handleNullReturnEvent(msg, "setVoicemailNumber");
968 break;
969
Stuart Scott54788802015-03-30 13:18:01 -0700970 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
973 request);
974 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
975 break;
976
977 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
978 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
979 break;
980
Shishir Agrawal302c8692015-06-19 13:49:39 -0700981 case CMD_PERFORM_NETWORK_SCAN:
982 request = (MainThreadRequest) msg.obj;
983 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
984 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
985 break;
986
Hall Liu27d24262020-09-18 19:04:59 -0700987 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700990 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
991 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
992 request.argument;
993 int callForwardingReason = args.first;
994 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800995 break;
Hall Liu27d24262020-09-18 19:04:59 -0700996 }
997 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001000 TelephonyManager.CallForwardingInfoCallback callback =
1001 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1002 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001003 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001004 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001005 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1006 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1007 // Service Class is a bit mask per 3gpp 27.007. Search for
1008 // any service for voice call.
1009 if ((callForwardInfo.serviceClass
1010 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001011 callForwardingInfo = new CallForwardingInfo(true,
1012 callForwardInfo.reason,
1013 callForwardInfo.number,
1014 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001015 break;
1016 }
1017 }
1018 // Didn't find a call forward info for voice call.
1019 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001020 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1021 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001022 }
Hall Liu27d24262020-09-18 19:04:59 -07001023 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001024 } else {
1025 if (ar.result == null) {
1026 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1027 }
1028 if (ar.exception != null) {
1029 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1030 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001031 int errorCode = TelephonyManager
1032 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001033 if (ar.exception instanceof CommandException) {
1034 CommandException.Error error =
1035 ((CommandException) (ar.exception)).getCommandError();
1036 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001037 errorCode = TelephonyManager
1038 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001039 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001040 errorCode = TelephonyManager
1041 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001042 }
1043 }
Hall Liu27d24262020-09-18 19:04:59 -07001044 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001045 }
Shuo Qian4a594052020-01-23 11:59:30 -08001046 break;
Hall Liu27d24262020-09-18 19:04:59 -07001047 }
Shuo Qian4a594052020-01-23 11:59:30 -08001048
Hall Liu27d24262020-09-18 19:04:59 -07001049 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001052 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001053 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001054 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1055 request.argument).first;
1056 request.phone.setCallForwardingOption(
1057 callForwardingInfoToSet.isEnabled()
1058 ? CommandsInterface.CF_ACTION_ENABLE
1059 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001060 callForwardingInfoToSet.getReason(),
1061 callForwardingInfoToSet.getNumber(),
1062 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1063 break;
Hall Liu27d24262020-09-18 19:04:59 -07001064 }
Shuo Qian4a594052020-01-23 11:59:30 -08001065
Hall Liu27d24262020-09-18 19:04:59 -07001066 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001069 Consumer<Integer> callback =
1070 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1071 request.argument).second;
1072 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001073 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001074 int errorCode = TelephonyManager.CallForwardingInfoCallback
1075 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001076 if (ar.exception instanceof CommandException) {
1077 CommandException.Error error =
1078 ((CommandException) (ar.exception)).getCommandError();
1079 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001080 errorCode = TelephonyManager.CallForwardingInfoCallback
1081 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001082 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001083 errorCode = TelephonyManager.CallForwardingInfoCallback
1084 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001085 }
1086 }
1087 callback.accept(errorCode);
1088 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001089 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001090 }
Shuo Qian4a594052020-01-23 11:59:30 -08001091 break;
Hall Liu27d24262020-09-18 19:04:59 -07001092 }
Shuo Qian4a594052020-01-23 11:59:30 -08001093
Hall Liu27d24262020-09-18 19:04:59 -07001094 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001095 request = (MainThreadRequest) msg.obj;
1096 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1097 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1098 break;
Hall Liu27d24262020-09-18 19:04:59 -07001099 }
Shuo Qian4a594052020-01-23 11:59:30 -08001100
Hall Liu27d24262020-09-18 19:04:59 -07001101 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001102 ar = (AsyncResult) msg.obj;
1103 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001104 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001105 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1106 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001107 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001108 // Service Class is a bit mask per 3gpp 27.007.
1109 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001110 if (callForwardResults.length > 1
1111 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001112 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001113 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001114 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1115 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001116 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001117 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001118 }
1119 } else {
1120 if (ar.result == null) {
1121 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1122 }
1123 if (ar.exception != null) {
1124 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1125 }
1126 if (ar.exception instanceof CommandException) {
1127 CommandException.Error error =
1128 ((CommandException) (ar.exception)).getCommandError();
1129 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1130 callForwardingStatus =
1131 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1132 }
1133 }
1134 }
Hall Liu27d24262020-09-18 19:04:59 -07001135 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001136 break;
Hall Liu27d24262020-09-18 19:04:59 -07001137 }
Shuo Qian4a594052020-01-23 11:59:30 -08001138
Hall Liu27d24262020-09-18 19:04:59 -07001139 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001140 request = (MainThreadRequest) msg.obj;
1141 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001142 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1143 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001144 break;
Hall Liu27d24262020-09-18 19:04:59 -07001145 }
Shuo Qian4a594052020-01-23 11:59:30 -08001146
Hall Liu27d24262020-09-18 19:04:59 -07001147 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001148 ar = (AsyncResult) msg.obj;
1149 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001150 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1151 Consumer<Integer> callback =
1152 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1153 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001154 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001155 if (ar.exception instanceof CommandException) {
1156 CommandException.Error error =
1157 ((CommandException) (ar.exception)).getCommandError();
1158 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1159 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1160 } else {
1161 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1162 }
1163 } else {
1164 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1165 }
1166 } else {
1167 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1168 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001169 }
Shuo Qian4a594052020-01-23 11:59:30 -08001170 break;
Hall Liu27d24262020-09-18 19:04:59 -07001171 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001172 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1173 ar = (AsyncResult) msg.obj;
1174 request = (MainThreadRequest) ar.userObj;
1175 CellNetworkScanResult cellScanResult;
1176 if (ar.exception == null && ar.result != null) {
1177 cellScanResult = new CellNetworkScanResult(
1178 CellNetworkScanResult.STATUS_SUCCESS,
1179 (List<OperatorInfo>) ar.result);
1180 } else {
1181 if (ar.result == null) {
1182 loge("getCellNetworkScanResults: Empty response");
1183 }
1184 if (ar.exception != null) {
1185 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1186 }
1187 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1188 if (ar.exception instanceof CommandException) {
1189 CommandException.Error error =
1190 ((CommandException) (ar.exception)).getCommandError();
1191 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1192 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1193 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1194 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1195 }
1196 }
1197 cellScanResult = new CellNetworkScanResult(errorCode, null);
1198 }
1199 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001200 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001201 break;
1202
1203 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1204 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001205 ManualNetworkSelectionArgument selArg =
1206 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001207 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1208 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001209 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1210 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001211 break;
1212
1213 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001214 ar = (AsyncResult) msg.obj;
1215 request = (MainThreadRequest) ar.userObj;
1216 if (ar.exception == null) {
1217 request.result = true;
1218 } else {
1219 request.result = false;
1220 loge("setNetworkSelectionModeManual " + ar.exception);
1221 }
1222 notifyRequester(request);
1223 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001224 break;
1225
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001226 case CMD_GET_MODEM_ACTIVITY_INFO:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001229 if (defaultPhone != null) {
1230 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001231 } else {
1232 ResultReceiver result = (ResultReceiver) request.argument;
1233 Bundle bundle = new Bundle();
1234 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001235 new ModemActivityInfo(0, 0, 0,
1236 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001237 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001238 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001239 break;
1240
Hall Liud0f208c2020-10-14 16:54:44 -07001241 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001242 ar = (AsyncResult) msg.obj;
1243 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001244 ResultReceiver result = (ResultReceiver) request.argument;
1245
Hall Liud0f208c2020-10-14 16:54:44 -07001246 ModemActivityInfo ret = null;
1247 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001248 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001249 // Update the last modem activity info and the result of the request.
1250 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1251 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001252 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001253 int[] txTimeMs = info.getTransmitTimeMillis();
1254 int[] lastModemTxTimeMs = mLastModemActivityInfo
1255 .getTransmitTimeMillis();
1256 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1257 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1258 }
Hall Liu49656c02020-10-09 19:00:11 -07001259 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001260 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1261 + mLastModemActivityInfo.getSleepTimeMillis());
1262 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1263 + mLastModemActivityInfo.getIdleTimeMillis());
1264 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1265 mLastModemActivityInfo.setReceiveTimeMillis(
1266 info.getReceiveTimeMillis()
1267 + mLastModemActivityInfo.getReceiveTimeMillis());
1268 }
Hall Liu49656c02020-10-09 19:00:11 -07001269 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001270 mLastModemActivityInfo.getSleepTimeMillis(),
1271 mLastModemActivityInfo.getIdleTimeMillis(),
1272 mLastModemActivityInfo.getTransmitTimeMillis(),
1273 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001274 } else {
1275 if (ar.result == null) {
1276 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001277 error = TelephonyManager.ModemActivityInfoException
1278 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001279 } else if (ar.exception instanceof CommandException) {
1280 loge("queryModemActivityInfo: CommandException: " +
1281 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001282 error = TelephonyManager.ModemActivityInfoException
1283 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001284 } else {
1285 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001286 error = TelephonyManager.ModemActivityInfoException
1287 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001288 }
1289 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001290 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001291 if (ret != null) {
1292 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1293 } else {
1294 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1295 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001296 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001297 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001298 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001299 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001300
Meng Wang1a7c35a2016-05-05 20:56:15 -07001301 case CMD_SET_ALLOWED_CARRIERS:
1302 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001303 CarrierRestrictionRules argument =
1304 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001305 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001306 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001307 break;
1308
1309 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
1312 if (ar.exception == null && ar.result != null) {
1313 request.result = ar.result;
1314 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001315 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1316 if (ar.exception instanceof CommandException) {
1317 loge("setAllowedCarriers: CommandException: " + ar.exception);
1318 CommandException.Error error =
1319 ((CommandException) (ar.exception)).getCommandError();
1320 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1321 request.result =
1322 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1323 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001324 } else {
1325 loge("setAllowedCarriers: Unknown exception");
1326 }
1327 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001328 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001329 break;
1330
1331 case CMD_GET_ALLOWED_CARRIERS:
1332 request = (MainThreadRequest) msg.obj;
1333 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001334 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001335 break;
1336
1337 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1338 ar = (AsyncResult) msg.obj;
1339 request = (MainThreadRequest) ar.userObj;
1340 if (ar.exception == null && ar.result != null) {
1341 request.result = ar.result;
1342 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001343 request.result = new IllegalStateException(
1344 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001345 if (ar.result == null) {
1346 loge("getAllowedCarriers: Empty response");
1347 } else if (ar.exception instanceof CommandException) {
1348 loge("getAllowedCarriers: CommandException: " +
1349 ar.exception);
1350 } else {
1351 loge("getAllowedCarriers: Unknown exception");
1352 }
1353 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001354 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001355 break;
1356
Nathan Haroldb3014052017-01-25 15:57:32 -08001357 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1358 ar = (AsyncResult) msg.obj;
1359 request = (MainThreadRequest) ar.userObj;
1360 if (ar.exception == null && ar.result != null) {
1361 request.result = ar.result;
1362 } else {
1363 request.result = new IllegalArgumentException(
1364 "Failed to retrieve Forbidden Plmns");
1365 if (ar.result == null) {
1366 loge("getForbiddenPlmns: Empty response");
1367 } else {
1368 loge("getForbiddenPlmns: Unknown exception");
1369 }
1370 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001371 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001372 break;
1373
1374 case CMD_GET_FORBIDDEN_PLMNS:
1375 request = (MainThreadRequest) msg.obj;
1376 uiccCard = getUiccCardFromRequest(request);
1377 if (uiccCard == null) {
1378 loge("getForbiddenPlmns() UiccCard is null");
1379 request.result = new IllegalArgumentException(
1380 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001381 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001382 break;
1383 }
1384 Integer appType = (Integer) request.argument;
1385 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1386 if (uiccApp == null) {
1387 loge("getForbiddenPlmns() no app with specified type -- "
1388 + appType);
1389 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001390 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001391 break;
1392 } else {
1393 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1394 + " specified type -- " + appType);
1395 }
1396 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1397 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1398 onCompleted);
1399 break;
1400
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001401 case CMD_SWITCH_SLOTS:
1402 request = (MainThreadRequest) msg.obj;
1403 int[] physicalSlots = (int[]) request.argument;
1404 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1405 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1406 break;
1407
1408 case EVENT_SWITCH_SLOTS_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001412 notifyRequester(request);
1413 break;
1414 case CMD_GET_NETWORK_SELECTION_MODE:
1415 request = (MainThreadRequest) msg.obj;
1416 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1417 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1418 break;
1419
1420 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 if (ar.exception != null) {
1424 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1425 } else {
1426 int mode = ((int[]) ar.result)[0];
1427 if (mode == 0) {
1428 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1429 } else {
1430 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1431 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001432 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001433 notifyRequester(request);
1434 break;
1435 case CMD_GET_CDMA_ROAMING_MODE:
1436 request = (MainThreadRequest) msg.obj;
1437 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1438 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1439 break;
1440 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1441 ar = (AsyncResult) msg.obj;
1442 request = (MainThreadRequest) ar.userObj;
1443 if (ar.exception != null) {
1444 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1445 } else {
1446 request.result = ((int[]) ar.result)[0];
1447 }
1448 notifyRequester(request);
1449 break;
1450 case CMD_SET_CDMA_ROAMING_MODE:
1451 request = (MainThreadRequest) msg.obj;
1452 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1453 int mode = (int) request.argument;
1454 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1455 break;
1456 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1457 ar = (AsyncResult) msg.obj;
1458 request = (MainThreadRequest) ar.userObj;
1459 request.result = ar.exception == null;
1460 notifyRequester(request);
1461 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001462 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1463 request = (MainThreadRequest) msg.obj;
1464 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1465 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1466 break;
1467 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1468 ar = (AsyncResult) msg.obj;
1469 request = (MainThreadRequest) ar.userObj;
1470 if (ar.exception != null) {
1471 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1472 } else {
1473 request.result = ((int[]) ar.result)[0];
1474 }
1475 notifyRequester(request);
1476 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001477 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1478 request = (MainThreadRequest) msg.obj;
1479 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1480 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001481 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1482 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001483 break;
1484 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1485 ar = (AsyncResult) msg.obj;
1486 request = (MainThreadRequest) ar.userObj;
1487 request.result = ar.exception == null;
1488 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001489 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 case CMD_GET_ALL_CELL_INFO:
1491 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001493 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001494 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 case EVENT_GET_ALL_CELL_INFO_DONE:
1496 ar = (AsyncResult) msg.obj;
1497 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001498 // If a timeout occurs, the response will be null
1499 request.result = (ar.exception == null && ar.result != null)
1500 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001501 synchronized (request) {
1502 request.notifyAll();
1503 }
1504 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001505 case CMD_REQUEST_CELL_INFO_UPDATE:
1506 request = (MainThreadRequest) msg.obj;
1507 request.phone.requestCellInfoUpdate(request.workSource,
1508 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1509 break;
1510 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1514 try {
1515 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001516 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001517 cb.onError(
1518 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1519 ar.exception.getClass().getName(),
1520 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001521 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001522 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001523 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001524 } else {
1525 // use the result as returned
1526 cb.onCellInfo((List<CellInfo>) ar.result);
1527 }
1528 } catch (RemoteException re) {
1529 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1530 }
1531 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001532 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001533 request = (MainThreadRequest) msg.obj;
1534 WorkSource ws = (WorkSource) request.argument;
1535 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001536 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001537 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001538 }
1539 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001540 ar = (AsyncResult) msg.obj;
1541 request = (MainThreadRequest) ar.userObj;
1542 if (ar.exception == null) {
1543 request.result = ar.result;
1544 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001545 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001546 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001547 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001548 }
1549
1550 synchronized (request) {
1551 request.notifyAll();
1552 }
1553 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001554 }
chen xu6dac5ab2018-10-26 17:39:23 -07001555 case CMD_MODEM_REBOOT:
1556 request = (MainThreadRequest) msg.obj;
1557 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001558 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001559 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001560 case EVENT_CMD_MODEM_REBOOT_DONE:
1561 handleNullReturnEvent(msg, "rebootModem");
1562 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001563 case CMD_REQUEST_ENABLE_MODEM:
1564 request = (MainThreadRequest) msg.obj;
1565 boolean enable = (boolean) request.argument;
1566 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001567 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001568 PhoneConfigurationManager.getInstance()
1569 .enablePhone(request.phone, enable, onCompleted);
1570 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001571 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001572 ar = (AsyncResult) msg.obj;
1573 request = (MainThreadRequest) ar.userObj;
1574 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001575 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001576 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001577 if ((boolean) request.result) {
1578 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1579 updateModemStateMetrics();
1580 } else {
1581 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1582 + ar.exception);
1583 }
1584 notifyRequester(request);
1585 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001586 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001587 case CMD_GET_MODEM_STATUS:
1588 request = (MainThreadRequest) msg.obj;
1589 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1590 PhoneConfigurationManager.getInstance()
1591 .getPhoneStatusFromModem(request.phone, onCompleted);
1592 break;
1593 case EVENT_GET_MODEM_STATUS_DONE:
1594 ar = (AsyncResult) msg.obj;
1595 request = (MainThreadRequest) ar.userObj;
1596 int id = request.phone.getPhoneId();
1597 if (ar.exception == null && ar.result != null) {
1598 request.result = ar.result;
1599 //update the cache as modem status has changed
1600 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1601 (boolean) request.result);
1602 } else {
1603 // Return true if modem status cannot be retrieved. For most cases,
1604 // modem status is on. And for older version modems, GET_MODEM_STATUS
1605 // and disable modem are not supported. Modem is always on.
1606 // TODO: this should be fixed in R to support a third
1607 // status UNKNOWN b/131631629
1608 request.result = true;
1609 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1610 + ar.exception);
1611 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001612 notifyRequester(request);
1613 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001614 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1615 request = (MainThreadRequest) msg.obj;
1616 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1617 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1618 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1619 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1620 break;
1621 }
1622 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1626 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1627 args.second.accept(ar.exception == null);
1628 notifyRequester(request);
1629 break;
1630 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001631 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1632 request = (MainThreadRequest) msg.obj;
1633 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1634 Phone phone = getPhoneFromRequest(request);
1635 if (phone != null) {
1636 phone.getSystemSelectionChannels(onCompleted);
1637 } else {
1638 loge("getSystemSelectionChannels: No phone object");
1639 request.result = new ArrayList<RadioAccessSpecifier>();
1640 notifyRequester(request);
1641 }
1642 break;
1643 }
1644 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1645 ar = (AsyncResult) msg.obj;
1646 request = (MainThreadRequest) ar.userObj;
1647 if (ar.exception == null && ar.result != null) {
1648 request.result = ar.result;
1649 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001650 request.result = new IllegalStateException(
1651 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001652 if (ar.result == null) {
1653 loge("getSystemSelectionChannels: Empty response");
1654 } else {
1655 loge("getSystemSelectionChannels: Unknown exception");
1656 }
1657 }
1658 notifyRequester(request);
1659 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001660 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1661 ar = (AsyncResult) msg.obj;
1662 request = (MainThreadRequest) ar.userObj;
1663 if (ar.exception == null && ar.result != null) {
1664 request.result = ar.result;
1665 } else {
1666 request.result = -1;
1667 loge("Failed to set Forbidden Plmns");
1668 if (ar.result == null) {
1669 loge("setForbidenPlmns: Empty response");
1670 } else if (ar.exception != null) {
1671 loge("setForbiddenPlmns: Exception: " + ar.exception);
1672 request.result = -1;
1673 } else {
1674 loge("setForbiddenPlmns: Unknown exception");
1675 }
1676 }
1677 notifyRequester(request);
1678 break;
1679 case CMD_SET_FORBIDDEN_PLMNS:
1680 request = (MainThreadRequest) msg.obj;
1681 uiccCard = getUiccCardFromRequest(request);
1682 if (uiccCard == null) {
1683 loge("setForbiddenPlmns: UiccCard is null");
1684 request.result = -1;
1685 notifyRequester(request);
1686 break;
1687 }
1688 Pair<Integer, List<String>> setFplmnsArgs =
1689 (Pair<Integer, List<String>>) request.argument;
1690 appType = setFplmnsArgs.first;
1691 List<String> fplmns = setFplmnsArgs.second;
1692 uiccApp = uiccCard.getApplicationByType(appType);
1693 if (uiccApp == null) {
1694 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1695 request.result = -1;
1696 loge("Failed to get UICC App");
1697 notifyRequester(request);
1698 } else {
1699 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1700 ((SIMRecords) uiccApp.getIccRecords())
1701 .setForbiddenPlmns(onCompleted, fplmns);
1702 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001703 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001704 case CMD_ERASE_MODEM_CONFIG:
1705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1707 defaultPhone.eraseModemConfig(onCompleted);
1708 break;
1709 case EVENT_ERASE_MODEM_CONFIG_DONE:
1710 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001711 break;
zoey chene02881a2019-12-30 16:11:23 +08001712
Kai Shif70f46f2021-03-03 13:59:46 -08001713 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1714 request = (MainThreadRequest) msg.obj;
1715 request.result = defaultPhone.eraseDataInSharedPreferences();
1716 notifyRequester(request);
1717 break;
1718
zoey chene02881a2019-12-30 16:11:23 +08001719 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1722 Pair<String, String> changed = (Pair<String, String>) request.argument;
1723 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1724 changed.first, changed.second, onCompleted);
1725 break;
1726 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1727 ar = (AsyncResult) msg.obj;
1728 request = (MainThreadRequest) ar.userObj;
1729 if (ar.exception == null) {
1730 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001731 // If the operation is successful, update the PIN storage
1732 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1733 int phoneId = getPhoneFromRequest(request).getPhoneId();
1734 UiccController.getInstance().getPinStorage()
1735 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001736 } else {
1737 request.result = msg.arg1;
1738 }
1739 notifyRequester(request);
1740 break;
1741
Michele Berionne5e411512020-11-13 02:36:59 +00001742 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001743 request = (MainThreadRequest) msg.obj;
1744 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1745 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1746 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1747 enabled.first, enabled.second, onCompleted);
1748 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001749 }
zoey chene02881a2019-12-30 16:11:23 +08001750 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
1753 if (ar.exception == null) {
1754 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001755 // If the operation is successful, update the PIN storage
1756 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1757 int phoneId = getPhoneFromRequest(request).getPhoneId();
1758 if (enabled.first) {
1759 UiccController.getInstance().getPinStorage()
1760 .storePin(enabled.second, phoneId);
1761 } else {
1762 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1763 }
zoey chene02881a2019-12-30 16:11:23 +08001764 } else {
1765 request.result = msg.arg1;
1766 }
Michele Berionne5e411512020-11-13 02:36:59 +00001767
1768
zoey chene02881a2019-12-30 16:11:23 +08001769 notifyRequester(request);
1770 break;
1771
Peter Wangdafb9ac2020-01-15 14:13:38 -08001772 case MSG_NOTIFY_USER_ACTIVITY:
1773 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001774 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001775 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1776 getDefaultPhone().getContext().sendBroadcastAsUser(
1777 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1778 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001779
1780 case CMD_SET_DATA_THROTTLING: {
1781 request = (MainThreadRequest) msg.obj;
1782 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1783 DataThrottlingRequest dataThrottlingRequest =
1784 (DataThrottlingRequest) request.argument;
1785 Phone phone = getPhoneFromRequest(request);
1786 if (phone != null) {
1787 phone.setDataThrottling(onCompleted,
1788 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1789 dataThrottlingRequest.getCompletionDurationMillis());
1790 } else {
1791 loge("setDataThrottling: No phone object");
1792 request.result =
1793 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1794 notifyRequester(request);
1795 }
1796
1797 break;
1798 }
1799 case EVENT_SET_DATA_THROTTLING_DONE:
1800 ar = (AsyncResult) msg.obj;
1801 request = (MainThreadRequest) ar.userObj;
1802
1803 if (ar.exception == null) {
1804 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1805 } else if (ar.exception instanceof CommandException) {
1806 loge("setDataThrottling: CommandException: " + ar.exception);
1807 CommandException.Error error =
1808 ((CommandException) (ar.exception)).getCommandError();
1809
1810 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1811 request.result = TelephonyManager
1812 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1813 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1814 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001815 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1816 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001817 } else {
1818 request.result =
1819 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1820 }
1821 } else {
1822 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1823 }
1824 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1825 notifyRequester(request);
1826 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001827
1828 case CMD_SET_SIM_POWER: {
1829 request = (MainThreadRequest) msg.obj;
1830 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1831 request = (MainThreadRequest) msg.obj;
1832 int stateToSet =
1833 ((Pair<Integer, IIntegerConsumer>)
1834 request.argument).first;
1835 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1836 break;
1837 }
1838 case EVENT_SET_SIM_POWER_DONE: {
1839 ar = (AsyncResult) msg.obj;
1840 request = (MainThreadRequest) ar.userObj;
1841 IIntegerConsumer callback =
1842 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1843 if (ar.exception != null) {
1844 loge("setSimPower exception: " + ar.exception);
1845 int errorCode = TelephonyManager.CallForwardingInfoCallback
1846 .RESULT_ERROR_UNKNOWN;
1847 if (ar.exception instanceof CommandException) {
1848 CommandException.Error error =
1849 ((CommandException) (ar.exception)).getCommandError();
1850 if (error == CommandException.Error.SIM_ERR) {
1851 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1852 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1853 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1854 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1855 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1856 } else {
1857 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1858 }
1859 }
1860 try {
1861 callback.accept(errorCode);
1862 } catch (RemoteException e) {
1863 // Ignore if the remote process is no longer available to call back.
1864 Log.w(LOG_TAG, "setSimPower: callback not available.");
1865 }
1866 } else {
1867 try {
1868 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1869 } catch (RemoteException e) {
1870 // Ignore if the remote process is no longer available to call back.
1871 Log.w(LOG_TAG, "setSimPower: callback not available.");
1872 }
1873 }
1874 break;
1875 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001876 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1877 request = (MainThreadRequest) msg.obj;
1878
1879 final Phone phone = getPhoneFromRequest(request);
1880 if (phone == null || phone.getServiceStateTracker() == null) {
1881 request.result = new IllegalStateException("Phone or SST is null");
1882 notifyRequester(request);
1883 break;
1884 }
1885
1886 Pair<Integer, SignalStrengthUpdateRequest> pair =
1887 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1888 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1889 request);
1890 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1891 request.subId, pair.first /*callingUid*/,
1892 pair.second /*request*/, onCompleted);
1893 break;
1894 }
1895 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 // request.result will be the exception of ar if present, true otherwise.
1899 // Be cautious not to leave result null which will wait() forever
1900 request.result = ar.exception != null ? ar.exception : true;
1901 notifyRequester(request);
1902 break;
1903 }
1904 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1905 request = (MainThreadRequest) msg.obj;
1906
1907 Phone phone = getPhoneFromRequest(request);
1908 if (phone == null || phone.getServiceStateTracker() == null) {
1909 request.result = new IllegalStateException("Phone or SST is null");
1910 notifyRequester(request);
1911 break;
1912 }
1913
1914 Pair<Integer, SignalStrengthUpdateRequest> pair =
1915 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1916 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1917 request);
1918 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1919 request.subId, pair.first /*callingUid*/,
1920 pair.second /*request*/, onCompleted);
1921 break;
1922 }
1923 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1924 ar = (AsyncResult) msg.obj;
1925 request = (MainThreadRequest) ar.userObj;
1926 request.result = ar.exception != null ? ar.exception : true;
1927 notifyRequester(request);
1928 break;
1929 }
Jordan Liu109698e2020-11-24 14:50:34 -08001930
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001931 case CMD_GET_SLICING_CONFIG: {
1932 request = (MainThreadRequest) msg.obj;
1933 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1934 request.phone.getSlicingConfig(onCompleted);
1935 break;
1936 }
1937 case EVENT_GET_SLICING_CONFIG_DONE: {
1938 ar = (AsyncResult) msg.obj;
1939 request = (MainThreadRequest) ar.userObj;
1940 ResultReceiver result = (ResultReceiver) request.argument;
1941
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001942 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001943 Bundle bundle = new Bundle();
1944 int resultCode = 0;
1945 if (ar.exception != null) {
1946 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1947 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001948 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001949 } else if (ar.result == null) {
1950 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001951 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001952 } else {
1953 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001954 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
1955 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001956 }
1957
1958 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001959 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001960 }
1961 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1962 result.send(resultCode, bundle);
1963 notifyRequester(request);
1964 break;
1965 }
1966
Michele Berionne5e411512020-11-13 02:36:59 +00001967 case CMD_PREPARE_UNATTENDED_REBOOT:
1968 request = (MainThreadRequest) msg.obj;
1969 request.result =
1970 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1971 notifyRequester(request);
1972 break;
1973
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 default:
1975 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1976 break;
1977 }
1978 }
Jake Hambye994d462014-02-03 13:10:13 -08001979
Pengquan Menga1bb6272018-09-06 09:59:22 -07001980 private void notifyRequester(MainThreadRequest request) {
1981 synchronized (request) {
1982 request.notifyAll();
1983 }
1984 }
1985
Jake Hambye994d462014-02-03 13:10:13 -08001986 private void handleNullReturnEvent(Message msg, String command) {
1987 AsyncResult ar = (AsyncResult) msg.obj;
1988 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1989 if (ar.exception == null) {
1990 request.result = true;
1991 } else {
1992 request.result = false;
1993 if (ar.exception instanceof CommandException) {
1994 loge(command + ": CommandException: " + ar.exception);
1995 } else {
1996 loge(command + ": Unknown exception");
1997 }
1998 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001999 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002000 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 }
2002
2003 /**
2004 * Posts the specified command to be executed on the main thread,
2005 * waits for the request to complete, and returns the result.
2006 * @see #sendRequestAsync
2007 */
2008 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002009 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2010 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002011 }
2012
2013 /**
2014 * Posts the specified command to be executed on the main thread,
2015 * waits for the request to complete, and returns the result.
2016 * @see #sendRequestAsync
2017 */
2018 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2019 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002020 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002021 }
2022
2023 /**
2024 * Posts the specified command to be executed on the main thread,
2025 * waits for the request to complete, and returns the result.
2026 * @see #sendRequestAsync
2027 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002028 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002029 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2030 }
2031
2032 /**
2033 * Posts the specified command to be executed on the main thread,
2034 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2035 * if not timeout or null otherwise.
2036 * @see #sendRequestAsync
2037 */
2038 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2039 long timeoutInMs) {
2040 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002041 }
2042
2043 /**
2044 * Posts the specified command to be executed on the main thread,
2045 * waits for the request to complete, and returns the result.
2046 * @see #sendRequestAsync
2047 */
Nathan Harold92bed182018-10-12 18:16:49 -07002048 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002049 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002050 }
2051
2052 /**
2053 * Posts the specified command to be executed on the main thread,
2054 * waits for the request to complete, and returns the result.
2055 * @see #sendRequestAsync
2056 */
2057 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002058 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2059 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002060 }
2061
2062 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002063 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2064 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2065 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002066 * @see #sendRequestAsync
2067 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002068 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2069 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2071 throw new RuntimeException("This method will deadlock if called from the main thread.");
2072 }
2073
Nathan Harold92bed182018-10-12 18:16:49 -07002074 MainThreadRequest request = null;
2075 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2076 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2077 } else if (phone != null) {
2078 request = new MainThreadRequest(argument, phone, workSource);
2079 } else {
2080 request = new MainThreadRequest(argument, subId, workSource);
2081 }
2082
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 Message msg = mMainThreadHandler.obtainMessage(command, request);
2084 msg.sendToTarget();
2085
Rambo Wang0f050d82021-02-12 11:43:36 -08002086
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002088 if (timeoutInMs >= 0) {
2089 // Wait for at least timeoutInMs before returning null request result
2090 long now = SystemClock.elapsedRealtime();
2091 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002092 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002093 try {
2094 request.wait(deadline - now);
2095 } catch (InterruptedException e) {
2096 // Do nothing, go back and check if request is completed or timeout
2097 } finally {
2098 now = SystemClock.elapsedRealtime();
2099 }
2100 }
2101 } else {
2102 // Wait for the request to complete
2103 while (request.result == null) {
2104 try {
2105 request.wait();
2106 } catch (InterruptedException e) {
2107 // Do nothing, go back and wait until the request is complete
2108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110 }
2111 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002112 if (request.result == null) {
2113 Log.wtf(LOG_TAG,
2114 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 return request.result;
2117 }
2118
2119 /**
2120 * Asynchronous ("fire and forget") version of sendRequest():
2121 * Posts the specified command to be executed on the main thread, and
2122 * returns immediately.
2123 * @see #sendRequest
2124 */
2125 private void sendRequestAsync(int command) {
2126 mMainThreadHandler.sendEmptyMessage(command);
2127 }
2128
2129 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002130 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002131 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002132 */
2133 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002134 sendRequestAsync(command, argument, null, null);
2135 }
2136
2137 /**
2138 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2139 * @see {@link #sendRequest(int,Object)}
2140 */
2141 private void sendRequestAsync(
2142 int command, Object argument, Phone phone, WorkSource workSource) {
2143 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002144 Message msg = mMainThreadHandler.obtainMessage(command, request);
2145 msg.sendToTarget();
2146 }
2147
2148 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 * Initialize the singleton PhoneInterfaceManager instance.
2150 * This is only done once, at startup, from PhoneApp.onCreate().
2151 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002152 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 synchronized (PhoneInterfaceManager.class) {
2154 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002155 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 } else {
2157 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2158 }
2159 return sInstance;
2160 }
2161 }
2162
2163 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002164 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002167 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002168 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002170 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002172 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002173 mTelephonySharedPreferences =
2174 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002175 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002176 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002177 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002178 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002179
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 publish();
2181 }
2182
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002183 private Phone getDefaultPhone() {
2184 Phone thePhone = getPhone(getDefaultSubscription());
2185 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2186 }
2187
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 private void publish() {
2189 if (DBG) log("publish: " + this);
2190
Peter Wangc035ce42020-01-08 21:00:22 -08002191 TelephonyFrameworkInitializer
2192 .getTelephonyServiceManager()
2193 .getTelephonyServiceRegisterer()
2194 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 }
2196
Stuart Scott584921c2015-01-15 17:10:34 -08002197 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002198 if (request.phone != null) {
2199 return request.phone;
2200 } else {
2201 return getPhoneFromSubId(request.subId);
2202 }
2203 }
2204
2205 private Phone getPhoneFromSubId(int subId) {
2206 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2207 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002208 }
2209
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002210 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2211 Phone phone = getPhoneFromRequest(request);
2212 return phone == null ? null :
2213 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2214 }
2215
Wink Saville36469e72014-06-11 15:17:00 -07002216 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002217 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002218 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220
Kai Shif70f46f2021-03-03 13:59:46 -08002221 private void sendEraseModemConfig(@NonNull Phone phone) {
2222 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2223 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2224 }
2225
2226 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2227 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2228 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002229 }
2230
Peter Wang44b186e2020-01-13 23:33:09 -08002231 private boolean isImsAvailableOnDevice() {
2232 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2233 if (pm == null) {
2234 // For some reason package manger is not available.. This will fail internally anyway,
2235 // so do not throw error and allow.
2236 return true;
2237 }
2238 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2239 }
2240
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002242 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002243 }
2244
Wink Savilleb564aae2014-10-23 10:18:09 -07002245 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 if (DBG) log("dial: " + number);
2247 // No permission check needed here: This is just a wrapper around the
2248 // ACTION_DIAL intent, which is available to any app since it puts up
2249 // the UI before it does anything.
2250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002251 final long identity = Binder.clearCallingIdentity();
2252 try {
2253 String url = createTelUrl(number);
2254 if (url == null) {
2255 return;
2256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258 // PENDING: should we just silently fail if phone is offhook or ringing?
2259 PhoneConstants.State state = mCM.getState(subId);
2260 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2261 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2262 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2263 mApp.startActivity(intent);
2264 }
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268 }
2269
2270 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002271 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002272 }
2273
Wink Savilleb564aae2014-10-23 10:18:09 -07002274 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 if (DBG) log("call: " + number);
2276
2277 // This is just a wrapper around the ACTION_CALL intent, but we still
2278 // need to do a permission check since we're calling startActivity()
2279 // from the context of the phone app.
2280 enforceCallPermission();
2281
Jordan Liu1617b712019-07-10 15:06:26 -07002282 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 != AppOpsManager.MODE_ALLOWED) {
2284 return;
2285 }
2286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 String url = createTelUrl(number);
2290 if (url == null) {
2291 return;
2292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294 boolean isValid = false;
2295 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2296 if (slist != null) {
2297 for (SubscriptionInfo subInfoRecord : slist) {
2298 if (subInfoRecord.getSubscriptionId() == subId) {
2299 isValid = true;
2300 break;
2301 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002302 }
Wink Saville08874612014-08-31 19:19:58 -07002303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002304 if (!isValid) {
2305 return;
2306 }
Wink Saville08874612014-08-31 19:19:58 -07002307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002308 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2309 intent.putExtra(SUBSCRIPTION_KEY, subId);
2310 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2311 mApp.startActivity(intent);
2312 } finally {
2313 Binder.restoreCallingIdentity(identity);
2314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 }
2316
Wink Savilleb564aae2014-10-23 10:18:09 -07002317 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002318 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002319 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2320 }
2321
Wink Savilleb564aae2014-10-23 10:18:09 -07002322 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002323 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002324 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2325 }
2326
Wink Savilleb564aae2014-10-23 10:18:09 -07002327 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002329
2330 final long identity = Binder.clearCallingIdentity();
2331 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002332 Phone phone = getPhone(subId);
2333 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002334 checkSimPin.start();
2335 return checkSimPin.unlockSim(null, pin);
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
2338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
Wink Savilleb564aae2014-10-23 10:18:09 -07002341 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343
2344 final long identity = Binder.clearCallingIdentity();
2345 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002346 Phone phone = getPhone(subId);
2347 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348 checkSimPuk.start();
2349 return checkSimPuk.unlockSim(puk, pin);
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
2352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
2355 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002356 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 * a synchronous one.
2358 */
2359 private static class UnlockSim extends Thread {
2360
2361 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002362 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363
2364 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002365 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2366 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367
2368 // For replies from SimCard interface
2369 private Handler mHandler;
2370
2371 // For async handler to identify request type
2372 private static final int SUPPLY_PIN_COMPLETE = 100;
2373
Michele Berionne5e411512020-11-13 02:36:59 +00002374 UnlockSim(int phoneId, IccCard simCard) {
2375 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 mSimCard = simCard;
2377 }
2378
2379 @Override
2380 public void run() {
2381 Looper.prepare();
2382 synchronized (UnlockSim.this) {
2383 mHandler = new Handler() {
2384 @Override
2385 public void handleMessage(Message msg) {
2386 AsyncResult ar = (AsyncResult) msg.obj;
2387 switch (msg.what) {
2388 case SUPPLY_PIN_COMPLETE:
2389 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2390 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002391 mRetryCount = msg.arg1;
2392 if (ar.exception != null) {
2393 if (ar.exception instanceof CommandException &&
2394 ((CommandException)(ar.exception)).getCommandError()
2395 == CommandException.Error.PASSWORD_INCORRECT) {
2396 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002397 } //When UiccCardApp dispose,handle message and return exception
2398 else if (ar.exception instanceof CommandException &&
2399 ((CommandException) (ar.exception)).getCommandError()
2400 == CommandException.Error.ABORTED) {
2401 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002402 } else {
2403 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2404 }
2405 } else {
2406 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 mDone = true;
2409 UnlockSim.this.notifyAll();
2410 }
2411 break;
2412 }
2413 }
2414 };
2415 UnlockSim.this.notifyAll();
2416 }
2417 Looper.loop();
2418 }
2419
2420 /*
2421 * Use PIN or PUK to unlock SIM card
2422 *
2423 * If PUK is null, unlock SIM card with PIN
2424 *
2425 * If PUK is not null, unlock SIM card with PUK and set PIN code
2426 */
Wink Saville9de0f752013-10-22 19:04:03 -07002427 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428
2429 while (mHandler == null) {
2430 try {
2431 wait();
2432 } catch (InterruptedException e) {
2433 Thread.currentThread().interrupt();
2434 }
2435 }
2436 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2437
2438 if (puk == null) {
2439 mSimCard.supplyPin(pin, callback);
2440 } else {
2441 mSimCard.supplyPuk(puk, pin, callback);
2442 }
2443
2444 while (!mDone) {
2445 try {
2446 Log.d(LOG_TAG, "wait for done");
2447 wait();
2448 } catch (InterruptedException e) {
2449 // Restore the interrupted status
2450 Thread.currentThread().interrupt();
2451 }
2452 }
2453 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002454 int[] resultArray = new int[2];
2455 resultArray[0] = mResult;
2456 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002457
2458 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2459 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2460 }
2461
Wink Saville9de0f752013-10-22 19:04:03 -07002462 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464 }
2465
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002466 /**
2467 * This method has been removed due to privacy and stability concerns.
2468 */
2469 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002471 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2472 return;
Wink Saville36469e72014-06-11 15:17:00 -07002473 }
2474
Nathan Harold1f889d82020-06-04 17:05:26 -07002475 @Override
2476 public void updateServiceLocationWithPackageName(String callingPackage) {
2477 mApp.getSystemService(AppOpsManager.class)
2478 .checkPackage(Binder.getCallingUid(), callingPackage);
2479
Nathan Haroldf096d982020-11-18 17:18:06 -08002480 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002481 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2482 // Callers targeting S have no business invoking this method.
2483 return;
2484 }
2485
2486 LocationAccessPolicy.LocationPermissionResult locationResult =
2487 LocationAccessPolicy.checkLocationPermission(mApp,
2488 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2489 .setCallingPackage(callingPackage)
2490 .setCallingFeatureId(null)
2491 .setCallingPid(Binder.getCallingPid())
2492 .setCallingUid(Binder.getCallingUid())
2493 .setMethod("updateServiceLocation")
2494 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2495 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2496 .build());
2497 // Apps that lack location permission have no business calling this method;
2498 // however, because no permission was declared in the public API, denials must
2499 // all be "soft".
2500 switch (locationResult) {
2501 case DENIED_HARD: /* fall through */
2502 case DENIED_SOFT:
2503 return;
2504 }
2505
2506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 final long identity = Binder.clearCallingIdentity();
2508 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002509 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002511 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 }
2513 } finally {
2514 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 }
2517
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002518 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002519 @Override
2520 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002521 return isRadioOnWithFeature(callingPackage, null);
2522 }
2523
2524
2525 @Override
2526 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2527 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2528 callingFeatureId);
2529 }
2530
2531 @Deprecated
2532 @Override
2533 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2534 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002535 }
2536
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002538 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2539 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002541 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002542 return false;
2543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 return isRadioOnForSubscriber(subId);
2548 } finally {
2549 Binder.restoreCallingIdentity(identity);
2550 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002551 }
2552
2553 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 final Phone phone = getPhone(subId);
2557 if (phone != null) {
2558 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2559 } else {
2560 return false;
2561 }
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 }
2566
2567 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002568 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 }
Wink Saville36469e72014-06-11 15:17:00 -07002570
Wink Savilleb564aae2014-10-23 10:18:09 -07002571 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone phone = getPhone(subId);
2577 if (phone != null) {
2578 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2579 }
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002582 }
Wink Saville36469e72014-06-11 15:17:00 -07002583 }
2584
2585 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002586 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Wink Savilleb564aae2014-10-23 10:18:09 -07002589 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591
2592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = getPhone(subId);
2595 if (phone == null) {
2596 return false;
2597 }
2598 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2599 toggleRadioOnOffForSubscriber(subId);
2600 }
2601 return true;
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 }
Wink Saville36469e72014-06-11 15:17:00 -07002606
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002607 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002608 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002609 /*
2610 * If any of the Radios are available, it will need to be
2611 * shutdown. So return true if any Radio is available.
2612 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2616 Phone phone = PhoneFactory.getPhone(i);
2617 if (phone != null && phone.isRadioAvailable()) return true;
2618 }
2619 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2620 return false;
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002623 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002624 }
2625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002627 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 enforceModifyPermission();
2629
2630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2633 logv("Shutting down Phone " + i);
2634 shutdownRadioUsingPhoneId(i);
2635 }
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002638 }
2639 }
2640
2641 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002642 Phone phone = PhoneFactory.getPhone(phoneId);
2643 if (phone != null && phone.isRadioAvailable()) {
2644 phone.shutdownRadio();
2645 }
2646 }
2647
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002649 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650
2651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2654 if (defaultPhone != null) {
2655 defaultPhone.setRadioPower(turnOn);
2656 return true;
2657 } else {
2658 loge("There's no default phone.");
2659 return false;
2660 }
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002663 }
Wink Saville36469e72014-06-11 15:17:00 -07002664 }
2665
Wink Savilleb564aae2014-10-23 10:18:09 -07002666 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668
2669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 final Phone phone = getPhone(subId);
2672 if (phone != null) {
2673 phone.setRadioPower(turnOn);
2674 return true;
2675 } else {
2676 return false;
2677 }
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 }
2682
Wink Saville36469e72014-06-11 15:17:00 -07002683 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002684 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 public boolean enableDataConnectivity() {
2686 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 int subId = mSubscriptionController.getDefaultDataSubId();
2691 final Phone phone = getPhone(subId);
2692 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002693 phone.getDataEnabledSettings().setDataEnabled(
2694 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 return true;
2696 } else {
2697 return false;
2698 }
2699 } finally {
2700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 }
2703
Wink Saville36469e72014-06-11 15:17:00 -07002704 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002705 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 public boolean disableDataConnectivity() {
2707 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 int subId = mSubscriptionController.getDefaultDataSubId();
2712 final Phone phone = getPhone(subId);
2713 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002714 phone.getDataEnabledSettings().setDataEnabled(
2715 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 return true;
2717 } else {
2718 return false;
2719 }
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002726 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 final Phone phone = getPhone(subId);
2730 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002731 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 } else {
2733 return false;
2734 }
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 }
2739
2740 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002741 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002742 }
2743
pkanwarae03a6b2016-11-06 20:37:09 -08002744 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745 enforceCallPermission();
2746
2747 final long identity = Binder.clearCallingIdentity();
2748 try {
2749 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2750 return;
2751 }
2752 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2753 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
pkanwar32d516d2016-10-14 19:37:38 -07002757 };
2758
Wink Savilleb564aae2014-10-23 10:18:09 -07002759 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2765 return false;
2766 }
2767 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002773 /**
2774 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2775 * tag on getCallState Binder call.
2776 */
2777 @Deprecated
2778 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002780 if (CompatChanges.isChangeEnabled(
2781 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2782 Binder.getCallingUid())) {
2783 // Do not allow this API to be called on API version 31+, it should only be
2784 // called on old apps using this Binder call directly.
2785 throw new SecurityException("This method can only be used for applications "
2786 + "targeting API version 30 or less.");
2787 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002790 Phone phone = getPhone(getDefaultSubscription());
2791 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2792 PhoneConstantConversions.convertCallState(phone.getState());
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
2795 }
2796 }
2797
2798 @Override
2799 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2800 if (CompatChanges.isChangeEnabled(
2801 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2802 Binder.getCallingUid())) {
2803 // Check READ_PHONE_STATE for API version 31+
2804 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2805 featureId, "getCallStateForSubscription")) {
2806 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2807 + "targeting API level 31+.");
2808 }
2809 }
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2814 PhoneConstantConversions.convertCallState(phone.getState());
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 }
2819
Sanket Padawe356d7632015-06-22 14:03:32 -07002820 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002821 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002822 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2823 }
2824
2825 @Override
2826 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 final long identity = Binder.clearCallingIdentity();
2828 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002829 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 if (phone != null) {
2831 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2832 } else {
2833 return PhoneConstantConversions.convertDataState(
2834 PhoneConstants.DataState.DISCONNECTED);
2835 }
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002842 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002843 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2844 }
2845
2846 @Override
2847 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002850 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 if (phone != null) {
2852 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2853 } else {
2854 return TelephonyManager.DATA_ACTIVITY_NONE;
2855 }
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860
2861 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002862 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002864 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002865
2866 LocationAccessPolicy.LocationPermissionResult locationResult =
2867 LocationAccessPolicy.checkLocationPermission(mApp,
2868 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2869 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002870 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002871 .setCallingPid(Binder.getCallingPid())
2872 .setCallingUid(Binder.getCallingUid())
2873 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002874 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002875 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2876 .build());
2877 switch (locationResult) {
2878 case DENIED_HARD:
2879 throw new SecurityException("Not allowed to access cell location");
2880 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002881 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2882 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002885 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002889 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002890 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 } finally {
2892 Binder.restoreCallingIdentity(identity);
2893 }
Svetoslav64fad262015-04-14 14:35:21 -07002894 }
2895
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002897 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002898 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2899 // registered cell info, so return a NULL country instead.
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002902 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2903 // Get default phone in this case.
2904 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2905 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002906 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002908 if (phone == null) return "";
2909 ServiceStateTracker sst = phone.getServiceStateTracker();
2910 if (sst == null) return "";
2911 LocaleTracker lt = sst.getLocaleTracker();
2912 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002913 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002917 }
2918
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002919 /**
2920 * This method was removed due to potential issues caused by performing partial
2921 * updates of service state, and lack of a credible use case.
2922 *
2923 * This has the ability to break the telephony implementation by disabling notification of
2924 * changes in device connectivity. DO NOT USE THIS!
2925 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002926 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 public void enableLocationUpdates() {
2928 mApp.enforceCallingOrSelfPermission(
2929 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002932 /**
2933 * This method was removed due to potential issues caused by performing partial
2934 * updates of service state, and lack of a credible use case.
2935 *
2936 * This has the ability to break the telephony implementation by disabling notification of
2937 * changes in device connectivity. DO NOT USE THIS!
2938 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 @Override
2940 public void disableLocationUpdates() {
2941 mApp.enforceCallingOrSelfPermission(
2942 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002943 }
2944
2945 @Override
2946 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002947 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2948 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002949 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002950 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2951 throw new SecurityException(
2952 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2953 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002954
Jordan Liu1617b712019-07-10 15:06:26 -07002955 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2957 return null;
2958 }
Svetoslav64fad262015-04-14 14:35:21 -07002959
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002960 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002962 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002963 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964
Nathan Haroldf180aac2018-06-01 18:43:55 -07002965 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2966 for (CellInfo ci : info) {
2967 if (ci instanceof CellInfoGsm) {
2968 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2969 } else if (ci instanceof CellInfoWcdma) {
2970 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2971 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002972 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002973 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 }
2975
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002976 private List<CellInfo> getCachedCellInfo() {
2977 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2978 for (Phone phone : PhoneFactory.getPhones()) {
2979 List<CellInfo> info = phone.getAllCellInfo();
2980 if (info != null) cellInfos.addAll(info);
2981 }
2982 return cellInfos;
2983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984
2985 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002986 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002988 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002989
2990 LocationAccessPolicy.LocationPermissionResult locationResult =
2991 LocationAccessPolicy.checkLocationPermission(mApp,
2992 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2993 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002994 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002995 .setCallingPid(Binder.getCallingPid())
2996 .setCallingUid(Binder.getCallingUid())
2997 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002998 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002999 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3000 .build());
3001 switch (locationResult) {
3002 case DENIED_HARD:
3003 throw new SecurityException("Not allowed to access cell info");
3004 case DENIED_SOFT:
3005 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 }
3007
Nathan Haroldf096d982020-11-18 17:18:06 -08003008 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003009 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3010 return getCachedCellInfo();
3011 }
3012
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003013 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003014 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3018 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003019 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003020 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 if (info != null) cellInfos.addAll(info);
3022 }
3023 return cellInfos;
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 }
3027 }
3028
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003029 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003030 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3031 String callingFeatureId) {
3032 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3033 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003034 }
3035
3036 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003037 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3038 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003039 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003040 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003041 }
3042
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003043 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3044 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003045 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003046 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003047
3048 LocationAccessPolicy.LocationPermissionResult locationResult =
3049 LocationAccessPolicy.checkLocationPermission(mApp,
3050 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3051 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003052 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003053 .setCallingPid(Binder.getCallingPid())
3054 .setCallingUid(Binder.getCallingUid())
3055 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003056 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3057 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003058 .build());
3059 switch (locationResult) {
3060 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003061 if (TelephonyPermissions
3062 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003063 // Safetynet logging for b/154934934
3064 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3065 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003066 throw new SecurityException("Not allowed to access cell info");
3067 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003068 if (TelephonyPermissions
3069 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003070 // Safetynet logging for b/154934934
3071 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3072 }
Nathan Harold5320c422019-05-09 10:26:08 -07003073 try {
3074 cb.onCellInfo(new ArrayList<CellInfo>());
3075 } catch (RemoteException re) {
3076 // Drop without consequences
3077 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003078 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003079 }
3080
Nathan Harolda939a962019-05-09 10:13:47 -07003081
3082 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003083 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3084
3085 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3086 }
3087
3088 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003090 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003091 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092
3093 final long identity = Binder.clearCallingIdentity();
3094 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003095 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003099 }
3100
Shishir Agrawala9f32182016-04-12 12:00:16 -07003101 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003102 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003103 Phone phone = PhoneFactory.getPhone(slotIndex);
3104 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003105 return null;
3106 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003107 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003108 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003109 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003110 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003111 return null;
3112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113
3114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 return phone.getImei();
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003120 }
3121
3122 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003123 public String getTypeAllocationCodeForSlot(int slotIndex) {
3124 Phone phone = PhoneFactory.getPhone(slotIndex);
3125 String tac = null;
3126 if (phone != null) {
3127 String imei = phone.getImei();
3128 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3129 }
3130 return tac;
3131 }
3132
3133 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003134 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003135 Phone phone = PhoneFactory.getPhone(slotIndex);
3136 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003137 return null;
3138 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003139
Jeff Davidson913390f2018-02-23 17:11:49 -08003140 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003141 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003142 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003143 return null;
3144 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145
3146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 return phone.getMeid();
3149 } finally {
3150 Binder.restoreCallingIdentity(identity);
3151 }
Jack Yu2af8d712017-03-15 17:14:14 -07003152 }
3153
3154 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003155 public String getManufacturerCodeForSlot(int slotIndex) {
3156 Phone phone = PhoneFactory.getPhone(slotIndex);
3157 String manufacturerCode = null;
3158 if (phone != null) {
3159 String meid = phone.getMeid();
3160 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3161 }
3162 return manufacturerCode;
3163 }
3164
3165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003166 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3167 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003168 Phone phone = PhoneFactory.getPhone(slotIndex);
3169 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003170 return null;
3171 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003172 int subId = phone.getSubId();
3173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003174 mApp, subId, callingPackage, callingFeatureId,
3175 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003176 return null;
3177 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003178
3179 final long identity = Binder.clearCallingIdentity();
3180 try {
3181 return phone.getDeviceSvn();
3182 } finally {
3183 Binder.restoreCallingIdentity(identity);
3184 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003185 }
3186
fionaxu43304da2017-11-27 22:51:16 -08003187 @Override
3188 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 final Phone phone = getPhone(subId);
3192 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
fionaxu43304da2017-11-27 22:51:16 -08003196 }
3197
3198 @Override
3199 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 final Phone phone = getPhone(subId);
3203 return phone == null ? null : phone.getCarrierName();
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
fionaxu43304da2017-11-27 22:51:16 -08003207 }
3208
calvinpanffe225e2018-11-01 19:43:06 +08003209 @Override
chen xu0026ca62019-03-06 15:28:50 -08003210 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 final Phone phone = getPhone(subId);
3214 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003215 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
3219 }
3220
3221 @Override
chen xu0026ca62019-03-06 15:28:50 -08003222 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003226 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
3230 }
3231
chen xu651eec72018-11-11 19:03:44 -08003232 @Override
chen xu864e11c2018-12-06 22:10:03 -08003233 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3234 if (!isSubscriptionMccMnc) {
3235 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3236 }
chen xu651eec72018-11-11 19:03:44 -08003237 final Phone phone = PhoneFactory.getPhone(slotIndex);
3238 if (phone == null) {
3239 return TelephonyManager.UNKNOWN_CARRIER_ID;
3240 }
3241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
3247 }
3248
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003249 //
3250 // Internal helper methods.
3251 //
3252
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003253 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003254 * Make sure the caller is the calling package itself
3255 *
3256 * @throws SecurityException if the caller is not the calling package
3257 */
3258 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3259 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003260 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3261 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003262 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003263 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003264 } catch (PackageManager.NameNotFoundException e) {
3265 // packageUid is -1
3266 }
3267 if (packageUid != callingUid) {
3268 throw new SecurityException(message + ": Package " + callingPackage
3269 + " does not belong to " + callingUid);
3270 }
3271 }
3272
3273 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3275 *
3276 * @throws SecurityException if the caller does not have the required permission
3277 */
3278 private void enforceModifyPermission() {
3279 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3280 }
3281
Shuo Qiancd19c462020-01-16 20:51:11 -08003282 /**
3283 * Make sure the caller is system.
3284 *
3285 * @throws SecurityException if the caller is not system.
3286 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003287 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003288 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3289 throw new SecurityException("Caller must be system");
3290 }
3291 }
3292
Shuo Qian3b6ee772019-11-13 17:43:31 -08003293 private void enforceActiveEmergencySessionPermission() {
3294 mApp.enforceCallingOrSelfPermission(
3295 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3296 }
3297
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003298 /**
3299 * Make sure the caller has the CALL_PHONE permission.
3300 *
3301 * @throws SecurityException if the caller does not have the required permission
3302 */
3303 private void enforceCallPermission() {
3304 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3305 }
3306
paulhu5a773602019-08-23 19:17:33 +08003307 private void enforceSettingsPermission() {
3308 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003309 }
3310
Michele Berionne5e411512020-11-13 02:36:59 +00003311 private void enforceRebootPermission() {
3312 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3313 }
3314
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003315 private String createTelUrl(String number) {
3316 if (TextUtils.isEmpty(number)) {
3317 return null;
3318 }
3319
Jake Hambye994d462014-02-03 13:10:13 -08003320 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 }
3322
Ihab Awadf9e92732013-12-05 18:02:52 -08003323 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003324 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3325 }
3326
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003327 private static void logv(String msg) {
3328 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3329 }
3330
Ihab Awadf9e92732013-12-05 18:02:52 -08003331 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003332 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3333 }
3334
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003335 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003337 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003338 }
3339
Sanket Padawe356d7632015-06-22 14:03:32 -07003340 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003341 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 final Phone phone = PhoneFactory.getPhone(slotIndex);
3345 if (phone == null) {
3346 return PhoneConstants.PHONE_TYPE_NONE;
3347 } else {
3348 return phone.getPhoneType();
3349 }
3350 } finally {
3351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003353 }
3354
3355 /**
3356 * Returns the CDMA ERI icon index to display
3357 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003359 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3360 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3361 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003362 }
3363
Sanket Padawe356d7632015-06-22 14:03:32 -07003364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003365 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3366 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003368 mApp, subId, callingPackage, callingFeatureId,
3369 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003370 return -1;
3371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003372
3373 final long identity = Binder.clearCallingIdentity();
3374 try {
3375 final Phone phone = getPhone(subId);
3376 if (phone != null) {
3377 return phone.getCdmaEriIconIndex();
3378 } else {
3379 return -1;
3380 }
3381 } finally {
3382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003384 }
3385
3386 /**
3387 * Returns the CDMA ERI icon mode,
3388 * 0 - ON
3389 * 1 - FLASHING
3390 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003391 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003392 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3393 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3394 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003395 }
3396
Sanket Padawe356d7632015-06-22 14:03:32 -07003397 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003398 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3399 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003401 mApp, subId, callingPackage, callingFeatureId,
3402 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003403 return -1;
3404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 final Phone phone = getPhone(subId);
3409 if (phone != null) {
3410 return phone.getCdmaEriIconMode();
3411 } else {
3412 return -1;
3413 }
3414 } finally {
3415 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003417 }
3418
3419 /**
3420 * Returns the CDMA ERI text,
3421 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003422 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003423 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3424 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3425 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003426 }
3427
Sanket Padawe356d7632015-06-22 14:03:32 -07003428 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003429 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3430 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003431 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003432 mApp, subId, callingPackage, callingFeatureId,
3433 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003434 return null;
3435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003436
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 final Phone phone = getPhone(subId);
3440 if (phone != null) {
3441 return phone.getCdmaEriText();
3442 } else {
3443 return null;
3444 }
3445 } finally {
3446 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 }
3449
3450 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003451 * Returns the CDMA MDN.
3452 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003453 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003454 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3456 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003457
3458 final long identity = Binder.clearCallingIdentity();
3459 try {
3460 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003461 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462 return phone.getLine1Number();
3463 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465 return null;
3466 }
3467 } finally {
3468 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003469 }
3470 }
3471
3472 /**
3473 * Returns the CDMA MIN.
3474 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003475 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003476 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3478 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 final Phone phone = getPhone(subId);
3483 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3484 return phone.getCdmaMin();
3485 } else {
3486 return null;
3487 }
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003490 }
3491 }
3492
Hall Liud892bec2018-11-30 14:51:45 -08003493 @Override
3494 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3495 INumberVerificationCallback callback, String callingPackage) {
3496 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3497 != PERMISSION_GRANTED) {
3498 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3499 }
3500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3501
3502 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3503 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003504 throw new SecurityException("Calling package must be configured in the device config: "
3505 + "calling package: " + callingPackage
3506 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003507 }
3508
3509 if (range == null) {
3510 throw new NullPointerException("Range must be non-null");
3511 }
3512
3513 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003514 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003515
3516 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3517 }
3518
Junda Liuca05d5d2014-08-14 22:36:34 -07003519 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 * Returns true if CDMA provisioning needs to run.
3521 */
3522 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523 final long identity = Binder.clearCallingIdentity();
3524 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003525 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003526 } finally {
3527 Binder.restoreCallingIdentity(identity);
3528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 }
3530
3531 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003532 * Sets the voice mail number of a given subId.
3533 */
3534 @Override
3535 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003536 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3537 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538
3539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3542 new Pair<String, String>(alphaTag, number), new Integer(subId));
3543 return success;
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003547 }
3548
Ta-wei Yen87c49842016-05-13 21:19:52 -07003549 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003550 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3551 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003552 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3553 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003554 if (!TextUtils.equals(callingPackage, systemDialer)) {
3555 throw new SecurityException("caller must be system dialer");
3556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3561 if (phoneAccountHandle == null) {
3562 return null;
3563 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003564 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 } finally {
3566 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003567 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003568 }
3569
3570 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003571 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3572 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003573 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003575 mApp, subId, callingPackage, callingFeatureId,
3576 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003577 return null;
3578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003580 final long identity = Binder.clearCallingIdentity();
3581 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003582 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003583 } finally {
3584 Binder.restoreCallingIdentity(identity);
3585 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003586 }
3587
3588 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003589 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3590 VisualVoicemailSmsFilterSettings settings) {
3591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592
3593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003596 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003597 } finally {
3598 Binder.restoreCallingIdentity(identity);
3599 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003600 }
3601
3602 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003603 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605
3606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003609 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003613 }
3614
3615 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003616 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3617 String callingPackage, int subId) {
3618 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619
3620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003623 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003627 }
3628
3629 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003630 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003631 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003636 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003640 }
3641
3642 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003643 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3644 String callingAttributionTag, int subId, String number, int port, String text,
3645 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003646 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003647 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003648 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003649 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003650 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3651 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003652 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003653
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003654 /**
fionaxu0152e512016-11-14 13:36:14 -08003655 * Sets the voice activation state of a given subId.
3656 */
3657 @Override
3658 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3660 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661
3662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = getPhone(subId);
3665 if (phone != null) {
3666 phone.setVoiceActivationState(activationState);
3667 } else {
3668 loge("setVoiceActivationState fails with invalid subId: " + subId);
3669 }
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003672 }
3673 }
3674
3675 /**
3676 * Sets the data activation state of a given subId.
3677 */
3678 @Override
3679 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3681 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 final Phone phone = getPhone(subId);
3686 if (phone != null) {
3687 phone.setDataActivationState(activationState);
3688 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003689 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 }
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003693 }
3694 }
3695
3696 /**
3697 * Returns the voice activation state of a given subId.
3698 */
3699 @Override
3700 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702
fionaxu0152e512016-11-14 13:36:14 -08003703 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 if (phone != null) {
3707 return phone.getVoiceActivationState();
3708 } else {
3709 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3710 }
3711 } finally {
3712 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003713 }
3714 }
3715
3716 /**
3717 * Returns the data activation state of a given subId.
3718 */
3719 @Override
3720 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003722
fionaxu0152e512016-11-14 13:36:14 -08003723 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 if (phone != null) {
3727 return phone.getDataActivationState();
3728 } else {
3729 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3730 }
3731 } finally {
3732 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003733 }
3734 }
3735
3736 /**
Wink Saville36469e72014-06-11 15:17:00 -07003737 * Returns the unread count of voicemails for a subId
3738 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003739 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003740 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3741 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003742 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003743 mApp, subId, callingPackage, callingFeatureId,
3744 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003745 return 0;
3746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 final Phone phone = getPhone(subId);
3750 if (phone != null) {
3751 return phone.getVoiceMessageCount();
3752 } else {
3753 return 0;
3754 }
3755 } finally {
3756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003758 }
3759
3760 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003761 * returns true, if the device is in a state where both voice and data
3762 * are supported simultaneously. This can change based on location or network condition.
3763 */
3764 @Override
3765 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 final Phone phone = getPhone(subId);
3769 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3770 } finally {
3771 Binder.restoreCallingIdentity(identity);
3772 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003773 }
3774
3775 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003776 * Send the dialer code if called from the current default dialer or the caller has
3777 * carrier privilege.
3778 * @param inputCode The dialer code to send
3779 */
3780 @Override
3781 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003782 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003783 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003784 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3785 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003786 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003787 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003788 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790
3791 final long identity = Binder.clearCallingIdentity();
3792 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003793 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794 } finally {
3795 Binder.restoreCallingIdentity(identity);
3796 }
fionaxu235cc5e2017-03-06 22:25:57 -08003797 }
3798
Pengquan Menga1bb6272018-09-06 09:59:22 -07003799 @Override
3800 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003801 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003802 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003803 mApp, subId, "getNetworkSelectionMode");
3804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 if (!isActiveSubscription(subId)) {
3807 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3808 }
3809 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003812 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003813 }
3814
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003816 public boolean isInEmergencySmsMode() {
3817 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 for (Phone phone : PhoneFactory.getPhones()) {
3821 if (phone.isInEmergencySmsMode()) {
3822 return true;
3823 }
3824 }
3825 } finally {
3826 Binder.restoreCallingIdentity(identity);
3827 }
3828 return false;
3829 }
3830
shilu366312e2019-12-17 09:28:10 -08003831 /**
3832 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3833 * @param subId The subscription to use to check the configuration.
3834 * @param c The callback that will be used to send the result.
3835 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003836 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003837 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3838 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003839 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003840 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003841
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003842 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3843 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3844 "IMS not available on device.");
3845 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003846 final long token = Binder.clearCallingIdentity();
3847 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003848 int slotId = getSlotIndexOrException(subId);
3849 verifyImsMmTelConfiguredOrThrow(slotId);
3850 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003851 } catch (ImsException e) {
3852 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003853 } finally {
3854 Binder.restoreCallingIdentity(token);
3855 }
3856 }
3857
shilu366312e2019-12-17 09:28:10 -08003858 /**
3859 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3860 * @param subId The subscription to use to check the configuration.
3861 * @param c The callback that will be used to send the result.
3862 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003864 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003865 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003866 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003867 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3868 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3869 }
Meng Wangafbc5852019-09-19 17:37:13 -07003870 final long token = Binder.clearCallingIdentity();
3871 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003872 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3873 .removeRegistrationCallbackForSubscription(c, subId);
3874 } catch (ImsException e) {
3875 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3876 + "is inactive, ignoring unregister.");
3877 // If the subscription is no longer active, just return, since the callback
3878 // will already have been removed internally.
3879 } finally {
3880 Binder.restoreCallingIdentity(token);
3881 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003882 }
3883
Brad Ebingera34a6c22019-10-22 17:36:18 -07003884 /**
3885 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3886 */
3887 @Override
3888 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3889 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3890 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3891 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3892 "IMS not available on device.");
3893 }
3894 final long token = Binder.clearCallingIdentity();
3895 try {
3896 Phone phone = getPhone(subId);
3897 if (phone == null) {
3898 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3899 + subId + "'");
3900 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3901 }
3902 phone.getImsRegistrationState(regState -> {
3903 try {
3904 consumer.accept((regState == null)
3905 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3906 } catch (RemoteException e) {
3907 // Ignore if the remote process is no longer available to call back.
3908 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3909 }
3910 });
3911 } finally {
3912 Binder.restoreCallingIdentity(token);
3913 }
3914 }
3915
3916 /**
3917 * Get the transport type for the IMS service registration state.
3918 */
3919 @Override
3920 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003921 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003922 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003923 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3924 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3925 "IMS not available on device.");
3926 }
3927 final long token = Binder.clearCallingIdentity();
3928 try {
3929 Phone phone = getPhone(subId);
3930 if (phone == null) {
3931 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3932 + subId + "'");
3933 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3934 }
3935 phone.getImsRegistrationTech(regTech -> {
3936 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3937 int regTechConverted = (regTech == null)
3938 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3939 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3940 regTechConverted);
3941 try {
3942 consumer.accept(regTechConverted);
3943 } catch (RemoteException e) {
3944 // Ignore if the remote process is no longer available to call back.
3945 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3946 }
3947 });
3948 } finally {
3949 Binder.restoreCallingIdentity(token);
3950 }
3951 }
3952
shilu366312e2019-12-17 09:28:10 -08003953 /**
3954 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3955 * @param subId The subscription to use to check the configuration.
3956 * @param c The callback that will be used to send the result.
3957 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003958 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003959 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3960 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003961 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003962 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003963 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3964 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3965 "IMS not available on device.");
3966 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003967 final long token = Binder.clearCallingIdentity();
3968 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003969 int slotId = getSlotIndexOrException(subId);
3970 verifyImsMmTelConfiguredOrThrow(slotId);
3971 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003972 } catch (ImsException e) {
3973 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 } finally {
3975 Binder.restoreCallingIdentity(token);
3976 }
3977 }
3978
shilu366312e2019-12-17 09:28:10 -08003979 /**
3980 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3981 * @param subId The subscription to use to check the configuration.
3982 * @param c The callback that will be used to send the result.
3983 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003985 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003986 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003987 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003988 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3989 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3990 }
Meng Wangafbc5852019-09-19 17:37:13 -07003991
3992 final long token = Binder.clearCallingIdentity();
3993 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003994 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003995 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003996 } catch (ImsException e) {
3997 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3998 + "is inactive, ignoring unregister.");
3999 // If the subscription is no longer active, just return, since the callback
4000 // will already have been removed internally.
4001 } finally {
4002 Binder.restoreCallingIdentity(token);
4003 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 }
4005
4006 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004007 public boolean isCapable(int subId, int capability, int regTech) {
4008 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 final long token = Binder.clearCallingIdentity();
4010 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004011 int slotId = getSlotIndexOrException(subId);
4012 verifyImsMmTelConfiguredOrThrow(slotId);
4013 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004014 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4016 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004017 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004018 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4019 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 } finally {
4021 Binder.restoreCallingIdentity(token);
4022 }
4023 }
4024
4025 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004026 public boolean isAvailable(int subId, int capability, int regTech) {
4027 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 final long token = Binder.clearCallingIdentity();
4029 try {
4030 Phone phone = getPhone(subId);
4031 if (phone == null) return false;
4032 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004033 } catch (com.android.ims.ImsException e) {
4034 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4035 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 } finally {
4037 Binder.restoreCallingIdentity(token);
4038 }
4039 }
4040
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004041 /**
4042 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4043 * subscription.
4044 * @param subId The subscription to use to check the configuration.
4045 * @param callback The callback that will be used to send the result.
4046 * @param capability The MmTelFeature capability that will be used to send the result.
4047 * @param transportType The transport type of the MmTelFeature capability.
4048 */
4049 @Override
4050 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4051 int transportType) {
4052 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4053 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4054 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4055 "IMS not available on device.");
4056 }
4057 final long token = Binder.clearCallingIdentity();
4058 try {
4059 int slotId = getSlotIndex(subId);
4060 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4061 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4062 + subId + "'");
4063 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4064 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004065 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004066 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4067 transportType, aBoolean -> {
4068 try {
4069 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4070 } catch (RemoteException e) {
4071 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4072 + "running. Ignore");
4073 }
4074 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004075 } catch (ImsException e) {
4076 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004077 } finally {
4078 Binder.restoreCallingIdentity(token);
4079 }
4080 }
4081
shilu366312e2019-12-17 09:28:10 -08004082 /**
4083 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4084 * @param subId The subscription to use to check the configuration.
4085 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 @Override
4087 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004088 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004089 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004090
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 final long token = Binder.clearCallingIdentity();
4092 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004093 int slotId = getSlotIndexOrException(subId);
4094 verifyImsMmTelConfiguredOrThrow(slotId);
4095 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 } catch (ImsException e) {
4097 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 } finally {
4099 Binder.restoreCallingIdentity(token);
4100 }
4101 }
4102
4103 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004104 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004106 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 final long identity = Binder.clearCallingIdentity();
4108 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004109 int slotId = getSlotIndexOrException(subId);
4110 verifyImsMmTelConfiguredOrThrow(slotId);
4111 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004112 } catch (ImsException e) {
4113 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 } finally {
4115 Binder.restoreCallingIdentity(identity);
4116 }
4117 }
4118
shilu366312e2019-12-17 09:28:10 -08004119 /**
4120 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4121 * @param subId The subscription to use to check the configuration.
4122 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004124 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004125 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004126 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 final long identity = Binder.clearCallingIdentity();
4128 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004129 int slotId = getSlotIndexOrException(subId);
4130 verifyImsMmTelConfiguredOrThrow(slotId);
4131 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004132 } catch (ImsException e) {
4133 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 } finally {
4135 Binder.restoreCallingIdentity(identity);
4136 }
4137 }
4138
4139 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004140 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004142 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 final long identity = Binder.clearCallingIdentity();
4144 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004145 int slotId = getSlotIndexOrException(subId);
4146 verifyImsMmTelConfiguredOrThrow(slotId);
4147 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004148 } catch (ImsException e) {
4149 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 } finally {
4151 Binder.restoreCallingIdentity(identity);
4152 }
4153 }
4154
shilu366312e2019-12-17 09:28:10 -08004155 /**
4156 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4157 * @param subId The subscription to use to check the configuration.
4158 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 @Override
4160 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004161 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004162 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 final long identity = Binder.clearCallingIdentity();
4164 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004165 int slotId = getSlotIndexOrException(subId);
4166 verifyImsMmTelConfiguredOrThrow(slotId);
4167 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004168 } catch (ImsException e) {
4169 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
4173 }
4174
4175 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004176 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004178 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004179 final long identity = Binder.clearCallingIdentity();
4180 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004181 int slotId = getSlotIndexOrException(subId);
4182 verifyImsMmTelConfiguredOrThrow(slotId);
4183 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004184 } catch (ImsException e) {
4185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
4189 }
4190
shilu366312e2019-12-17 09:28:10 -08004191 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004192 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4193 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4194 * @param subId The subscription to use to check the configuration.
4195 */
4196 @Override
4197 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004198 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004199 mApp, subId, "isCrossSimCallingEnabledByUser");
4200 final long identity = Binder.clearCallingIdentity();
4201 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004202 int slotId = getSlotIndexOrException(subId);
4203 verifyImsMmTelConfiguredOrThrow(slotId);
4204 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004205 } catch (ImsException e) {
4206 throw new ServiceSpecificException(e.getCode());
4207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
4210 }
4211
4212 /**
4213 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4214 * Requires MODIFY_PHONE_STATE permission.
4215 * @param subId The subscription to use to check the configuration.
4216 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4217 * false otherwise
4218 */
4219 @Override
4220 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4222 "setCrossSimCallingEnabled");
4223 final long identity = Binder.clearCallingIdentity();
4224 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004225 int slotId = getSlotIndexOrException(subId);
4226 verifyImsMmTelConfiguredOrThrow(slotId);
4227 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004228 } catch (ImsException e) {
4229 throw new ServiceSpecificException(e.getCode());
4230 } finally {
4231 Binder.restoreCallingIdentity(identity);
4232 }
4233 }
4234
4235 /**
shilu366312e2019-12-17 09:28:10 -08004236 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4237 * @param subId The subscription to use to check the configuration.
4238 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004240
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004242 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004243 mApp, subId, "isVoWiFiRoamingSettingEnabled");
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);
4247 verifyImsMmTelConfiguredOrThrow(slotId);
4248 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
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 setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004259 "setVoWiFiRoamingSettingEnabled");
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);
4263 verifyImsMmTelConfiguredOrThrow(slotId);
4264 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004265 } catch (ImsException e) {
4266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
4270 }
4271
4272 @Override
4273 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4275 "setVoWiFiNonPersistent");
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 int slotId = getSlotIndexOrException(subId);
4279 verifyImsMmTelConfiguredOrThrow(slotId);
4280 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004281 } catch (ImsException e) {
4282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
4286 }
4287
shilu366312e2019-12-17 09:28:10 -08004288 /**
4289 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4290 * @param subId The subscription to use to check the configuration.
4291 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 @Override
4293 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004294 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004295 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 final long identity = Binder.clearCallingIdentity();
4297 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 int slotId = getSlotIndexOrException(subId);
4299 verifyImsMmTelConfiguredOrThrow(slotId);
4300 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004301 } catch (ImsException e) {
4302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
4306 }
4307
4308 @Override
4309 public void setVoWiFiModeSetting(int subId, int mode) {
4310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4311 "setVoWiFiModeSetting");
4312 final long identity = Binder.clearCallingIdentity();
4313 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004314 int slotId = getSlotIndexOrException(subId);
4315 verifyImsMmTelConfiguredOrThrow(slotId);
4316 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004317 } catch (ImsException e) {
4318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
4324 @Override
4325 public int getVoWiFiRoamingModeSetting(int subId) {
4326 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4327 final long identity = Binder.clearCallingIdentity();
4328 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004329 int slotId = getSlotIndexOrException(subId);
4330 verifyImsMmTelConfiguredOrThrow(slotId);
4331 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004332 } catch (ImsException e) {
4333 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
4337 }
4338
4339 @Override
4340 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4342 "setVoWiFiRoamingModeSetting");
4343 final long identity = Binder.clearCallingIdentity();
4344 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004345 int slotId = getSlotIndexOrException(subId);
4346 verifyImsMmTelConfiguredOrThrow(slotId);
4347 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004348 } catch (ImsException e) {
4349 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
4353 }
4354
4355 @Override
4356 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4358 "setRttCapabilityEnabled");
4359 final long identity = Binder.clearCallingIdentity();
4360 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004361 int slotId = getSlotIndexOrException(subId);
4362 verifyImsMmTelConfiguredOrThrow(slotId);
4363 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004364 } catch (ImsException e) {
4365 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 } finally {
4367 Binder.restoreCallingIdentity(identity);
4368 }
4369 }
4370
shilu366312e2019-12-17 09:28:10 -08004371 /**
4372 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4373 * @param subId The subscription to use to check the configuration.
4374 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 @Override
4376 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004377 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004378 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 final long identity = Binder.clearCallingIdentity();
4380 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004381 int slotId = getSlotIndexOrException(subId);
4382 verifyImsMmTelConfiguredOrThrow(slotId);
4383 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004384 } catch (ImsException e) {
4385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 } finally {
4387 Binder.restoreCallingIdentity(identity);
4388 }
4389 }
4390
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004391 @Override
4392 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4393 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4394 final long identity = Binder.clearCallingIdentity();
4395 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004396 if (!isImsAvailableOnDevice()) {
4397 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4398 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004399 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004400 int slotId = getSlotIndexOrException(subId);
4401 verifyImsMmTelConfiguredOrThrow(slotId);
4402 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004403 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004404 } catch (ImsException e) {
4405 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
4409 }
4410
4411 @Override
4412 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4413 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4414 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004415 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4416 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4417 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004418 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004419 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004420 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004421 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004422 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4423 + "is inactive, ignoring unregister.");
4424 // If the subscription is no longer active, just return, since the callback will already
4425 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
4429 }
4430
allenwtsu99c623b2020-01-03 18:24:23 +08004431
4432 private void checkModifyPhoneStatePermission(int subId, String message) {
4433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4434 message);
4435 }
4436
4437 private boolean isImsProvisioningRequired(int subId, int capability,
4438 boolean isMmtelCapability) {
4439 Phone phone = getPhone(subId);
4440 if (phone == null) {
4441 loge("phone instance null for subid " + subId);
4442 return false;
4443 }
4444 if (isMmtelCapability) {
4445 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4446 return false;
4447 }
4448 } else {
4449 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4450 return false;
4451 }
4452 }
4453 return true;
4454 }
4455
4456 @Override
4457 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4458 boolean isProvisioned) {
4459 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4460
4461 final long identity = Binder.clearCallingIdentity();
4462 try {
4463 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4464 if (!isImsProvisioningRequired(subId, capability, false)) {
4465 return;
4466 }
4467
4468 // this capability requires provisioning, route to the correct API.
4469 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4470 switch (capability) {
4471 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4472 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4473 ims.setEabProvisioned(isProvisioned);
4474 break;
4475 default: {
4476 throw new IllegalArgumentException("Tried to set provisioning for "
4477 + "rcs capability '" + capability + "', which does not require "
4478 + "provisioning.");
4479 }
4480 }
4481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
4484
4485 }
4486
4487
4488 @Override
4489 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4490 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4491 final long identity = Binder.clearCallingIdentity();
4492 try {
4493 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4494 if (!isImsProvisioningRequired(subId, capability, false)) {
4495 return true;
4496 }
4497
4498 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4499 switch (capability) {
4500 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4501 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4502 return ims.isEabProvisionedOnDevice();
4503
4504 default: {
4505 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4506 + "capability '" + capability + "', which does not require "
4507 + "provisioning.");
4508 }
4509 }
4510
4511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
4514 }
4515
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004516 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004517 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4518 boolean isProvisioned) {
4519 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004520 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4521 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4522 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004523 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4524 }
allenwtsu99c623b2020-01-03 18:24:23 +08004525 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004526 final long identity = Binder.clearCallingIdentity();
4527 try {
4528 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004529 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004530 return;
4531 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004532 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4533 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4534 loge("setImsProvisioningStatusForCapability: called for technology that does "
4535 + "not support provisioning - " + tech);
4536 return;
4537 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004538
4539 // this capability requires provisioning, route to the correct API.
4540 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4541 switch (capability) {
4542 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4543 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4544 ims.setVolteProvisioned(isProvisioned);
4545 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4546 ims.setWfcProvisioned(isProvisioned);
4547 }
4548 break;
4549 }
4550 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4551 // There is currently no difference in VT provisioning type.
4552 ims.setVtProvisioned(isProvisioned);
4553 break;
4554 }
4555 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4556 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4557 // change the capability of the feature instead if needed.
4558 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4559 == isProvisioned) {
4560 // No change in provisioning.
4561 return;
4562 }
4563 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4564 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004565 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004566 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004567 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4568 + ", Exception" + e.getMessage());
4569 }
4570 break;
4571 }
4572 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004573 throw new IllegalArgumentException("Tried to set provisioning for "
4574 + "MmTel capability '" + capability + "', which does not require "
4575 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004576 }
4577 }
4578
4579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
4582 }
4583
4584 @Override
4585 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4586 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004587 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4588 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4589 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004590 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4591 }
4592 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004596 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 return true;
4598 }
4599
Brad Ebinger0d79c572021-04-17 15:20:49 -07004600 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4601 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4602 loge("getImsProvisioningStatusForCapability: called for technology that does "
4603 + "not support provisioning - " + tech);
4604 return true;
4605 }
4606
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004607 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4608 switch (capability) {
4609 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4610 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4611 return ims.isVolteProvisionedOnDevice();
4612 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4613 return ims.isWfcProvisionedOnDevice();
4614 }
4615 // This should never happen, since we are checking tech above to make sure it
4616 // is either LTE or IWLAN.
4617 throw new IllegalArgumentException("Invalid radio technology for voice "
4618 + "capability.");
4619 }
4620 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4621 // There is currently no difference in VT provisioning type.
4622 return ims.isVtProvisionedOnDevice();
4623 }
4624 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4625 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4626 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4627 }
4628 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004629 throw new IllegalArgumentException(
4630 "Tried to get provisioning for MmTel capability '" + capability
4631 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004632 }
4633 }
4634
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639
4640 @Override
4641 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4642 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4643 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4644 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4645 }
4646 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4647 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4648 return (provisionedBits & capability) > 0;
4649 }
4650
4651 @Override
4652 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4653 boolean isProvisioned) {
4654 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4655 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4656 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4657 }
4658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4659 "setProvisioningStatusForCapability");
4660 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4661 // If the current provisioning status for capability already matches isProvisioned,
4662 // do nothing.
4663 if (((provisionedBits & capability) > 0) == isProvisioned) {
4664 return;
4665 }
4666 if (isProvisioned) {
4667 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4668 } else {
4669 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4670 }
4671 }
4672
4673 /**
4674 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4675 * technology. The bitfield should mirror the bitfield defined by
4676 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4677 */
4678 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4679 String key = getMmTelProvisioningKey(subId, tech);
4680 // Default is no capabilities are provisioned.
4681 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4682 }
4683
4684 /**
4685 * Sets the MmTel capability provisioning bitfield (defined by
4686 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4687 * technology specified.
4688 *
4689 * Note: This is a synchronous command and should not be called on UI thread.
4690 */
4691 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4692 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4693 String key = getMmTelProvisioningKey(subId, tech);
4694 editor.putInt(key, newField);
4695 editor.commit();
4696 }
4697
4698 private static String getMmTelProvisioningKey(int subId, int tech) {
4699 // resulting key is provision_ims_mmtel_{subId}_{tech}
4700 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4701 }
4702
4703 /**
4704 * Query CarrierConfig to see if the specified capability requires provisioning for the
4705 * carrier associated with the subscription id.
4706 */
4707 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4708 int capability) {
4709 CarrierConfigManager configManager = new CarrierConfigManager(context);
4710 PersistableBundle c = configManager.getConfigForSubId(subId);
4711 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004712 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004713 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4714 false);
4715 boolean requireVoiceVtProvisioning = c.getBoolean(
4716 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4717
4718 // First check to make sure that the capability requires provisioning.
4719 switch (capability) {
4720 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4721 // intentional fallthrough
4722 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4723 if (requireVoiceVtProvisioning) {
4724 // Voice and Video requires provisioning
4725 return true;
4726 }
4727 break;
4728 }
4729 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4730 if (requireUtProvisioning) {
4731 // UT requires provisioning
4732 return true;
4733 }
4734 break;
4735 }
4736 }
4737 return false;
4738 }
4739
allenwtsu99c623b2020-01-03 18:24:23 +08004740 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4741 int capability) {
4742 CarrierConfigManager configManager = new CarrierConfigManager(context);
4743 PersistableBundle c = configManager.getConfigForSubId(subId);
4744
4745 boolean requireRcsProvisioning = c.getBoolean(
4746 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4747
4748 // First check to make sure that the capability requires provisioning.
4749 switch (capability) {
4750 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4751 // intentional fallthrough
4752 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4753 if (requireRcsProvisioning) {
4754 // OPTION or PRESENCE requires provisioning
4755 return true;
4756 }
4757 break;
4758 }
4759 }
4760 return false;
4761 }
4762
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004763 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004764 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004765 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4766 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4767 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004768 enforceReadPrivilegedPermission("getImsProvisioningInt");
4769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004772 int slotId = getSlotIndex(subId);
4773 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4774 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4775 + subId + "' for key:" + key);
4776 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4777 }
calvinpanb5a34062021-02-08 19:59:36 +08004778 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004779 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004780 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4781 + subId + "' for key:" + key);
4782 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004783 } finally {
4784 Binder.restoreCallingIdentity(identity);
4785 }
4786 }
4787
4788 @Override
4789 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4791 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4792 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004793 enforceReadPrivilegedPermission("getImsProvisioningString");
4794 final long identity = Binder.clearCallingIdentity();
4795 try {
4796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004797 int slotId = getSlotIndex(subId);
4798 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4799 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4800 + subId + "' for key:" + key);
4801 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4802 }
calvinpanb5a34062021-02-08 19:59:36 +08004803 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004804 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004805 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4806 + subId + "' for key:" + key);
4807 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004808 } finally {
4809 Binder.restoreCallingIdentity(identity);
4810 }
4811 }
4812
4813 @Override
4814 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004815 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4816 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4817 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4819 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004820 final long identity = Binder.clearCallingIdentity();
4821 try {
4822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004823 int slotId = getSlotIndex(subId);
4824 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4825 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4826 + subId + "' for key:" + key);
4827 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4828 }
calvinpanb5a34062021-02-08 19:59:36 +08004829 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4830 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004831 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004832 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004833 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004834 } finally {
4835 Binder.restoreCallingIdentity(identity);
4836 }
4837 }
4838
4839 @Override
4840 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004841 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4842 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4843 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4845 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004849 int slotId = getSlotIndex(subId);
4850 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4851 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4852 + subId + "' for key:" + key);
4853 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4854 }
calvinpanb5a34062021-02-08 19:59:36 +08004855 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4856 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004857 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004858 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004859 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
4863 }
4864
Brad Ebinger919631e2021-06-02 17:46:35 -07004865 /**
4866 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4867 * for the given slot ID or no ImsResolver instance has been created.
4868 * @param slotId The slot ID that the IMS service is created for.
4869 * @throws ImsException If there is no ImsService configured for this slot.
4870 */
4871 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4872 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4873 ImsFeature.FEATURE_MMTEL)) {
4874 throw new ImsException("This subscription does not support MMTEL over IMS",
4875 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4876 }
4877 }
4878
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004879 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004880 int slotId = SubscriptionManager.getSlotIndex(subId);
4881 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004882 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4883 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004884 }
4885 return slotId;
4886 }
4887
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 private int getSlotIndex(int subId) {
4889 int slotId = SubscriptionManager.getSlotIndex(subId);
4890 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4891 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4892 }
4893 return slotId;
4894 }
4895
Wink Saville36469e72014-06-11 15:17:00 -07004896 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004897 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004898 */
4899 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004900 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4901 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004902 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004903 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004904 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004905 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004906 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004907 mApp, subId, callingPackage, callingFeatureId,
4908 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004909 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4910 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 final Phone phone = getPhone(subId);
4915 if (phone != null) {
4916 return phone.getServiceState().getDataNetworkType();
4917 } else {
4918 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4919 }
4920 } finally {
4921 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004923 }
4924
4925 /**
4926 * Returns the data network type
4927 */
4928 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004929 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004930 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4931 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004932 }
4933
4934 /**
4935 * Returns the data network type for a subId
4936 */
4937 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004938 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4939 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004941 mApp, subId, callingPackage, callingFeatureId,
4942 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004943 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4944 }
4945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 final long identity = Binder.clearCallingIdentity();
4947 try {
4948 final Phone phone = getPhone(subId);
4949 if (phone != null) {
4950 return phone.getServiceState().getDataNetworkType();
4951 } else {
4952 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4953 }
4954 } finally {
4955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004957 }
4958
4959 /**
Wink Saville36469e72014-06-11 15:17:00 -07004960 * Returns the Voice network type for a subId
4961 */
4962 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004963 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4964 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004966 mApp, subId, callingPackage, callingFeatureId,
4967 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004968 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4969 }
4970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 final long identity = Binder.clearCallingIdentity();
4972 try {
4973 final Phone phone = getPhone(subId);
4974 if (phone != null) {
4975 return phone.getServiceState().getVoiceNetworkType();
4976 } else {
4977 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4978 }
4979 } finally {
4980 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004982 }
4983
4984 /**
4985 * @return true if a ICC card is present
4986 */
4987 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004988 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004989 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4990 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004991 }
4992
4993 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004994 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004995 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004996 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004997 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 final long identity = Binder.clearCallingIdentity();
4999 try {
5000 final Phone phone = PhoneFactory.getPhone(slotIndex);
5001 if (phone != null) {
5002 return phone.getIccCard().hasIccCard();
5003 } else {
5004 return false;
5005 }
5006 } finally {
5007 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005009 }
5010
5011 /**
5012 * Return if the current radio is LTE on CDMA. This
5013 * is a tri-state return value as for a period of time
5014 * the mode may be unknown.
5015 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005016 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005017 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005018 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005019 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005020 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005021 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5022 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5023 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005024 }
5025
Sanket Padawe356d7632015-06-22 14:03:32 -07005026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005027 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5028 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005029 try {
5030 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5031 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005032 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5033 }
5034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 final Phone phone = getPhone(subId);
5038 if (phone == null) {
5039 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5040 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005041 return TelephonyProperties.lte_on_cdma_device()
5042 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 }
5044 } finally {
5045 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005046 }
Wink Saville36469e72014-06-11 15:17:00 -07005047 }
5048
Wink Saville36469e72014-06-11 15:17:00 -07005049 /**
5050 * {@hide}
5051 * Returns Default subId, 0 in the case of single standby.
5052 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005053 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005054 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005055 }
5056
Shishir Agrawala9f32182016-04-12 12:00:16 -07005057 private int getSlotForDefaultSubscription() {
5058 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5059 }
5060
Wink Savilleb564aae2014-10-23 10:18:09 -07005061 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005062 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005063 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005064
Pengquan Menge92a50d2018-09-21 15:54:48 -07005065 private boolean isActiveSubscription(int subId) {
5066 return mSubscriptionController.isActiveSubId(subId);
5067 }
5068
Ihab Awadf2177b72013-11-25 13:33:23 -08005069 /**
5070 * @see android.telephony.TelephonyManager.WifiCallingChoices
5071 */
5072 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 final long identity = Binder.clearCallingIdentity();
5074 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005075 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5077 getWhenToMakeWifiCallsDefaultPreference());
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
5080 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005081 }
5082
5083 /**
5084 * @see android.telephony.TelephonyManager.WifiCallingChoices
5085 */
5086 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005090 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5092 } finally {
5093 Binder.restoreCallingIdentity(identity);
5094 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005095 }
5096
Sailesh Nepald1e68152013-12-12 19:08:02 -08005097 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005098 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005099 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005100 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005101
Jordan Liu4c733742019-02-28 12:03:40 -08005102 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5103 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5104 if (phoneId == -1) {
5105 throw new IllegalArgumentException("Given slot index: " + slotIndex
5106 + " does not correspond to an active phone");
5107 }
5108 return PhoneFactory.getPhone(phoneId);
5109 }
5110
Shishir Agrawal566b7612013-10-28 14:41:00 -07005111 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005112 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5113 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5115 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005117 if (DBG) {
5118 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5119 }
5120 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5121 p2);
5122 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005123
Jordan Liu4c733742019-02-28 12:03:40 -08005124
5125 @Override
5126 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5127 int slotIndex, String callingPackage, String aid, int p2) {
5128 enforceModifyPermission();
5129 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5130 if (DBG) {
5131 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5132 }
5133 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5134 callingPackage, aid, p2);
5135 }
5136
5137 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5138 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 final long identity = Binder.clearCallingIdentity();
5140 try {
5141 if (TextUtils.equals(ISDR_AID, aid)) {
5142 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005143 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5144 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 if (bestComponent == null
5146 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5147 loge("The calling package is not allowed to access ISD-R.");
5148 throw new SecurityException(
5149 "The calling package is not allowed to access ISD-R.");
5150 }
Derek Tan740e1672017-06-27 14:56:27 -07005151 }
Derek Tan740e1672017-06-27 14:56:27 -07005152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005154 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5155 null /* workSource */);
5156 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157 return response;
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005161 }
5162
5163 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005164 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5166 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005167 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5168 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5169 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005170
Jordan Liu4c733742019-02-28 12:03:40 -08005171 @Override
5172 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5173 enforceModifyPermission();
5174 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5175 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5176 channel);
5177 }
5178
5179 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 final long identity = Binder.clearCallingIdentity();
5181 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 if (channel < 0) {
5183 return false;
5184 }
Jordan Liu4c733742019-02-28 12:03:40 -08005185 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5186 null /* workSource */);
5187 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 return success;
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005191 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005192 }
5193
5194 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005195 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005196 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5198 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005199 if (DBG) {
5200 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5201 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5202 + p3 + " data=" + data);
5203 }
5204 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5205 command, p1, p2, p3, data);
5206 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005207
Jordan Liu4c733742019-02-28 12:03:40 -08005208 @Override
5209 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5210 int command, int p1, int p2, int p3, String data) {
5211 enforceModifyPermission();
5212 if (DBG) {
5213 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5214 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5215 + p3 + " data=" + data);
5216 }
5217 return iccTransmitApduLogicalChannelWithPermission(
5218 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5219 data);
5220 }
5221
5222 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5223 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005226 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 return "";
5228 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005231 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5232 null /* workSource */);
5233 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 // Append the returned status code to the end of the response payload.
5236 String s = Integer.toHexString(
5237 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5238 if (response.payload != null) {
5239 s = IccUtils.bytesToHexString(response.payload) + s;
5240 }
5241 return s;
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005244 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005245 }
Jake Hambye994d462014-02-03 13:10:13 -08005246
Evan Charltonc66da362014-05-16 14:06:40 -07005247 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005248 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5249 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5251 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005253 if (DBG) {
5254 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5255 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5256 }
5257 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5258 cla, command, p1, p2, p3, data);
5259 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005260
Jordan Liu4c733742019-02-28 12:03:40 -08005261 @Override
5262 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5263 int command, int p1, int p2, int p3, String data) {
5264 enforceModifyPermission();
5265 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5266 if (DBG) {
5267 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5268 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5269 + " data=" + data);
5270 }
5271
5272 return iccTransmitApduBasicChannelWithPermission(
5273 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5274 p2, p3, data);
5275 }
5276
5277 // open APDU basic channel assuming the caller has sufficient permissions
5278 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5279 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 final long identity = Binder.clearCallingIdentity();
5281 try {
5282 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5283 && TextUtils.equals(ISDR_AID, data)) {
5284 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005285 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5286 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 if (bestComponent == null
5288 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5289 loge("The calling package is not allowed to select ISD-R.");
5290 throw new SecurityException(
5291 "The calling package is not allowed to select ISD-R.");
5292 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005293 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005296 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5297 null /* workSource */);
5298 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 // Append the returned status code to the end of the response payload.
5301 String s = Integer.toHexString(
5302 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5303 if (response.payload != null) {
5304 s = IccUtils.bytesToHexString(response.payload) + s;
5305 }
5306 return s;
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005309 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005310 }
5311
5312 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005313 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005314 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5316 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318 final long identity = Binder.clearCallingIdentity();
5319 try {
5320 if (DBG) {
5321 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5322 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5323 }
5324
5325 IccIoResult response =
5326 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5327 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5328 subId);
5329
5330 if (DBG) {
5331 log("Exchange SIM_IO [R]" + response);
5332 }
5333
5334 byte[] result = null;
5335 int length = 2;
5336 if (response.payload != null) {
5337 length = 2 + response.payload.length;
5338 result = new byte[length];
5339 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5340 } else {
5341 result = new byte[length];
5342 }
5343
5344 result[length - 1] = (byte) response.sw2;
5345 result[length - 2] = (byte) response.sw1;
5346 return result;
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005349 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005350 }
5351
Nathan Haroldb3014052017-01-25 15:57:32 -08005352 /**
5353 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5354 * on a particular subscription
5355 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005356 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5357 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005359 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005360 return null;
5361 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362
5363 final long identity = Binder.clearCallingIdentity();
5364 try {
5365 if (appType != TelephonyManager.APPTYPE_USIM
5366 && appType != TelephonyManager.APPTYPE_SIM) {
5367 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5368 return null;
5369 }
5370 Object response = sendRequest(
5371 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5372 if (response instanceof String[]) {
5373 return (String[]) response;
5374 }
yincheng zhao2737e882019-09-06 17:06:54 -07005375 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005377 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 } finally {
5379 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005380 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005381 }
5382
yincheng zhao2737e882019-09-06 17:06:54 -07005383 /**
5384 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5385 * subscription.
5386 *
5387 * @param subId the id of the subscription.
5388 * @param appType the uicc app type, must be USIM or SIM.
5389 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5390 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005391 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005392 * @return number of fplmns that is successfully written to the SIM.
5393 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005394 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5395 String callingFeatureId) {
5396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5397 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005398 if (DBG) logv("no permissions for setForbiddenplmns");
5399 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5400 }
5401 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5402 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5403 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5404 }
5405 if (fplmns == null) {
5406 throw new IllegalArgumentException("Fplmn List provided is null");
5407 }
5408 for (String fplmn : fplmns) {
5409 if (!CellIdentity.isValidPlmn(fplmn)) {
5410 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5411 }
5412 }
5413 final long identity = Binder.clearCallingIdentity();
5414 try {
5415 Object response = sendRequest(
5416 CMD_SET_FORBIDDEN_PLMNS,
5417 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5418 subId);
5419 return (int) response;
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
5423 }
5424
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005425 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005426 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5428 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5433 if (response.payload == null) {
5434 return "";
5435 }
Evan Charltonc66da362014-05-16 14:06:40 -07005436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 // Append the returned status code to the end of the response payload.
5438 String s = Integer.toHexString(
5439 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5440 s = IccUtils.bytesToHexString(response.payload) + s;
5441 return s;
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
Evan Charltonc66da362014-05-16 14:06:40 -07005445 }
5446
Jake Hambye994d462014-02-03 13:10:13 -08005447 /**
5448 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5449 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5450 *
5451 * @param itemID the ID of the item to read
5452 * @return the NV item as a String, or null on error.
5453 */
5454 @Override
5455 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005456 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5458 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459
5460 final long identity = Binder.clearCallingIdentity();
5461 try {
5462 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005463 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5465 return value;
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
5468 }
Jake Hambye994d462014-02-03 13:10:13 -08005469 }
5470
5471 /**
5472 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5473 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5474 *
5475 * @param itemID the ID of the item to read
5476 * @param itemValue the value to write, as a String
5477 * @return true on success; false on any failure
5478 */
5479 @Override
5480 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005481 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5483 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484
5485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5488 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005489 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5491 return success;
5492 } finally {
5493 Binder.restoreCallingIdentity(identity);
5494 }
Jake Hambye994d462014-02-03 13:10:13 -08005495 }
5496
5497 /**
5498 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5499 * Used for device configuration by some CDMA operators.
5500 *
5501 * @param preferredRoamingList byte array containing the new PRL
5502 * @return true on success; false on any failure
5503 */
5504 @Override
5505 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5507 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508
5509 final long identity = Binder.clearCallingIdentity();
5510 try {
5511 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5512 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5513 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5514 return success;
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
Jake Hambye994d462014-02-03 13:10:13 -08005518 }
5519
5520 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005521 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005522 * Used for device configuration by some CDMA operators.
5523 *
chen xu6dac5ab2018-10-26 17:39:23 -07005524 * @param slotIndex - device slot.
5525 *
Jake Hambye994d462014-02-03 13:10:13 -08005526 * @return true on success; false on any failure
5527 */
5528 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005529 public boolean resetModemConfig(int slotIndex) {
5530 Phone phone = PhoneFactory.getPhone(slotIndex);
5531 if (phone != null) {
5532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5533 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534
chen xu6dac5ab2018-10-26 17:39:23 -07005535 final long identity = Binder.clearCallingIdentity();
5536 try {
5537 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5538 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5539 return success;
5540 } finally {
5541 Binder.restoreCallingIdentity(identity);
5542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 }
chen xu6dac5ab2018-10-26 17:39:23 -07005544 return false;
5545 }
5546
5547 /**
5548 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5549 *
5550 * @param slotIndex - device slot.
5551 *
5552 * @return true on success; false on any failure
5553 */
5554 @Override
5555 public boolean rebootModem(int slotIndex) {
5556 Phone phone = PhoneFactory.getPhone(slotIndex);
5557 if (phone != null) {
5558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5559 mApp, phone.getSubId(), "rebootModem");
5560
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5564 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5565 return success;
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
5569 }
5570 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005571 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005572
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005573 public String[] getPcscfAddress(String apnType, String callingPackage,
5574 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005575 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5577 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005578 return new String[0];
5579 }
5580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 final long identity = Binder.clearCallingIdentity();
5582 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005583 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
Wink Saville36469e72014-06-11 15:17:00 -07005587 }
5588
Brad Ebinger51f743a2017-01-23 13:50:20 -08005589 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005590 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5591 * {@link #disableIms(int)}.
5592 * @param slotIndex device slot.
5593 */
5594 public void resetIms(int slotIndex) {
5595 enforceModifyPermission();
5596
5597 final long identity = Binder.clearCallingIdentity();
5598 try {
5599 if (mImsResolver == null) {
5600 // may happen if the does not support IMS.
5601 return;
5602 }
5603 mImsResolver.disableIms(slotIndex);
5604 mImsResolver.enableIms(slotIndex);
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
5608 }
5609
5610 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005611 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5612 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005613 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005614 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005615 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616
5617 final long identity = Binder.clearCallingIdentity();
5618 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005619 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005620 // may happen if the device does not support IMS.
5621 return;
5622 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005623 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005627 }
5628
5629 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005630 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5631 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005632 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005633 public void disableIms(int slotId) {
5634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005638 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005639 // may happen if the device does not support IMS.
5640 return;
5641 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005642 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005646 }
5647
5648 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005649 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5650 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005651 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005652 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005653 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005658 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005659 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5660 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005661 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005662 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005666 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005667 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005668 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5669 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005670 @Override
5671 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005672 enforceModifyPermission();
5673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005677 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005678 } finally {
5679 Binder.restoreCallingIdentity(identity);
5680 }
5681 }
5682
5683 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005684 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005685 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005686 */
5687 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689
5690 final long identity = Binder.clearCallingIdentity();
5691 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005692 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005693 // may happen if the device does not support IMS.
5694 return null;
5695 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005696 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005700 }
5701
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005702 /**
5703 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005704 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005705 */
5706 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5707 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708
5709 final long identity = Binder.clearCallingIdentity();
5710 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005711 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005712 // may happen if the device does not support IMS.
5713 return null;
5714 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005715 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005719 }
5720
Brad Ebinger884c07b2018-02-15 16:17:40 -08005721 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005722 * Sets the ImsService Package Name that Telephony will bind to.
5723 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005724 * @param slotIndex the slot ID that the ImsService should bind for.
5725 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005726 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005727 * @param featureTypes An integer array of feature types associated with a packageName.
5728 * @param packageName The name of the package that the current configuration will be replaced
5729 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005730 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005731 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005732 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5733 int[] featureTypes, String packageName) {
5734 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5735 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5737 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005738 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 final long identity = Binder.clearCallingIdentity();
5741 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005742 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005743 // may happen if the device does not support IMS.
5744 return false;
5745 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005746 Map<Integer, String> featureConfig = new HashMap<>();
5747 for (int featureType : featureTypes) {
5748 featureConfig.put(featureType, packageName);
5749 }
5750 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5751 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005755 }
5756
5757 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005758 * Clears any carrier ImsService overrides for the slot index specified that were previously
5759 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5760 *
5761 * This should only be used for testing.
5762 *
5763 * @param slotIndex the slot ID that the ImsService should bind for.
5764 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5765 */
5766 @Override
5767 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5768 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5770 "clearCarrierImsServiceOverride");
5771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5772 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5773 "clearCarrierImsServiceOverride");
5774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 if (mImsResolver == null) {
5778 // may happen if the device does not support IMS.
5779 return false;
5780 }
5781 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
5785 }
5786
5787 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005788 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005789 *
5790 * @param slotId The slot that the ImsService is associated with.
5791 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5792 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005793 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005794 * @return the package name of the ImsService configuration.
5795 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005796 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5797 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005798 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005799 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005800 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005801 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5802 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 final long identity = Binder.clearCallingIdentity();
5805 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005806 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005807 // may happen if the device does not support IMS.
5808 return "";
5809 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005810 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005811 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5812 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005816 }
5817
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005818 /**
5819 * Get the MmTelFeature state associated with the requested subscription id.
5820 * @param subId The subscription that the MmTelFeature is associated with.
5821 * @param callback A callback with an integer containing the
5822 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5823 */
5824 @Override
5825 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5826 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5827 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5828 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5829 "IMS not available on device.");
5830 }
5831 final long token = Binder.clearCallingIdentity();
5832 try {
5833 int slotId = getSlotIndex(subId);
5834 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5835 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5836 + subId + "'");
5837 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5838 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005839 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005840 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5841 try {
5842 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5843 } catch (RemoteException e) {
5844 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5845 + "Ignore");
5846 }
5847 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005848 } catch (ImsException e) {
5849 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005850 } finally {
5851 Binder.restoreCallingIdentity(token);
5852 }
5853 }
5854
Daniel Brightbb5840b2021-01-12 15:48:18 -08005855 /**
5856 * Sets the ims registration state on all valid {@link Phone}s.
5857 */
5858 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005863 // NOTE: Before S, this method only set the default phone.
5864 for (final Phone phone : PhoneFactory.getPhones()) {
5865 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5866 phone.setImsRegistrationState(registered);
5867 }
5868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
Wink Saville36469e72014-06-11 15:17:00 -07005872 }
5873
5874 /**
Stuart Scott54788802015-03-30 13:18:01 -07005875 * Set the network selection mode to automatic.
5876 *
5877 */
5878 @Override
5879 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5881 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
shilufc958392020-01-20 11:36:01 -08005885 if (!isActiveSubscription(subId)) {
5886 return;
5887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005889 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5890 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
Stuart Scott54788802015-03-30 13:18:01 -07005894 }
5895
Jack Yud10cdd42020-09-28 20:28:01 -07005896 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005897 * Ask the radio to connect to the input network and change selection mode to manual.
5898 *
5899 * @param subId the id of the subscription.
5900 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5901 * the operator to attach to.
5902 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5903 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5904 * normal network selection next time.
5905 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005906 */
5907 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005908 public boolean setNetworkSelectionModeManual(
5909 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5911 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005912
5913 if (!isActiveSubscription(subId)) {
5914 return false;
5915 }
5916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 final long identity = Binder.clearCallingIdentity();
5918 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005919 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005921 if (DBG) {
5922 log("setNetworkSelectionModeManual: subId: " + subId
5923 + " operator: " + operatorInfo);
5924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5926 } finally {
5927 Binder.restoreCallingIdentity(identity);
5928 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005929 }
shilu84f6e8b2019-12-19 13:58:01 -08005930 /**
5931 * Get the manual network selection
5932 *
5933 * @param subId the id of the subscription.
5934 *
5935 * @return the previously saved user selected PLMN
5936 */
5937 @Override
5938 public String getManualNetworkSelectionPlmn(int subId) {
5939 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005940 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005941 mApp, subId, "getManualNetworkSelectionPlmn");
5942
5943 final long identity = Binder.clearCallingIdentity();
5944 try {
5945 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005946 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005947 }
5948
5949 final Phone phone = getPhone(subId);
5950 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005951 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005952 }
5953 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5954 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5955 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
5959 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005960
5961 /**
5962 * Scans for available networks.
5963 */
5964 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005965 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5966 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5968 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005969 LocationAccessPolicy.LocationPermissionResult locationResult =
5970 LocationAccessPolicy.checkLocationPermission(mApp,
5971 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5972 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005973 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005974 .setCallingPid(Binder.getCallingPid())
5975 .setCallingUid(Binder.getCallingUid())
5976 .setMethod("getCellNetworkScanResults")
5977 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005978 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5979 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005980 .build());
5981 switch (locationResult) {
5982 case DENIED_HARD:
5983 throw new SecurityException("Not allowed to access scan results -- location");
5984 case DENIED_SOFT:
5985 return null;
5986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987
Pengquan Menga1bb6272018-09-06 09:59:22 -07005988 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 try {
5990 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005991 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 } finally {
5994 Binder.restoreCallingIdentity(identity);
5995 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005996 }
5997
5998 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005999 * Get the call forwarding info, given the call forwarding reason.
6000 */
6001 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006002 public void getCallForwarding(int subId, int callForwardingReason,
6003 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006004 enforceReadPrivilegedPermission("getCallForwarding");
6005 long identity = Binder.clearCallingIdentity();
6006 try {
6007 if (DBG) {
6008 log("getCallForwarding: subId " + subId
6009 + " callForwardingReason" + callForwardingReason);
6010 }
Hall Liu27d24262020-09-18 19:04:59 -07006011
6012 Phone phone = getPhone(subId);
6013 if (phone == null) {
6014 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006015 callback.onError(
6016 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006017 } catch (RemoteException e) {
6018 // ignore
6019 }
6020 return;
6021 }
6022
6023 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6024 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6025 @Override
6026 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6027 try {
6028 callback.onCallForwardingInfoAvailable(info);
6029 } catch (RemoteException e) {
6030 // ignore
6031 }
6032 }
6033
6034 @Override
6035 public void onError(int error) {
6036 try {
6037 callback.onError(error);
6038 } catch (RemoteException e) {
6039 // ignore
6040 }
6041 }
6042 });
6043 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006044 } finally {
6045 Binder.restoreCallingIdentity(identity);
6046 }
6047 }
6048
6049 /**
6050 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6051 * reason, the number to forward, and the timeout before the forwarding is attempted.
6052 */
6053 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006054 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6055 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006056 enforceModifyPermission();
6057 long identity = Binder.clearCallingIdentity();
6058 try {
6059 if (DBG) {
6060 log("setCallForwarding: subId " + subId
6061 + " callForwardingInfo" + callForwardingInfo);
6062 }
Hall Liu27d24262020-09-18 19:04:59 -07006063
6064 Phone phone = getPhone(subId);
6065 if (phone == null) {
6066 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006067 callback.accept(
6068 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006069 } catch (RemoteException e) {
6070 // ignore
6071 }
6072 return;
6073 }
6074
6075 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6076 FunctionalUtils.ignoreRemoteException(callback::accept));
6077
6078 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006079 } finally {
6080 Binder.restoreCallingIdentity(identity);
6081 }
6082 }
6083
6084 /**
Hall Liu27d24262020-09-18 19:04:59 -07006085 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006086 */
6087 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006088 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006089 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006090 long identity = Binder.clearCallingIdentity();
6091 try {
Hall Liu27d24262020-09-18 19:04:59 -07006092 Phone phone = getPhone(subId);
6093 if (phone == null) {
6094 try {
6095 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6096 } catch (RemoteException e) {
6097 // ignore
6098 }
6099 return;
6100 }
SongFerngWang0e767992021-03-31 22:08:45 +08006101 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6102 PersistableBundle c = configManager.getConfigForSubId(subId);
6103 boolean requireUssd = c.getBoolean(
6104 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006105
Shuo Qian4a594052020-01-23 11:59:30 -08006106 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006107 if (requireUssd) {
6108 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6109 getSubscriptionCarrierId(subId));
6110 String newUssdCommand = "";
6111 try {
6112 newUssdCommand = carrierXmlParser.getFeature(
6113 CarrierXmlParser.FEATURE_CALL_WAITING)
6114 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6115 } catch (NullPointerException e) {
6116 loge("Failed to generate USSD number" + e);
6117 }
6118 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6119 mMainThreadHandler, callback, carrierXmlParser,
6120 CarrierXmlParser.SsEntry.SSAction.QUERY);
6121 final String ussdCommand = newUssdCommand;
6122 Executors.newSingleThreadExecutor().execute(() -> {
6123 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6124 });
6125 } else {
6126 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6127 callback::accept);
6128 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6129 }
Shuo Qian4a594052020-01-23 11:59:30 -08006130 } finally {
6131 Binder.restoreCallingIdentity(identity);
6132 }
6133 }
6134
6135 /**
Hall Liu27d24262020-09-18 19:04:59 -07006136 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006137 */
6138 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006139 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006140 enforceModifyPermission();
6141 long identity = Binder.clearCallingIdentity();
6142 try {
Hall Liu27d24262020-09-18 19:04:59 -07006143 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6144
6145 Phone phone = getPhone(subId);
6146 if (phone == null) {
6147 try {
6148 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6149 } catch (RemoteException e) {
6150 // ignore
6151 }
6152 return;
6153 }
6154
SongFerngWang0e767992021-03-31 22:08:45 +08006155 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6156 PersistableBundle c = configManager.getConfigForSubId(subId);
6157 boolean requireUssd = c.getBoolean(
6158 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006159
SongFerngWang0e767992021-03-31 22:08:45 +08006160 if (DBG) log("getCallWaitingStatus: subId " + subId);
6161 if (requireUssd) {
6162 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6163 getSubscriptionCarrierId(subId));
6164 CarrierXmlParser.SsEntry.SSAction ssAction =
6165 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6166 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6167 String newUssdCommand = "";
6168 try {
6169 newUssdCommand = carrierXmlParser.getFeature(
6170 CarrierXmlParser.FEATURE_CALL_WAITING)
6171 .makeCommand(ssAction, null);
6172 } catch (NullPointerException e) {
6173 loge("Failed to generate USSD number" + e);
6174 }
6175 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6176 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6177 final String ussdCommand = newUssdCommand;
6178 Executors.newSingleThreadExecutor().execute(() -> {
6179 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6180 });
6181 } else {
6182 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6183 FunctionalUtils.ignoreRemoteException(callback::accept));
6184
6185 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6186 }
Shuo Qian4a594052020-01-23 11:59:30 -08006187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
yinxub1bed742017-04-17 11:45:04 -07006193 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006194 *
yinxub1bed742017-04-17 11:45:04 -07006195 * @param subId id of the subscription
6196 * @param request contains the radio access networks with bands/channels to scan
6197 * @param messenger callback messenger for scan results or errors
6198 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006199 * @return the id of the requested scan which can be used to stop the scan.
6200 */
6201 @Override
6202 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006203 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6205 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006206 LocationAccessPolicy.LocationPermissionResult locationResult =
6207 LocationAccessPolicy.checkLocationPermission(mApp,
6208 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6209 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006210 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006211 .setCallingPid(Binder.getCallingPid())
6212 .setCallingUid(Binder.getCallingUid())
6213 .setMethod("requestNetworkScan")
6214 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006215 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6216 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006217 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006218 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006219 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6220 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006221 if (e != null) {
6222 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6223 throw e;
6224 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006225 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006226 return TelephonyScanManager.INVALID_SCAN_ID;
6227 }
6228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 }
Hall Liu912dfd32019-04-25 14:02:26 -07006230 int callingUid = Binder.getCallingUid();
6231 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006232 final long identity = Binder.clearCallingIdentity();
6233 try {
6234 return mNetworkScanRequestTracker.startNetworkScan(
6235 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006236 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
yinxu504e1392017-04-12 16:03:22 -07006240 }
6241
Hall Liub2ac8ef2019-02-28 15:56:23 -08006242 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006243 NetworkScanRequest request, int subId, String callingPackage) {
6244 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006245 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6246 boolean hasNetworkScanPermission =
6247 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6248 == PERMISSION_GRANTED;
6249
6250 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6251 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6252 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006253 }
6254
6255 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6256 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006257 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6258 return new SecurityException("Specific channels must not be"
6259 + " scanned without location access.");
6260 }
6261 }
6262 }
6263
Hall Liub2ac8ef2019-02-28 15:56:23 -08006264 return null;
6265 }
6266
yinxu504e1392017-04-12 16:03:22 -07006267 /**
6268 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006269 *
6270 * @param subId id of the subscription
6271 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006272 */
6273 @Override
6274 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6276 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277
Hall Liu912dfd32019-04-25 14:02:26 -07006278 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006279 final long identity = Binder.clearCallingIdentity();
6280 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006281 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 } finally {
6283 Binder.restoreCallingIdentity(identity);
6284 }
yinxu504e1392017-04-12 16:03:22 -07006285 }
6286
6287 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006288 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006289 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006290 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006291 */
6292 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006293 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006294 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006295 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006296 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297
6298 final long identity = Binder.clearCallingIdentity();
6299 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006300 if (DBG) log("getAllowedNetworkTypesBitmask");
6301 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6302 int networkTypesBitmask = (result != null ? result[0] : -1);
6303 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6304 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 } finally {
6306 Binder.restoreCallingIdentity(identity);
6307 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006308 }
6309
6310 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006311 * Get the allowed network types for certain reason.
6312 *
6313 * @param subId the id of the subscription.
6314 * @param reason the reason the allowed network type change is taking place
6315 * @return the allowed network types.
6316 */
6317 @Override
6318 public long getAllowedNetworkTypesForReason(int subId,
6319 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006320 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006321 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006322 final long identity = Binder.clearCallingIdentity();
6323 try {
6324 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
6328 }
6329
6330 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006331 * Enable/Disable E-UTRA-NR Dual Connectivity
6332 * @param subId subscription id of the sim card
6333 * @param nrDualConnectivityState expected NR dual connectivity state
6334 * This can be passed following states
6335 * <ol>
6336 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6337 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6338 * <li>Disable NR dual connectivity and force secondary cell to be released
6339 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6340 * </ol>
6341 * @return operation result.
6342 */
6343 @Override
6344 public int setNrDualConnectivityState(int subId,
6345 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6347 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006348 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006349 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6350 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6351 }
6352
Sooraj Sasindran37444802020-08-11 10:40:43 -07006353 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6354 final long identity = Binder.clearCallingIdentity();
6355 try {
6356 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6357 nrDualConnectivityState, subId,
6358 workSource);
6359 if (DBG) log("enableNRDualConnectivity result: " + result);
6360 return result;
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
6364 }
6365
6366 /**
6367 * Is E-UTRA-NR Dual Connectivity enabled
6368 * @return true if dual connectivity is enabled else false
6369 */
6370 @Override
6371 public boolean isNrDualConnectivityEnabled(int subId) {
6372 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006373 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006374 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006375 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006376 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6377 return false;
6378 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006379 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6383 null, subId, workSource);
6384 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6385 return isEnabled;
6386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
6389 }
6390
6391 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006392 * Set the allowed network types of the device and
6393 * provide the reason triggering the allowed network change.
6394 *
6395 * @param subId the id of the subscription.
6396 * @param reason the reason the allowed network type change is taking place
6397 * @param allowedNetworkTypes the allowed network types.
6398 * @return true on success; false on any failure.
6399 */
6400 @Override
6401 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006402 @TelephonyManager.AllowedNetworkTypesReason int reason,
6403 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6405 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006406 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006407 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6408 return false;
6409 }
6410 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6411 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006412 return false;
6413 }
6414
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006415 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6416 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6417
6418
6419 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6420 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6421 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006422 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006423
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006424 final long identity = Binder.clearCallingIdentity();
6425 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006426 Boolean success = (Boolean) sendRequest(
6427 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6428 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6429
6430 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6431 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
6435 }
6436
6437 /**
Miaoa84611c2019-03-15 09:21:10 +08006438 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006439 *
Miaoa84611c2019-03-15 09:21:10 +08006440 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006441 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006442 * @hide
6443 */
6444 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006445 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006446 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006448 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449 try {
Miaoa84611c2019-03-15 09:21:10 +08006450 if (phone != null) {
6451 return phone.hasMatchedTetherApnSetting();
6452 } else {
6453 return false;
6454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 } finally {
6456 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006457 }
Junda Liu475951f2014-11-07 16:45:03 -08006458 }
6459
6460 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006461 * Enable or disable always reporting signal strength changes from radio.
6462 *
6463 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6464 */
6465 @Override
6466 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6467 enforceModifyPermission();
6468 enforceSystemCaller();
6469
6470 final long identity = Binder.clearCallingIdentity();
6471 final Phone phone = getPhone(subId);
6472 try {
6473 if (phone != null) {
6474 if (DBG) {
6475 log("setAlwaysReportSignalStrength: subId=" + subId
6476 + " isEnable=" + isEnable);
6477 }
6478 phone.setAlwaysReportSignalStrength(isEnable);
6479 } else {
6480 loge("setAlwaysReportSignalStrength: no phone found for subId="
6481 + subId);
6482 }
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
6486 }
6487
6488 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006489 * Get the user enabled state of Mobile Data.
6490 *
6491 * TODO: remove and use isUserDataEnabled.
6492 * This can't be removed now because some vendor codes
6493 * calls through ITelephony directly while they should
6494 * use TelephonyManager.
6495 *
6496 * @return true on enabled
6497 */
6498 @Override
6499 public boolean getDataEnabled(int subId) {
6500 return isUserDataEnabled(subId);
6501 }
6502
6503 /**
6504 * Get whether mobile data is enabled per user setting.
6505 *
6506 * There are other factors deciding whether mobile data is actually enabled, but they are
6507 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006508 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006509 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006510 *
6511 * @return {@code true} if data is enabled else {@code false}
6512 */
6513 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006514 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006515 try {
6516 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6517 null);
6518 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6520 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522
6523 final long identity = Binder.clearCallingIdentity();
6524 try {
6525 int phoneId = mSubscriptionController.getPhoneId(subId);
6526 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6527 Phone phone = PhoneFactory.getPhone(phoneId);
6528 if (phone != null) {
6529 boolean retVal = phone.isUserDataEnabled();
6530 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6531 return retVal;
6532 } else {
6533 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6534 return false;
6535 }
6536 } finally {
6537 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006538 }
6539 }
6540
6541 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006542 * Checks if the device is capable of mobile data by considering whether whether the
6543 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6544 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006545 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006546 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006547 */
6548 @Override
6549 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006550 try {
6551 try {
6552 mApp.enforceCallingOrSelfPermission(
6553 android.Manifest.permission.ACCESS_NETWORK_STATE,
6554 null);
6555 } catch (Exception e) {
6556 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6557 "isDataEnabled");
6558 }
6559 } catch (Exception e) {
6560 enforceReadPrivilegedPermission("isDataEnabled");
6561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562
6563 final long identity = Binder.clearCallingIdentity();
6564 try {
6565 int phoneId = mSubscriptionController.getPhoneId(subId);
6566 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6567 Phone phone = PhoneFactory.getPhone(phoneId);
6568 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006569 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6571 return retVal;
6572 } else {
6573 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6574 return false;
6575 }
6576 } finally {
6577 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006578 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006579 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006580
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006581 /**
6582 * Check if data is enabled for a specific reason
6583 * @param subId Subscription index
6584 * @param reason the reason the data enable change is taking place
6585 * @return {@code true} if the overall data is enabled; {@code false} if not.
6586 */
6587 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006588 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006589 @TelephonyManager.DataEnabledReason int reason) {
6590 try {
6591 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6592 null);
6593 } catch (Exception e) {
6594 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006595 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006596 }
6597
6598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
6601 int phoneId = mSubscriptionController.getPhoneId(subId);
6602 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006603 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006604 + " reason=" + reason);
6605 }
6606 Phone phone = PhoneFactory.getPhone(phoneId);
6607 if (phone != null) {
6608 boolean retVal;
6609 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6610 retVal = phone.isUserDataEnabled();
6611 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006612 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006613 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006614 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006615 return retVal;
6616 } else {
6617 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006618 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006619 + subId + " retVal=false");
6620 }
6621 return false;
6622 }
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
6626 }
6627
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006628 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006629 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006630 if (uid == Process.PHONE_UID) {
6631 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6632 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006633 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6634 }
6635
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006636 //load access rules from carrier configs, and check those as well: b/139133814
6637 SubscriptionController subController = SubscriptionController.getInstance();
6638 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6639 || subController == null) return privilegeFromSim;
6640
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006641 PackageManager pkgMgr = phone.getContext().getPackageManager();
6642 String[] packages = pkgMgr.getPackagesForUid(uid);
6643
6644 final long identity = Binder.clearCallingIdentity();
6645 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006646 int subId = phone.getSubId();
6647 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6648 // A test override is in place for the privileges for this subId, so don't try to
6649 // read the subscription privileges.
6650 return privilegeFromSim;
6651 }
6652 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006653 SubscriptionManager subManager = (SubscriptionManager)
6654 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6655 for (String pkg : packages) {
6656 if (subManager.canManageSubscription(subInfo, pkg)) {
6657 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6658 }
6659 }
6660 return privilegeFromSim;
6661 } finally {
6662 Binder.restoreCallingIdentity(identity);
6663 }
6664 }
6665
6666 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6667 String pkgName) {
6668 //load access rules from carrier configs, and check those as well: b/139133814
6669 SubscriptionController subController = SubscriptionController.getInstance();
6670 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6671 || subController == null) return privilegeFromSim;
6672
6673 final long identity = Binder.clearCallingIdentity();
6674 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006675 int subId = phone.getSubId();
6676 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6677 // A test override is in place for the privileges for this subId, so don't try to
6678 // read the subscription privileges.
6679 return privilegeFromSim;
6680 }
6681 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006682 SubscriptionManager subManager = (SubscriptionManager)
6683 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6684 return subManager.canManageSubscription(subInfo, pkgName)
6685 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
6688 }
6689 }
6690
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006691 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006692 public int getCarrierPrivilegeStatus(int subId) {
6693 final Phone phone = getPhone(subId);
6694 if (phone == null) {
6695 loge("getCarrierPrivilegeStatus: Invalid subId");
6696 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6697 }
6698 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006699 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006700 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006701 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6702 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006703
6704 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6705 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006706 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006707 }
Junda Liu29340342014-07-10 15:23:27 -07006708
6709 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006710 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006711 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006712 final Phone phone = getPhone(subId);
6713 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006714 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006715 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6716 }
6717 UiccProfile profile =
6718 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6719 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006720 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006721 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6722 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006723 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006724 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006725 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006726 }
6727
6728 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006729 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006730 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006731 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006732 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006733 }
6734
6735 int phoneId = SubscriptionManager.getPhoneId(subId);
6736 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006737 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006738 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006739 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6740 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006741 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6742 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6743 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006744 }
6745
6746 @Override
6747 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006748 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006749 if (TextUtils.isEmpty(pkgName))
6750 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006751 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6752 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6753 UiccCard card = UiccController.getInstance().getUiccCard(i);
6754 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006755 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006756 continue;
6757 }
6758
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006759 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6760 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6761 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006762 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6763 break;
6764 }
6765 }
6766
6767 return result;
Junda Liu29340342014-07-10 15:23:27 -07006768 }
Derek Tan89e89d42014-07-08 17:00:10 -07006769
6770 @Override
Junda Liue64de782015-04-16 17:19:16 -07006771 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006772 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006773 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6774 loge("phoneId " + phoneId + " is not valid.");
6775 return null;
6776 }
6777 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006778 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006779 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006780 return null ;
6781 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006782 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006783 }
6784
Amith Yamasani6e118872016-02-19 12:53:51 -08006785 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006786 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006787 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006788 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006789 List<String> privilegedPackages = new ArrayList<>();
6790 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006791 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6792 // has UICC in that slot.
6793 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006794 if (card.hasCarrierPrivilegeRules()) {
6795 if (packages == null) {
6796 // Only check packages in user 0 for now
6797 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006798 PackageManager.MATCH_DISABLED_COMPONENTS
6799 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006800 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006801 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006802 }
6803 for (int p = packages.size() - 1; p >= 0; p--) {
6804 PackageInfo pkgInfo = packages.get(p);
6805 if (pkgInfo != null && pkgInfo.packageName != null
6806 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006807 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006808 privilegedPackages.add(pkgInfo.packageName);
6809 }
6810 }
6811 }
6812 }
6813 return privilegedPackages;
6814 }
6815
chen xuf7e9fe82019-05-09 19:31:02 -07006816 @Override
6817 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006818 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6819
6820 final long identity = Binder.clearCallingIdentity();
6821
chen xuf7e9fe82019-05-09 19:31:02 -07006822 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006823 try {
6824 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6825 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6826 }
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006829 }
6830 return privilegedPackages;
6831 }
6832
Wink Savilleb564aae2014-10-23 10:18:09 -07006833 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006834 final Phone phone = getPhone(subId);
6835 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006836 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006837 return null;
6838 }
6839 String iccId = card.getIccId();
6840 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006841 return null;
6842 }
6843 return iccId;
6844 }
6845
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006846 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006847 public void setCallComposerStatus(int subId, int status) {
6848 enforceModifyPermission();
6849
6850 final long identity = Binder.clearCallingIdentity();
6851 try {
6852 Phone phone = getPhone(subId);
6853 if (phone != null) {
6854 Phone defaultPhone = phone.getImsPhone();
6855 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6856 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6857 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006858 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6859 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006860 }
6861 }
Shuo Qian284ae752020-12-22 19:10:14 -08006862 } catch (ImsException e) {
6863 throw new ServiceSpecificException(e.getCode());
6864 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006865 Binder.restoreCallingIdentity(identity);
6866 }
6867 }
6868
6869 @Override
6870 public int getCallComposerStatus(int subId) {
6871 enforceReadPrivilegedPermission("getCallComposerStatus");
6872
6873 final long identity = Binder.clearCallingIdentity();
6874 try {
6875 Phone phone = getPhone(subId);
6876 if (phone != null) {
6877 Phone defaultPhone = phone.getImsPhone();
6878 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6879 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6880 return imsPhone.getCallComposerStatus();
6881 }
6882 }
6883 } finally {
6884 Binder.restoreCallingIdentity(identity);
6885 }
6886 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6887 }
6888
6889 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006890 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6891 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006892 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006893 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 final long identity = Binder.clearCallingIdentity();
6896 try {
6897 final String iccId = getIccId(subId);
6898 final Phone phone = getPhone(subId);
6899 if (phone == null) {
6900 return false;
6901 }
6902 final String subscriberId = phone.getSubscriberId();
6903
6904 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006905 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 + subscriberId + " to " + number);
6907 }
6908
6909 if (TextUtils.isEmpty(iccId)) {
6910 return false;
6911 }
6912
6913 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6914
6915 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6916 if (alphaTag == null) {
6917 editor.remove(alphaTagPrefKey);
6918 } else {
6919 editor.putString(alphaTagPrefKey, alphaTag);
6920 }
6921
6922 // Record both the line number and IMSI for this ICCID, since we need to
6923 // track all merged IMSIs based on line number
6924 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6925 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6926 if (number == null) {
6927 editor.remove(numberPrefKey);
6928 editor.remove(subscriberPrefKey);
6929 } else {
6930 editor.putString(numberPrefKey, number);
6931 editor.putString(subscriberPrefKey, subscriberId);
6932 }
6933
6934 editor.commit();
6935 return true;
6936 } finally {
6937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006938 }
Derek Tan7226c842014-07-02 17:42:23 -07006939 }
6940
6941 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006942 public String getLine1NumberForDisplay(int subId, String callingPackage,
6943 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006944 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006946 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006947 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006948 return null;
6949 }
Derek Tan97ebb422014-09-05 16:55:38 -07006950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006951 final long identity = Binder.clearCallingIdentity();
6952 try {
6953 String iccId = getIccId(subId);
6954 if (iccId != null) {
6955 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6956 if (DBG_MERGE) {
6957 log("getLine1NumberForDisplay returning "
6958 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6959 }
6960 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006962 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6963 return null;
6964 } finally {
6965 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006966 }
Derek Tan7226c842014-07-02 17:42:23 -07006967 }
6968
6969 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006970 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6971 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006973 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006974 return null;
6975 }
Derek Tan97ebb422014-09-05 16:55:38 -07006976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 String iccId = getIccId(subId);
6980 if (iccId != null) {
6981 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6982 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6983 }
6984 return null;
6985 } finally {
6986 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006987 }
Derek Tan7226c842014-07-02 17:42:23 -07006988 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006989
6990 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006991 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6992 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006993 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6994 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006996 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006997 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006998 return null;
6999 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007000
Jordan Liub49b04b2019-05-06 14:45:15 -07007001 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7002 // the process, where TelephonyManager was instantiated.
7003 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007004 final long identity = Binder.clearCallingIdentity();
7005 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007006 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 final TelephonyManager tele = TelephonyManager.from(context);
7008 final SubscriptionManager sub = SubscriptionManager.from(context);
7009
7010 // Figure out what subscribers are currently active
7011 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012
Jordan Liub49b04b2019-05-06 14:45:15 -07007013 // Only consider subs which match the current subId
7014 // This logic can be simplified. See b/131189269 for progress.
7015 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007016 activeSubscriberIds.add(tele.getSubscriberId(subId));
7017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018
7019 // First pass, find a number override for an active subscriber
7020 String mergeNumber = null;
7021 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7022 for (String key : prefs.keySet()) {
7023 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7024 final String subscriberId = (String) prefs.get(key);
7025 if (activeSubscriberIds.contains(subscriberId)) {
7026 final String iccId = key.substring(
7027 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7028 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7029 mergeNumber = (String) prefs.get(numberKey);
7030 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007031 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 + " for active subscriber " + subscriberId);
7033 }
7034 if (!TextUtils.isEmpty(mergeNumber)) {
7035 break;
7036 }
7037 }
7038 }
7039 }
7040
7041 // Shortcut when no active merged subscribers
7042 if (TextUtils.isEmpty(mergeNumber)) {
7043 return null;
7044 }
7045
7046 // Second pass, find all subscribers under that line override
7047 final ArraySet<String> result = new ArraySet<>();
7048 for (String key : prefs.keySet()) {
7049 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7050 final String number = (String) prefs.get(key);
7051 if (mergeNumber.equals(number)) {
7052 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7053 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7054 final String subscriberId = (String) prefs.get(subscriberKey);
7055 if (!TextUtils.isEmpty(subscriberId)) {
7056 result.add(subscriberId);
7057 }
7058 }
7059 }
7060 }
7061
7062 final String[] resultArray = result.toArray(new String[result.size()]);
7063 Arrays.sort(resultArray);
7064 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007065 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7067 }
7068 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007069 } finally {
7070 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007071 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007072 }
7073
7074 @Override
zoey chen38003472019-12-13 17:16:31 +08007075 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7076 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007077
7078 final long identity = Binder.clearCallingIdentity();
7079 try {
7080 final TelephonyManager telephonyManager = mApp.getSystemService(
7081 TelephonyManager.class);
7082 String subscriberId = telephonyManager.getSubscriberId(subId);
7083 if (subscriberId == null) {
7084 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007085 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007086 + subId);
7087 }
7088 return null;
7089 }
7090
7091 final SubscriptionInfo info = SubscriptionController.getInstance()
7092 .getSubscriptionInfo(subId);
7093 final ParcelUuid groupUuid = info.getGroupUuid();
7094 // If it doesn't belong to any group, return just subscriberId of itself.
7095 if (groupUuid == null) {
7096 return new String[]{subscriberId};
7097 }
7098
7099 // Get all subscriberIds from the group.
7100 final List<String> mergedSubscriberIds = new ArrayList<>();
7101 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007102 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007103 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007104 for (SubscriptionInfo subInfo : groupInfos) {
7105 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7106 if (subscriberId != null) {
7107 mergedSubscriberIds.add(subscriberId);
7108 }
7109 }
7110
7111 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
7114
7115 }
7116 }
7117
7118 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007119 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007120 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007121 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122
7123 final long identity = Binder.clearCallingIdentity();
7124 try {
7125 final Phone phone = getPhone(subId);
7126 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7127 } finally {
7128 Binder.restoreCallingIdentity(identity);
7129 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007130 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007131
7132 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007133 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007134 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7135 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007136 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7137 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 final Phone phone = getPhone(subId);
7142 if (phone == null) {
7143 return false;
7144 }
7145 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7146 cdmaNonRoamingList);
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007149 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007150 }
7151
7152 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007153 @Deprecated
7154 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7155 enforceModifyPermission();
7156
7157 int returnValue = 0;
7158 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007159 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007160 if(result.exception == null) {
7161 if (result.result != null) {
7162 byte[] responseData = (byte[])(result.result);
7163 if(responseData.length > oemResp.length) {
7164 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7165 responseData.length + "bytes. Buffer Size is " +
7166 oemResp.length + "bytes.");
7167 }
7168 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7169 returnValue = responseData.length;
7170 }
7171 } else {
7172 CommandException ex = (CommandException) result.exception;
7173 returnValue = ex.getCommandError().ordinal();
7174 if(returnValue > 0) returnValue *= -1;
7175 }
7176 } catch (RuntimeException e) {
7177 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7178 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7179 if(returnValue > 0) returnValue *= -1;
7180 }
7181
7182 return returnValue;
7183 }
7184
7185 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007186 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007187 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007188 try {
7189 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007190 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007191 mApp, phone.getSubId(), "getRadioAccessFamily");
7192 } catch (SecurityException e) {
7193 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7194 throw e;
7195 }
chen xub97461a2018-10-26 14:17:57 -07007196 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007197 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007198 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007199 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 final long identity = Binder.clearCallingIdentity();
7201 try {
chen xub97461a2018-10-26 14:17:57 -07007202 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007203 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007204 mApp, phone.getSubId(), "getRadioAccessFamily");
7205 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
chen xub97461a2018-10-26 14:17:57 -07007209 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007210 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007211
7212 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007213 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007214 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007215 try {
7216 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7217 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007218 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007219 }
7220 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007221 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007222 }
7223 RoleManager rm = mApp.getSystemService(RoleManager.class);
7224 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7225 if (!dialerRoleHolders.contains(callingPackage)) {
7226 throw new SecurityException("App must be the dialer role holder to"
7227 + " upload a call composer pic");
7228 }
7229
7230 Executors.newSingleThreadExecutor().execute(() -> {
7231 ByteArrayOutputStream output = new ByteArrayOutputStream(
7232 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7233 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7234 boolean readUntilEnd = false;
7235 int totalBytesRead = 0;
7236 byte[] buffer = new byte[16 * 1024];
7237 while (true) {
7238 int numRead;
7239 try {
7240 numRead = input.read(buffer);
7241 } catch (IOException e) {
7242 try {
7243 fd.checkError();
7244 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7245 null);
7246 } catch (IOException e1) {
7247 // This means that the other side closed explicitly with an error. If this
7248 // happens, log and ignore.
7249 loge("Remote end of call composer picture pipe closed: " + e1);
7250 }
7251 break;
7252 }
7253 if (numRead == -1) {
7254 readUntilEnd = true;
7255 break;
7256 }
7257 totalBytesRead += numRead;
7258 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7259 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7260 try {
7261 input.close();
7262 } catch (IOException e) {
7263 // ignore
7264 }
7265 break;
7266 }
7267 output.write(buffer, 0, numRead);
7268 }
7269 // Generally, the remote end will close the file descriptors. The only case where we
7270 // close is above, where the picture size is too big.
7271
7272 try {
7273 fd.checkError();
7274 } catch (IOException e) {
7275 loge("Remote end for call composer closed with an error: " + e);
7276 return;
7277 }
7278
Hall Liuaa4211e2021-01-20 15:43:39 -08007279 if (!readUntilEnd) {
7280 loge("Did not finish reading entire image; aborting");
7281 return;
7282 }
Hall Liu82694d52020-12-11 18:22:04 -08007283
Hall Liuaa4211e2021-01-20 15:43:39 -08007284 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7285 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7286 new CallComposerPictureTransfer.Factory() {},
7287 imageData,
7288 (result) -> {
7289 if (result.first != null) {
7290 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7291 Bundle outputResult = new Bundle();
7292 outputResult.putParcelable(
7293 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7294 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7295 outputResult);
7296 } else {
7297 callback.send(result.second, null);
7298 }
7299 }
7300 );
Hall Liu82694d52020-12-11 18:22:04 -08007301 });
7302 }
7303
7304 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007305 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007306 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007307 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308
7309 final long identity = Binder.clearCallingIdentity();
7310 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007311 ImsManager.getInstance(defaultPhone.getContext(),
7312 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 } finally {
7314 Binder.restoreCallingIdentity(identity);
7315 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007316 }
7317
7318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007319 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007320 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7322 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007323 return false;
7324 }
Svet Ganovb320e182015-04-16 12:30:10 -07007325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 final long identity = Binder.clearCallingIdentity();
7327 try {
7328 // Check the user preference and the system-level IMS setting. Even if the user has
7329 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7330 // In the long run, we may instead need to check if there exists a connection service
7331 // which can support video calling.
7332 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007333 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334 return imsManager.isVtEnabledByPlatform()
7335 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7336 && imsManager.isVtEnabledByUser();
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007340 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007341
Andrew Leea1239f22015-03-02 17:44:07 -08007342 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007343 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7344 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007346 mApp, subId, callingPackage, callingFeatureId,
7347 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348 return false;
7349 }
7350
7351 final long identity = Binder.clearCallingIdentity();
7352 try {
7353 CarrierConfigManager configManager =
7354 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007355 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7357 } finally {
7358 Binder.restoreCallingIdentity(identity);
7359 }
Andrew Leea1239f22015-03-02 17:44:07 -08007360 }
7361
7362 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007363 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007365 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 return false;
7367 }
7368
7369 final long identity = Binder.clearCallingIdentity();
7370 try {
7371 CarrierConfigManager configManager =
7372 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007373 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7375 } finally {
7376 Binder.restoreCallingIdentity(identity);
7377 }
Andrew Leea1239f22015-03-02 17:44:07 -08007378 }
7379
Andrew Lee9431b832015-03-09 18:46:45 -07007380 @Override
7381 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007382 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007383 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007384 }
7385
7386 @Override
7387 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 final long identity = Binder.clearCallingIdentity();
7389 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007390 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 } finally {
7392 Binder.restoreCallingIdentity(identity);
7393 }
Andrew Lee9431b832015-03-09 18:46:45 -07007394 }
7395
Hall Liuf6668912018-10-31 17:05:23 -07007396 /**
7397 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7398 * support for the feature and device firmware support.
7399 *
7400 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7401 */
7402 @Override
7403 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007405 final Phone phone = getPhone(subscriptionId);
7406 if (phone == null) {
7407 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7408 return false;
7409 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007411 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007412 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7413 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007414 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 return isCarrierSupported && isDeviceSupported;
7416 } finally {
7417 Binder.restoreCallingIdentity(identity);
7418 }
Hall Liu98187582018-01-22 19:15:32 -08007419 }
7420
Hall Liuf6668912018-10-31 17:05:23 -07007421 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007422 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7423 * RTT setting, will return true if the device and carrier both support RTT.
7424 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007425 */
7426 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 final long identity = Binder.clearCallingIdentity();
7428 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007429 boolean isRttSupported = isRttSupported(subscriptionId);
7430 boolean isUserRttSettingOn = Settings.Secure.getInt(
7431 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7432 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7433 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7434 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435 } finally {
7436 Binder.restoreCallingIdentity(identity);
7437 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007438 }
7439
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007440 @Deprecated
7441 @Override
7442 public String getDeviceId(String callingPackage) {
7443 return getDeviceIdWithFeature(callingPackage, null);
7444 }
7445
Sanket Padawe7310cc72015-01-14 09:53:20 -08007446 /**
7447 * Returns the unique device ID of phone, for example, the IMEI for
7448 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7449 *
7450 * <p>Requires Permission:
7451 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7452 */
7453 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007454 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007455 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007456 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007457 return null;
7458 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007459 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007460 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007461 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007462 return null;
7463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464
7465 final long identity = Binder.clearCallingIdentity();
7466 try {
7467 return phone.getDeviceId();
7468 } finally {
7469 Binder.restoreCallingIdentity(identity);
7470 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007471 }
7472
Ping Sunc67b7c22016-03-02 19:16:45 +08007473 /**
7474 * {@hide}
7475 * Returns the IMS Registration Status on a particular subid
7476 *
7477 * @param subId
7478 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007479 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007480 Phone phone = getPhone(subId);
7481 if (phone != null) {
7482 return phone.isImsRegistered();
7483 } else {
7484 return false;
7485 }
7486 }
7487
Santos Cordon7a1885b2015-02-03 11:15:19 -08007488 @Override
7489 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 final long identity = Binder.clearCallingIdentity();
7491 try {
7492 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007496 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007497
Tyler Gunnf70ed162019-04-03 15:28:53 -07007498 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007499 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007500 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007502 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007503 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7504 }
7505 final long identity = Binder.clearCallingIdentity();
7506 try {
7507 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
7511 }
7512
7513 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007514 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007515 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007516 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007517 mApp,
7518 subscriptionId,
7519 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007520 final long identity = Binder.clearCallingIdentity();
7521 try {
7522 Phone phone = getPhone(subscriptionId);
7523 if (phone == null) {
7524 return null;
7525 }
7526 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7527 } finally {
7528 Binder.restoreCallingIdentity(identity);
7529 }
7530 }
7531
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007532 /**
7533 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007534 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007535 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 final long identity = Binder.clearCallingIdentity();
7537 try {
7538 Phone phone = getPhone(subId);
7539 if (phone != null) {
7540 return phone.isWifiCallingEnabled();
7541 } else {
7542 return false;
7543 }
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007546 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007547 }
7548
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007549 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007550 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007551 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007552 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 Phone phone = getPhone(subId);
7556 if (phone != null) {
7557 return phone.isVideoEnabled();
7558 } else {
7559 return false;
7560 }
7561 } finally {
7562 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007563 }
7564 }
7565
7566 /**
7567 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7568 * defined in {@link ImsRegistrationImplBase}.
7569 */
7570 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007571 final long identity = Binder.clearCallingIdentity();
7572 try {
7573 Phone phone = getPhone(subId);
7574 if (phone != null) {
7575 return phone.getImsRegistrationTech();
7576 } else {
7577 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7578 }
7579 } finally {
7580 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007581 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007582 }
7583
Stuart Scott8eef64f2015-04-08 15:13:54 -07007584 @Override
7585 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007586 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007587 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7588 return;
7589 }
Kai Shif70f46f2021-03-03 13:59:46 -08007590 Phone defaultPhone = getDefaultPhone();
7591 if (defaultPhone != null) {
7592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7593 mApp, getDefaultPhone().getSubId(), "factoryReset");
7594 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007595 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007596
Svet Ganovcc087f82015-05-12 20:35:54 -07007597 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007598 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7599 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007600 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007601 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007602 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007603 Phone phone = getPhone(subId);
7604 if (phone != null) {
7605 SubscriptionManager.setSubscriptionProperty(subId,
7606 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7607 "user=" + RadioAccessFamily.getRafFromNetworkType(
7608 RILConstants.PREFERRED_NETWORK_MODE));
7609 phone.loadAllowedNetworksFromSubscriptionDatabase();
7610 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007611 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007612 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007613 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007614 // There has been issues when Sms raw table somehow stores orphan
7615 // fragments. They lead to garbled message when new fragments come
7616 // in and combined with those stale ones. In case this happens again,
7617 // user can reset all network settings which will clean up this table.
7618 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007619 // Clean up IMS settings as well here.
7620 int slotId = getSlotIndex(subId);
7621 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7622 ImsManager.getInstance(mApp, slotId).factoryReset();
7623 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007624
Kai Shif70f46f2021-03-03 13:59:46 -08007625 if (defaultPhone == null) {
7626 return;
7627 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007628 // Erase modem config if erase modem on network setting is enabled.
7629 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7630 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7631 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007632 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007633 }
Kai Shif70f46f2021-03-03 13:59:46 -08007634
7635 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007636 } finally {
7637 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007638 }
7639 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007640
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007641 private void cleanUpSmsRawTable(Context context) {
7642 ContentResolver resolver = context.getContentResolver();
7643 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7644 resolver.delete(uri, null, null);
7645 }
7646
Narayan Kamath1c496c22015-04-16 14:40:19 +01007647 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007648 public String getSimLocaleForSubscriber(int subId) {
7649 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7650 final Phone phone = getPhone(subId);
7651 if (phone == null) {
7652 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007653 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007655 final long identity = Binder.clearCallingIdentity();
7656 try {
chen xu5d3637b2019-01-21 23:31:38 -08007657 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007658 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007659 if (info == null) {
7660 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7661 return null;
7662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663 // Try and fetch the locale from the carrier properties or from the SIM language
7664 // preferences (EF-PL and EF-LI)...
7665 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007667 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7668 if (localeFromDefaultSim != null) {
7669 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7670 if (DBG) log("Using locale from subId: " + subId + " locale: "
7671 + localeFromDefaultSim);
7672 return localeFromDefaultSim.toLanguageTag();
7673 } else {
7674 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 }
7676 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 // The SIM language preferences only store a language (e.g. fr = French), not an
7679 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7680 // the SIM and carrier preferences does not include a country we add the country
7681 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007682 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007684 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 return mccLocale.toLanguageTag();
7686 }
7687
7688 if (DBG) log("No locale found - returning null");
7689 return null;
7690 } finally {
7691 Binder.restoreCallingIdentity(identity);
7692 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007693 }
7694
7695 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007696 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007697 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007698 }
7699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 /**
7701 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7702 */
7703 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007704 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007705 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007706 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007707
Chenjie Yu1ba97252018-01-11 18:16:20 -08007708 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007709 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007710
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007711 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007712 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7713 * representing the state of the modem.
7714 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007715 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7716 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007717 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007718 */
7719 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007720 public void requestModemActivityInfo(ResultReceiver result) {
7721 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007722 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723
7724 final long identity = Binder.clearCallingIdentity();
7725 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007726 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 } finally {
7728 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007729 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007730 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007731
Siddharth Rayb8114062018-06-17 15:02:38 -07007732 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7733 // less than total activity duration.
7734 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7735 if (info == null) {
7736 return false;
7737 }
7738 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007739 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7740 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7741
Siddharth Rayb8114062018-06-17 15:02:38 -07007742 return (info.isValid()
7743 && (info.getSleepTimeMillis() <= activityDurationMs)
7744 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007745 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007746 && (totalTxTimeMs <= activityDurationMs));
7747 }
7748
Jack Yu85bd38a2015-11-09 11:34:32 -08007749 /**
7750 * {@hide}
7751 * Returns the service state information on specified subscription.
7752 */
7753 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007754 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7755 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007757 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007758 return null;
7759 }
7760
Hall Liuf19c44f2018-11-27 14:38:17 -08007761 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7762 LocationAccessPolicy.checkLocationPermission(mApp,
7763 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7764 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007765 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007766 .setCallingPid(Binder.getCallingPid())
7767 .setCallingUid(Binder.getCallingUid())
7768 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007769 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007770 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007771 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7772 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007773 .build());
7774
7775 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7776 LocationAccessPolicy.checkLocationPermission(mApp,
7777 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7778 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007779 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007780 .setCallingPid(Binder.getCallingPid())
7781 .setCallingUid(Binder.getCallingUid())
7782 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007783 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007784 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007785 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7786 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007787 .build());
7788 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7789 boolean hasFinePermission =
7790 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7791 boolean hasCoarsePermission =
7792 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7793
Jack Yu479f40e2020-10-27 21:29:25 -07007794 final Phone phone = getPhone(subId);
7795 if (phone == null) {
7796 return null;
7797 }
7798
Jordan Liu0f2bc442020-11-18 16:47:37 -08007799 final long identity = Binder.clearCallingIdentity();
7800
Jack Yu479f40e2020-10-27 21:29:25 -07007801 boolean isCallingPackageDataService = phone.getDataServicePackages()
7802 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007804 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7805 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7806 Rlog.d(LOG_TAG,
7807 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7808 return null;
7809 }
7810
Hall Liuf19c44f2018-11-27 14:38:17 -08007811 ServiceState ss = phone.getServiceState();
7812
7813 // Scrub out the location info in ServiceState depending on what level of access
7814 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007815 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007816 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7817 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 } finally {
7819 Binder.restoreCallingIdentity(identity);
7820 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007821 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007822
7823 /**
7824 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7825 *
7826 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7827 * voicemail ringtone.
7828 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7829 * PhoneAccount.
7830 */
7831 @Override
7832 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007833 final long identity = Binder.clearCallingIdentity();
7834 try {
7835 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7836 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007837 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007840 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007844 }
7845
7846 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007847 * Sets the per-account voicemail ringtone.
7848 *
7849 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7850 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7851 *
7852 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7853 * voicemail ringtone.
7854 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7855 * PhoneAccount.
7856 */
7857 @Override
7858 public void setVoicemailRingtoneUri(String callingPackage,
7859 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007860 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007861 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007862 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7863 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7865 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7866 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007867 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868
7869 final long identity = Binder.clearCallingIdentity();
7870 try {
7871 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7872 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007873 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874 }
7875 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7876 } finally {
7877 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007878 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007879 }
7880
7881 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007882 * Returns whether vibration is set for voicemail notification in Phone settings.
7883 *
7884 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7885 * voicemail vibration setting.
7886 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7887 */
7888 @Override
7889 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007890 final long identity = Binder.clearCallingIdentity();
7891 try {
7892 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7893 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007894 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007897 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7898 } finally {
7899 Binder.restoreCallingIdentity(identity);
7900 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007901 }
7902
Youhan Wange64578a2016-05-02 15:32:42 -07007903 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007904 * Sets the per-account voicemail vibration.
7905 *
7906 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7907 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7908 *
7909 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7910 * voicemail vibration setting.
7911 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7912 * specific PhoneAccount.
7913 */
7914 @Override
7915 public void setVoicemailVibrationEnabled(String callingPackage,
7916 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007917 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007918 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007919 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7920 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7922 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7923 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007924 }
7925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 final long identity = Binder.clearCallingIdentity();
7927 try {
7928 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7929 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007930 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 }
7932 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7933 } finally {
7934 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007935 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007936 }
7937
7938 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007939 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7940 *
7941 * @throws SecurityException if the caller does not have the required permission
7942 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007943 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007944 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007945 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007946 }
7947
7948 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007949 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7950 * permission.
7951 *
7952 * @throws SecurityException if the caller does not have the required permission
7953 */
7954 private void enforceSendSmsPermission() {
7955 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7956 }
7957
7958 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007959 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007960 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007961 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007962 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007963 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964 final long identity = Binder.clearCallingIdentity();
7965 try {
7966 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007967 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 if (componentName == null) {
7969 throw new SecurityException(
7970 "Caller not current active visual voicemail package[null]");
7971 }
7972 String vvmPackage = componentName.getPackageName();
7973 if (!callingPackage.equals(vvmPackage)) {
7974 throw new SecurityException("Caller not current active visual voicemail package["
7975 + vvmPackage + "]");
7976 }
7977 } finally {
7978 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007979 }
7980 }
7981
7982 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007983 * Return the application ID for the app type.
7984 *
7985 * @param subId the subscription ID that this request applies to.
7986 * @param appType the uicc app type.
7987 * @return Application ID for specificied app type, or null if no uicc.
7988 */
7989 @Override
7990 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007991 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007992 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993
7994 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007995 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 if (phone == null) {
7997 return null;
7998 }
7999 String aid = null;
8000 try {
8001 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8002 .getApplicationByType(appType).getAid();
8003 } catch (Exception e) {
8004 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8005 }
8006 return aid;
8007 } finally {
8008 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008009 }
Youhan Wange64578a2016-05-02 15:32:42 -07008010 }
8011
Youhan Wang4001d252016-05-11 10:29:41 -07008012 /**
8013 * Return the Electronic Serial Number.
8014 *
8015 * @param subId the subscription ID that this request applies to.
8016 * @return ESN or null if error.
8017 */
8018 @Override
8019 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008020 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008021 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022
8023 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008024 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 if (phone == null) {
8026 return null;
8027 }
8028 String esn = null;
8029 try {
8030 esn = phone.getEsn();
8031 } catch (Exception e) {
8032 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8033 }
8034 return esn;
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008037 }
Youhan Wang4001d252016-05-11 10:29:41 -07008038 }
8039
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008040 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008041 * Return the Preferred Roaming List Version.
8042 *
8043 * @param subId the subscription ID that this request applies to.
8044 * @return PRLVersion or null if error.
8045 */
8046 @Override
8047 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008048 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008049 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050
8051 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008052 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 if (phone == null) {
8054 return null;
8055 }
8056 String cdmaPrlVersion = null;
8057 try {
8058 cdmaPrlVersion = phone.getCdmaPrlVersion();
8059 } catch (Exception e) {
8060 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8061 }
8062 return cdmaPrlVersion;
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008065 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008066 }
8067
8068 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008069 * Get snapshot of Telephony histograms
8070 * @return List of Telephony histograms
8071 * @hide
8072 */
8073 @Override
8074 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8076 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008077
8078 final long identity = Binder.clearCallingIdentity();
8079 try {
8080 return RIL.getTelephonyRILTimingHistograms();
8081 } finally {
8082 Binder.restoreCallingIdentity(identity);
8083 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008084 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008085
8086 /**
8087 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008088 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8089 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008090 * Require system privileges. In the future we may add this to carrier APIs.
8091 *
Michele Berionne482f8202018-11-27 18:57:59 -08008092 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008093 */
8094 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008095 @TelephonyManager.SetCarrierRestrictionResult
8096 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008097 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008098 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008099
Michele Berionne482f8202018-11-27 18:57:59 -08008100 if (carrierRestrictionRules == null) {
8101 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008102 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 final long identity = Binder.clearCallingIdentity();
8105 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008106 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008107 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 } finally {
8109 Binder.restoreCallingIdentity(identity);
8110 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008111 }
8112
8113 /**
8114 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008115 * Get the allowed carrier list and the excluded carrier list, including the priority between
8116 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008117 * Require system privileges. In the future we may add this to carrier APIs.
8118 *
Michele Berionne482f8202018-11-27 18:57:59 -08008119 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008120 */
8121 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008122 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008123 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008124 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125
8126 final long identity = Binder.clearCallingIdentity();
8127 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008128 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8129 if (response instanceof CarrierRestrictionRules) {
8130 return (CarrierRestrictionRules) response;
8131 }
8132 // Response is an Exception of some kind,
8133 // which is signalled to the user as a NULL retval
8134 return null;
8135 } catch (Exception e) {
8136 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8137 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008138 } finally {
8139 Binder.restoreCallingIdentity(identity);
8140 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008141 }
8142
fionaxu59545b42016-05-25 15:53:37 -07008143 /**
fionaxu59545b42016-05-25 15:53:37 -07008144 * Action set from carrier signalling broadcast receivers to enable/disable radio
8145 * @param subId the subscription ID that this action applies to.
8146 * @param enabled control enable or disable radio.
8147 * {@hide}
8148 */
8149 @Override
8150 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8151 enforceModifyPermission();
8152 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153
8154 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008155 if (phone == null) {
8156 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8157 return;
8158 }
8159 try {
8160 phone.carrierActionSetRadioEnabled(enabled);
8161 } catch (Exception e) {
8162 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008163 } finally {
8164 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008165 }
8166 }
8167
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008168 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008169 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8170 * network status based on which carrier apps could apply actions accordingly,
8171 * enable/disable default url handler for example.
8172 *
8173 * @param subId the subscription ID that this action applies to.
8174 * @param report control start/stop reporting the default network status.
8175 * {@hide}
8176 */
8177 @Override
8178 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8179 enforceModifyPermission();
8180 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181
8182 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008183 if (phone == null) {
8184 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8185 return;
8186 }
8187 try {
8188 phone.carrierActionReportDefaultNetworkStatus(report);
8189 } catch (Exception e) {
8190 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191 } finally {
8192 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008193 }
8194 }
8195
8196 /**
fionaxud9622282017-07-17 17:51:30 -07008197 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8198 * @param subId the subscription ID that this action applies to.
8199 * {@hide}
8200 */
8201 @Override
8202 public void carrierActionResetAll(int subId) {
8203 enforceModifyPermission();
8204 final Phone phone = getPhone(subId);
8205 if (phone == null) {
8206 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8207 return;
8208 }
8209 try {
8210 phone.carrierActionResetAll();
8211 } catch (Exception e) {
8212 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8213 }
8214 }
8215
8216 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008217 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8218 * bug report is being generated.
8219 */
8220 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008221 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008222 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8223 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008224 writer.println("Permission Denial: can't dump Phone from pid="
8225 + Binder.getCallingPid()
8226 + ", uid=" + Binder.getCallingUid()
8227 + "without permission "
8228 + android.Manifest.permission.DUMP);
8229 return;
8230 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008231 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008232 }
Jack Yueb89b242016-06-22 13:27:47 -07008233
Brad Ebingerdac2f002018-04-03 15:17:52 -07008234 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008235 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8236 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8237 @NonNull String[] args) {
8238 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8239 this, in.getFileDescriptor(), out.getFileDescriptor(),
8240 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008241 }
8242
Jack Yueb89b242016-06-22 13:27:47 -07008243 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008244 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008245 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008246 * @param reason the reason the data enable change is taking place
8247 * @param enabled True if enabling the data, otherwise disabling.
8248 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008249 */
8250 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008251 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008252 boolean enabled) {
8253 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8254 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8255 try {
8256 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008257 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008258 } catch (SecurityException se) {
8259 enforceModifyPermission();
8260 }
8261 } else {
8262 enforceModifyPermission();
8263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264
8265 final long identity = Binder.clearCallingIdentity();
8266 try {
8267 Phone phone = getPhone(subId);
8268 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008269 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8270 phone.carrierActionSetMeteredApnsEnabled(enabled);
8271 } else {
8272 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 }
8275 } finally {
8276 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008277 }
8278 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008279
8280 /**
8281 * Get Client request stats
8282 * @return List of Client Request Stats
8283 * @hide
8284 */
8285 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008286 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8287 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008289 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008290 return null;
8291 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008292 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 if (phone != null) {
8297 return phone.getClientRequestStats();
8298 }
8299
8300 return null;
8301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008304 }
8305
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008306 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008307 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008308 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008309 }
Jack Yueb4124c2017-02-16 15:32:43 -08008310
8311 /**
Grace Chen70990072017-03-24 17:21:30 -07008312 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008313 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008314 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008315 * @param state State of SIM (power down, power up, pass through)
8316 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8317 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8318 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008319 *
8320 **/
8321 @Override
Grace Chen70990072017-03-24 17:21:30 -07008322 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008323 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008324 Phone phone = PhoneFactory.getPhone(slotIndex);
8325
vagdeviaf9a5b92018-08-15 16:01:53 -07008326 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 final long identity = Binder.clearCallingIdentity();
8329 try {
8330 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008331 phone.setSimPowerState(state, null, workSource);
8332 }
8333 } finally {
8334 Binder.restoreCallingIdentity(identity);
8335 }
8336 }
8337
8338 /**
8339 * Set SIM card power state.
8340 *
8341 * @param slotIndex SIM slot id.
8342 * @param state State of SIM (power down, power up, pass through)
8343 * @param callback callback to trigger after success or failure
8344 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8345 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8346 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8347 *
8348 **/
8349 @Override
8350 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8351 IIntegerConsumer callback) {
8352 enforceModifyPermission();
8353 Phone phone = PhoneFactory.getPhone(slotIndex);
8354
8355 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8356
8357 final long identity = Binder.clearCallingIdentity();
8358 try {
8359 if (phone != null) {
8360 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8361 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008362 }
8363 } finally {
8364 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008365 }
8366 }
Shuo Qiandd210312017-04-12 22:11:33 +00008367
Tyler Gunn65d45c22017-06-05 11:22:26 -07008368 private boolean isUssdApiAllowed(int subId) {
8369 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008370 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008371 if (configManager == null) {
8372 return false;
8373 }
8374 PersistableBundle pb = configManager.getConfigForSubId(subId);
8375 if (pb == null) {
8376 return false;
8377 }
8378 return pb.getBoolean(
8379 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8380 }
8381
Shuo Qiandd210312017-04-12 22:11:33 +00008382 /**
8383 * Check if phone is in emergency callback mode
8384 * @return true if phone is in emergency callback mode
8385 * @param subId sub id
8386 */
goneil9c5f4872017-12-05 14:07:56 -08008387 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008388 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008389 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008390 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391
8392 final long identity = Binder.clearCallingIdentity();
8393 try {
8394 if (phone != null) {
8395 return phone.isInEcm();
8396 } else {
8397 return false;
8398 }
8399 } finally {
8400 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008401 }
8402 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008403
8404 /**
8405 * Get the current signal strength information for the given subscription.
8406 * Because this information is not updated when the device is in a low power state
8407 * it should not be relied-upon to be current.
8408 * @param subId Subscription index
8409 * @return the most recent cached signal strength info from the modem
8410 */
8411 @Override
8412 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008413 final long identity = Binder.clearCallingIdentity();
8414 try {
8415 Phone p = getPhone(subId);
8416 if (p == null) {
8417 return null;
8418 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008420 return p.getSignalStrength();
8421 } finally {
8422 Binder.restoreCallingIdentity(identity);
8423 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008424 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008425
Pengquan Meng77b7f132018-08-22 14:49:57 -07008426 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008427 * Get the current modem radio state for the given slot.
8428 * @param slotIndex slot index.
8429 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008430 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008431 * @return the current radio power state from the modem
8432 */
8433 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008434 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008435 Phone phone = PhoneFactory.getPhone(slotIndex);
8436 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8438 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008439 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8440 }
8441
8442 final long identity = Binder.clearCallingIdentity();
8443 try {
8444 return phone.getRadioPowerState();
8445 } finally {
8446 Binder.restoreCallingIdentity(identity);
8447 }
8448 }
8449 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8450 }
8451
8452 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008453 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8454 *
8455 * <p>Requires one of the following permissions:
8456 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8457 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8458 * privileges.
8459 *
8460 * @param subId subscription id
8461 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8462 * {@code false}.
8463 */
8464 @Override
8465 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008466 try {
8467 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8468 null);
8469 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008470 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008471 mApp, subId, "isDataRoamingEnabled");
8472 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008473
Pengquan Menga1bb6272018-09-06 09:59:22 -07008474 boolean isEnabled = false;
8475 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008476 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008477 Phone phone = getPhone(subId);
8478 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008479 } finally {
8480 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008481 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008482 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008483 }
8484
8485
8486 /**
8487 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8488 *
8489 * <p> Requires permission:
8490 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8491 * privileges.
8492 *
8493 * @param subId subscription id
8494 * @param isEnabled {@code true} means enable, {@code false} means disable.
8495 */
8496 @Override
8497 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8499 mApp, subId, "setDataRoamingEnabled");
8500
Pengquan Menga1bb6272018-09-06 09:59:22 -07008501 final long identity = Binder.clearCallingIdentity();
8502 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008503 Phone phone = getPhone(subId);
8504 if (phone != null) {
8505 phone.setDataRoamingEnabled(isEnabled);
8506 }
8507 } finally {
8508 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008509 }
8510 }
8511
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008512 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008513 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008514 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008515 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008516 mApp, subId, "isManualNetworkSelectionAllowed");
8517
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008518 boolean isAllowed = true;
8519 final long identity = Binder.clearCallingIdentity();
8520 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008521 Phone phone = getPhone(subId);
8522 if (phone != null) {
8523 isAllowed = phone.isCspPlmnEnabled();
8524 }
8525 } finally {
8526 Binder.restoreCallingIdentity(identity);
8527 }
8528 return isAllowed;
8529 }
8530
8531 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008532 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008533 // Verify that tha callingPackage belongs to the calling UID
8534 mApp.getSystemService(AppOpsManager.class)
8535 .checkPackage(Binder.getCallingUid(), callingPackage);
8536
Jordan Liu1e142fc2019-04-22 15:10:43 -07008537 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008538 try {
8539 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008540 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008541 } catch (SecurityException e) {
8542 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8543 // has carrier privileges on an active UICC
8544 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8545 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008546 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008547 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008548 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008549
8550 final long identity = Binder.clearCallingIdentity();
8551 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008552 UiccController uiccController = UiccController.getInstance();
8553 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008554 if (hasReadPermission) {
8555 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008556 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008557
8558 // Remove private info if the caller doesn't have access
8559 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8560 for (UiccCardInfo cardInfo : cardInfos) {
8561 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8562 // is available
8563 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8564 if (card == null || card.getUiccProfile() == null) {
8565 // assume no access if the card or profile is unavailable
8566 filteredInfos.add(cardInfo.getUnprivileged());
8567 continue;
8568 }
8569 UiccProfile profile = card.getUiccProfile();
8570 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8571 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8572 filteredInfos.add(cardInfo);
8573 } else {
8574 filteredInfos.add(cardInfo.getUnprivileged());
8575 }
8576 }
8577 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008578 } finally {
8579 Binder.restoreCallingIdentity(identity);
8580 }
8581 }
8582
8583 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008584 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008585 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008586
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008587 final long identity = Binder.clearCallingIdentity();
8588 try {
8589 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8590 if (slots == null) {
8591 Rlog.i(LOG_TAG, "slots is null.");
8592 return null;
8593 }
8594
8595 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8596 for (int i = 0; i < slots.length; i++) {
8597 UiccSlot slot = slots[i];
8598 if (slot == null) {
8599 continue;
8600 }
8601
Jordan Liu7be7e652019-05-06 18:55:02 +00008602 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603 UiccCard card = slot.getUiccCard();
8604 if (card != null) {
8605 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008606 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008607 cardId = slot.getEid();
8608 if (TextUtils.isEmpty(cardId)) {
8609 cardId = slot.getIccId();
8610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008611 }
8612
Jordan Liu857451f2019-05-09 16:35:35 -07008613 if (cardId != null) {
8614 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8615 // if cardId is an EID, it's all digits so this is fine
8616 cardId = IccUtils.stripTrailingFs(cardId);
8617 }
8618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619 int cardState = 0;
8620 switch (slot.getCardState()) {
8621 case CARDSTATE_ABSENT:
8622 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8623 break;
8624 case CARDSTATE_PRESENT:
8625 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8626 break;
8627 case CARDSTATE_ERROR:
8628 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8629 break;
8630 case CARDSTATE_RESTRICTED:
8631 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8632 break;
8633 default:
8634 break;
8635
8636 }
8637
8638 infos[i] = new UiccSlotInfo(
8639 slot.isActive(),
8640 slot.isEuicc(),
8641 cardId,
8642 cardState,
8643 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008644 slot.isExtendedApduSupported(),
8645 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008646 }
8647 return infos;
8648 } finally {
8649 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008650 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008651 }
8652
8653 @Override
8654 public boolean switchSlots(int[] physicalSlots) {
8655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008656
8657 final long identity = Binder.clearCallingIdentity();
8658 try {
8659 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8660 } finally {
8661 Binder.restoreCallingIdentity(identity);
8662 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008663 }
Jack Yu4c988042018-02-27 15:30:01 -08008664
8665 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008666 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008667 final long identity = Binder.clearCallingIdentity();
8668 try {
8669 return UiccController.getInstance().getCardIdForDefaultEuicc();
8670 } finally {
8671 Binder.restoreCallingIdentity(identity);
8672 }
8673 }
8674
Pengquan Meng85728fb2018-03-12 16:31:21 -07008675 /**
goneil47ffb6e2018-04-06 15:40:58 -07008676 * A test API to reload the UICC profile.
8677 *
8678 * <p>Requires that the calling app has permission
8679 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8680 * @hide
8681 */
8682 @Override
8683 public void refreshUiccProfile(int subId) {
8684 enforceModifyPermission();
8685
8686 final long identity = Binder.clearCallingIdentity();
8687 try {
8688 Phone phone = getPhone(subId);
8689 if (phone == null) {
8690 return;
8691 }
8692 UiccCard uiccCard = phone.getUiccCard();
8693 if (uiccCard == null) {
8694 return;
8695 }
8696 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8697 if (uiccProfile == null) {
8698 return;
8699 }
8700 uiccProfile.refresh();
8701 } finally {
8702 Binder.restoreCallingIdentity(identity);
8703 }
8704 }
8705
8706 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008707 * Returns false if the mobile data is disabled by default, otherwise return true.
8708 */
8709 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008710 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008711 }
8712
8713 /**
8714 * Returns true if the data roaming is enabled by default, i.e the system property
8715 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8716 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8717 */
8718 private boolean getDefaultDataRoamingEnabled(int subId) {
8719 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008720 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008721 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008722 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8723 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8724 return isDataRoamingEnabled;
8725 }
8726
8727 /**
8728 * Returns the default network type for the given {@code subId}, if the default network type is
8729 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8730 */
8731 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008732 List<Integer> list = TelephonyProperties.default_network();
8733 int phoneId = mSubscriptionController.getPhoneId(subId);
8734 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8735 return list.get(phoneId);
8736 }
8737 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008738 }
fionaxua13278b2018-03-21 00:08:13 -07008739
8740 @Override
8741 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008742 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008744
8745 final long identity = Binder.clearCallingIdentity();
8746 try {
8747 final Phone phone = getPhone(subId);
8748 if (phone == null) {
8749 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8750 return;
8751 }
chen xueaba88a2019-03-15 13:15:10 -07008752 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8753 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008754 if (carrierPrivilegeRules == null) {
8755 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8756 } else {
8757 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008759 } finally {
8760 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008761 }
fionaxua13278b2018-03-21 00:08:13 -07008762 }
8763
8764 @Override
8765 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008766 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008767
8768 final long identity = Binder.clearCallingIdentity();
8769 try {
8770 final Phone phone = getPhone(subId);
8771 if (phone == null) {
8772 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8773 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8774 }
8775 return phone.getCarrierIdListVersion();
8776 } finally {
8777 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008778 }
fionaxua13278b2018-03-21 00:08:13 -07008779 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008780
8781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008782 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8783 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008785 mApp, subId, callingPackage, callingFeatureId,
8786 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008787 return -1;
8788 }
8789
8790 final long identity = Binder.clearCallingIdentity();
8791 try {
8792 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8793 } finally {
8794 Binder.restoreCallingIdentity(identity);
8795 }
8796 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008797
8798 @Override
8799 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008800 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008801 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008802 mApp, subId, "getCdmaRoamingMode");
8803
8804 final long identity = Binder.clearCallingIdentity();
8805 try {
8806 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8807 } finally {
8808 Binder.restoreCallingIdentity(identity);
8809 }
8810 }
8811
8812 @Override
8813 public boolean setCdmaRoamingMode(int subId, int mode) {
8814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8815 mApp, subId, "setCdmaRoamingMode");
8816
8817 final long identity = Binder.clearCallingIdentity();
8818 try {
8819 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8820 } finally {
8821 Binder.restoreCallingIdentity(identity);
8822 }
8823 }
8824
8825 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008826 public int getCdmaSubscriptionMode(int subId) {
8827 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008828 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008829 mApp, subId, "getCdmaSubscriptionMode");
8830
8831 final long identity = Binder.clearCallingIdentity();
8832 try {
8833 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8834 } finally {
8835 Binder.restoreCallingIdentity(identity);
8836 }
8837 }
8838
8839 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008840 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8842 mApp, subId, "setCdmaSubscriptionMode");
8843
8844 final long identity = Binder.clearCallingIdentity();
8845 try {
8846 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8847 } finally {
8848 Binder.restoreCallingIdentity(identity);
8849 }
8850 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008851
sqianc5eccab2018-10-19 18:46:41 -07008852 @Override
sqian8c685422019-02-22 15:55:18 -08008853 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008854 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008856 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8857 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008858 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8859 }
8860 final long identity = Binder.clearCallingIdentity();
8861 try {
sqian854d44b2018-12-12 16:48:18 -08008862 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8863 for (Phone phone: PhoneFactory.getPhones()) {
8864 if (phone.getEmergencyNumberTracker() != null
8865 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8866 emergencyNumberListInternal.put(
8867 phone.getSubId(),
8868 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8869 }
sqian11b7a0e2018-12-05 18:48:28 -08008870 }
sqian854d44b2018-12-12 16:48:18 -08008871 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008872 } finally {
8873 Binder.restoreCallingIdentity(identity);
8874 }
sqianc5eccab2018-10-19 18:46:41 -07008875 }
8876
8877 @Override
sqian8c685422019-02-22 15:55:18 -08008878 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008879 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008880 if (!exactMatch) {
8881 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008882 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008883 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008884 }
8885 final long identity = Binder.clearCallingIdentity();
8886 try {
sqian854d44b2018-12-12 16:48:18 -08008887 for (Phone phone: PhoneFactory.getPhones()) {
8888 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008889 && phone.getEmergencyNumberTracker()
8890 .isEmergencyNumber(number, exactMatch)) {
8891 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008892 }
sqian11b7a0e2018-12-05 18:48:28 -08008893 }
8894 return false;
8895 } finally {
8896 Binder.restoreCallingIdentity(identity);
8897 }
8898 }
8899
sqianf4ca7ed2019-01-15 18:32:07 -08008900 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008901 * Start emergency callback mode for GsmCdmaPhone for testing.
8902 */
8903 @Override
8904 public void startEmergencyCallbackMode() {
8905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8906 "startEmergencyCallbackMode");
8907 enforceModifyPermission();
8908 final long identity = Binder.clearCallingIdentity();
8909 try {
8910 for (Phone phone : PhoneFactory.getPhones()) {
8911 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8912 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8913 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8914 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8915 gsmCdmaPhone.obtainMessage(
8916 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8917 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8918 }
8919 }
8920 } finally {
8921 Binder.restoreCallingIdentity(identity);
8922 }
8923 }
8924
8925 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008926 * Update emergency number list for test mode.
8927 */
8928 @Override
8929 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8930 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8931 "updateEmergencyNumberListTestMode");
8932
8933 final long identity = Binder.clearCallingIdentity();
8934 try {
8935 for (Phone phone: PhoneFactory.getPhones()) {
8936 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8937 if (tracker != null) {
8938 tracker.executeEmergencyNumberTestModeCommand(action, num);
8939 }
8940 }
8941 } finally {
8942 Binder.restoreCallingIdentity(identity);
8943 }
8944 }
8945
8946 /**
8947 * Get the full emergency number list for test mode.
8948 */
8949 @Override
8950 public List<String> getEmergencyNumberListTestMode() {
8951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8952 "getEmergencyNumberListTestMode");
8953
8954 final long identity = Binder.clearCallingIdentity();
8955 try {
8956 Set<String> emergencyNumbers = new HashSet<>();
8957 for (Phone phone: PhoneFactory.getPhones()) {
8958 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8959 if (tracker != null) {
8960 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8961 emergencyNumbers.add(num.getNumber());
8962 }
8963 }
8964 }
8965 return new ArrayList<>(emergencyNumbers);
8966 } finally {
8967 Binder.restoreCallingIdentity(identity);
8968 }
8969 }
8970
chen xud6b45bd2018-10-30 22:27:10 -07008971 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008972 public int getEmergencyNumberDbVersion(int subId) {
8973 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8974
8975 final long identity = Binder.clearCallingIdentity();
8976 try {
8977 final Phone phone = getPhone(subId);
8978 if (phone == null) {
8979 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8980 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8981 }
8982 return phone.getEmergencyNumberDbVersion();
8983 } finally {
8984 Binder.restoreCallingIdentity(identity);
8985 }
8986 }
8987
8988 @Override
8989 public void notifyOtaEmergencyNumberDbInstalled() {
8990 enforceModifyPermission();
8991
8992 final long identity = Binder.clearCallingIdentity();
8993 try {
8994 for (Phone phone: PhoneFactory.getPhones()) {
8995 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8996 if (tracker != null) {
8997 tracker.updateOtaEmergencyNumberDatabase();
8998 }
8999 }
9000 } finally {
9001 Binder.restoreCallingIdentity(identity);
9002 }
9003 }
9004
9005 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009006 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009007 enforceActiveEmergencySessionPermission();
9008
9009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 for (Phone phone: PhoneFactory.getPhones()) {
9012 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9013 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009014 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9015 }
9016 }
9017 } finally {
9018 Binder.restoreCallingIdentity(identity);
9019 }
9020 }
9021
9022 @Override
9023 public void resetOtaEmergencyNumberDbFilePath() {
9024 enforceActiveEmergencySessionPermission();
9025
9026 final long identity = Binder.clearCallingIdentity();
9027 try {
9028 for (Phone phone: PhoneFactory.getPhones()) {
9029 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9030 if (tracker != null) {
9031 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009032 }
9033 }
9034 } finally {
9035 Binder.restoreCallingIdentity(identity);
9036 }
9037 }
9038
9039 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009040 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9041 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9042 Phone phone = getPhone(subId);
9043 if (phone == null) {
9044 return null;
9045 }
9046 final long identity = Binder.clearCallingIdentity();
9047 try {
9048 UiccProfile profile = UiccController.getInstance()
9049 .getUiccProfileForPhone(phone.getPhoneId());
9050 if (profile != null) {
9051 return profile.getCertsFromCarrierPrivilegeAccessRules();
9052 }
9053 } finally {
9054 Binder.restoreCallingIdentity(identity);
9055 }
9056 return null;
9057 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009058
9059 /**
9060 * Enable or disable a modem stack.
9061 */
9062 @Override
9063 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9064 enforceModifyPermission();
9065
9066 final long identity = Binder.clearCallingIdentity();
9067 try {
9068 Phone phone = PhoneFactory.getPhone(slotIndex);
9069 if (phone == null) {
9070 return false;
9071 } else {
9072 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9073 }
9074 } finally {
9075 Binder.restoreCallingIdentity(identity);
9076 }
9077 }
Michelecea4cf22018-12-21 15:00:11 -08009078
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009079 /**
9080 * Whether a modem stack is enabled or not.
9081 */
9082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009083 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9084 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009085 Phone phone = PhoneFactory.getPhone(slotIndex);
9086 if (phone == null) return false;
9087
9088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009089 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9090 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009091 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9092 }
9093
9094 final long identity = Binder.clearCallingIdentity();
9095 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009096 try {
9097 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9098 } catch (NoSuchElementException ex) {
9099 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9100 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009101 } finally {
9102 Binder.restoreCallingIdentity(identity);
9103 }
9104 }
9105
Michelecea4cf22018-12-21 15:00:11 -08009106 @Override
Michele0ea7d782019-03-19 14:58:42 -07009107 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009108 enforceModifyPermission();
9109
9110 final long identity = Binder.clearCallingIdentity();
9111 try {
9112 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009113 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009114 .commit();
9115 } finally {
9116 Binder.restoreCallingIdentity(identity);
9117 }
9118 }
9119
9120 @Override
Michele0ea7d782019-03-19 14:58:42 -07009121 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009122 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009124 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9125 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009126 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009127 }
Michelecea4cf22018-12-21 15:00:11 -08009128
9129 final long identity = Binder.clearCallingIdentity();
9130 try {
Michele0ea7d782019-03-19 14:58:42 -07009131 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009136
Michele0ea7d782019-03-19 14:58:42 -07009137 @TelephonyManager.IsMultiSimSupportedResult
9138 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009139 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9140 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9141 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009142 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9143 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009144 }
9145 // Check if the hardware supports multisim functionality. If usage of multisim is not
9146 // supported by the modem, indicate that it is restricted.
9147 PhoneCapability staticCapability =
9148 mPhoneConfigurationManager.getStaticPhoneCapability();
9149 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009150 loge("isMultiSimSupportedInternal: no static configuration available");
9151 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009152 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009153 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009154 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9155 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009156 }
9157 // Check if support of multiple SIMs is restricted by carrier
9158 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009159 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009160 }
9161
Michele0ea7d782019-03-19 14:58:42 -07009162 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009163 }
9164
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009165 /**
9166 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009167 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9168 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9169 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009170 * @param numOfSims number of active sims we want to switch to
9171 */
9172 @Override
9173 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009174 if (numOfSims == 1) {
9175 enforceModifyPermission();
9176 } else {
9177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9178 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9179 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009180 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009181
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009182 try {
Michele30b57b22019-03-01 12:01:14 -08009183 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009184 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009185 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9186 return;
9187 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009188 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9189 } finally {
9190 Binder.restoreCallingIdentity(identity);
9191 }
9192 }
9193
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009194 @Override
9195 public boolean isApplicationOnUicc(int subId, int appType) {
9196 enforceReadPrivilegedPermission("isApplicationOnUicc");
9197 Phone phone = getPhone(subId);
9198 if (phone == null) {
9199 return false;
9200 }
9201 final long identity = Binder.clearCallingIdentity();
9202 try {
9203 UiccCard uiccCard = phone.getUiccCard();
9204 if (uiccCard == null) {
9205 return false;
9206 }
9207 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9208 if (uiccProfile == null) {
9209 return false;
9210 }
9211 if (TelephonyManager.APPTYPE_SIM <= appType
9212 && appType <= TelephonyManager.APPTYPE_ISIM) {
9213 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9214 }
9215 return false;
9216 } finally {
9217 Binder.restoreCallingIdentity(identity);
9218 }
9219 }
9220
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009221 /**
chen xub4baa772019-04-03 10:23:41 -07009222 * Get whether making changes to modem configurations will trigger reboot.
9223 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009224 */
9225 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009226 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9227 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009229 mApp, subId, callingPackage, callingFeatureId,
9230 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009231 return false;
9232 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009233 final long identity = Binder.clearCallingIdentity();
9234 try {
9235 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9236 } finally {
9237 Binder.restoreCallingIdentity(identity);
9238 }
9239 }
9240
Nathan Harold29f5f052019-02-15 13:41:57 -08009241 private void updateModemStateMetrics() {
9242 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9243 // TODO: check the state for each modem if the api is ready.
9244 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9245 }
9246
Pengquan Meng3889a572019-01-23 11:16:29 -08009247 @Override
9248 public int[] getSlotsMapping() {
9249 enforceReadPrivilegedPermission("getSlotsMapping");
9250
9251 final long identity = Binder.clearCallingIdentity();
9252 try {
9253 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9254 // All logical slots should have a mapping to a physical slot.
9255 int[] logicalSlotsMapping = new int[phoneCount];
9256 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9257 for (int i = 0; i < slotInfos.length; i++) {
9258 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9259 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9260 }
9261 }
9262 return logicalSlotsMapping;
9263 } finally {
9264 Binder.restoreCallingIdentity(identity);
9265 }
9266 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009267
9268 /**
9269 * Get the IRadio HAL Version
9270 */
9271 @Override
9272 public int getRadioHalVersion() {
9273 Phone phone = getDefaultPhone();
9274 if (phone == null) return -1;
9275 HalVersion hv = phone.getHalVersion();
9276 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9277 return hv.major * 100 + hv.minor;
9278 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009279
9280 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009281 * Get the current calling package name.
9282 * @return the current calling package name
9283 */
9284 @Override
9285 public String getCurrentPackageName() {
9286 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9287 }
9288
9289 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009290 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9291 * corresponding network requests on a subId.
9292 *
9293 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009294 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009295 * 2) APN is un-metered for this subscription, or
9296 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009297 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009298 *
9299 * @return whether data is allowed for a apn type.
9300 *
9301 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009302 */
9303 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009304 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009305 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9306 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009307
9308 // Now that all security checks passes, perform the operation as ourselves.
9309 final long identity = Binder.clearCallingIdentity();
9310 try {
9311 Phone phone = getPhone(subId);
9312 if (phone == null) return false;
9313
Jack Yu41407ee2019-05-13 16:54:09 -07009314 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009315 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9316 } finally {
9317 Binder.restoreCallingIdentity(identity);
9318 }
9319 }
9320
9321 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009322 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009323 enforceReadPrivilegedPermission("isApnMetered");
9324
9325 // Now that all security checks passes, perform the operation as ourselves.
9326 final long identity = Binder.clearCallingIdentity();
9327 try {
9328 Phone phone = getPhone(subId);
9329 if (phone == null) return true; // By default return true.
9330
Jack Yu41407ee2019-05-13 16:54:09 -07009331 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009332 } finally {
9333 Binder.restoreCallingIdentity(identity);
9334 }
9335 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009336
9337 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009338 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9339 int subscriptionId, IBooleanConsumer resultCallback) {
9340 enforceModifyPermission();
9341 long token = Binder.clearCallingIdentity();
9342 try {
9343 Phone phone = getPhone(subscriptionId);
9344 if (phone == null) {
9345 try {
9346 if (resultCallback != null) {
9347 resultCallback.accept(false);
9348 }
9349 } catch (RemoteException e) {
9350 // ignore
9351 }
9352 return;
9353 }
9354 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9355 Pair.create(specifiers, (x) -> {
9356 try {
9357 if (resultCallback != null) {
9358 resultCallback.accept(x);
9359 }
9360 } catch (RemoteException e) {
9361 // ignore
9362 }
9363 });
9364 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9365 } finally {
9366 Binder.restoreCallingIdentity(token);
9367 }
9368 }
9369
9370 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009371 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9372 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009373 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009374 mApp, subId, "getSystemSelectionChannels");
9375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9376 final long identity = Binder.clearCallingIdentity();
9377 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009378 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9379 if (result instanceof IllegalStateException) {
9380 throw (IllegalStateException) result;
9381 }
9382 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009383 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9384 return specifiers;
9385 } finally {
9386 Binder.restoreCallingIdentity(identity);
9387 }
9388 }
9389
9390 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009391 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009392 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009393 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9394 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9395 if (iccRecords == null) {
9396 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9397 return false;
9398 }
9399 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9400 }
9401
9402 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009403 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9404 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009405 if (callingPackage == null) {
9406 callingPackage = getCurrentPackageName();
9407 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009408 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9409 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009410 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9411 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009412 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9413 }
9414 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9415 Intent intent = new Intent();
9416 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9417 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9418 // Bring up choose default SMS subscription dialog right now
9419 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9420 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9421 mApp.startActivity(intent);
9422 }
chen xud5ca2d52019-05-28 15:20:57 -07009423
9424 @Override
9425 public String getMmsUAProfUrl(int subId) {
9426 //TODO investigate if this API should require proper permission check in R b/133791609
9427 final long identity = Binder.clearCallingIdentity();
9428 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009429 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9430 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9431 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9432 return carrierUAProfUrl;
9433 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009434 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9435 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009436 } finally {
9437 Binder.restoreCallingIdentity(identity);
9438 }
9439 }
9440
9441 @Override
9442 public String getMmsUserAgent(int subId) {
9443 //TODO investigate if this API should require proper permission check in R b/133791609
9444 final long identity = Binder.clearCallingIdentity();
9445 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009446 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9447 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9448 if (!TextUtils.isEmpty(carrierUserAgent)) {
9449 return carrierUserAgent;
9450 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009451 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9452 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009453 } finally {
9454 Binder.restoreCallingIdentity(identity);
9455 }
9456 }
Jack Yub07d4972019-05-28 16:12:25 -07009457
9458 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009459 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9460 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009461
Jack Yub07d4972019-05-28 16:12:25 -07009462 final long identity = Binder.clearCallingIdentity();
9463 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009464 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009465 if (phone == null) return false;
9466
Hall Liua62f5da2020-09-25 10:42:19 -07009467 switch (policy) {
9468 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9469 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9470 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9471 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9472 default:
9473 throw new IllegalArgumentException(policy + " is not a valid policy");
9474 }
Jack Yub07d4972019-05-28 16:12:25 -07009475 } finally {
9476 Binder.restoreCallingIdentity(identity);
9477 }
9478 }
9479
9480 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009481 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009482 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009483 enforceModifyPermission();
9484
changbettyd5c246e2019-12-24 15:40:37 +08009485 final long identity = Binder.clearCallingIdentity();
9486 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009487 Phone phone = getPhone(subscriptionId);
9488 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009489
Hall Liua62f5da2020-09-25 10:42:19 -07009490 switch (policy) {
9491 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9492 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9493 break;
9494 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9495 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9496 break;
9497 default:
9498 throw new IllegalArgumentException(policy + " is not a valid policy");
9499 }
changbettyd5c246e2019-12-24 15:40:37 +08009500 } finally {
9501 Binder.restoreCallingIdentity(identity);
9502 }
9503 }
9504
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009505 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009506 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009507 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9508 * otherwise.
9509 */
9510 @Override
9511 public void setCepEnabled(boolean isCepEnabled) {
9512 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9513
9514 final long identity = Binder.clearCallingIdentity();
9515 try {
9516 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9517 for (Phone phone : PhoneFactory.getPhones()) {
9518 Phone defaultPhone = phone.getImsPhone();
9519 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9520 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9521 ImsPhoneCallTracker imsPhoneCallTracker =
9522 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9523 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9524 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9525 + imsPhone.getMsisdn());
9526 }
9527 }
9528 } finally {
9529 Binder.restoreCallingIdentity(identity);
9530 }
9531 }
allenwtsu46dcc572020-01-08 18:24:03 +08009532
9533 /**
9534 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9535 *
9536 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9537 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9538 * before being read.
9539 */
9540 @Override
9541 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9542 isCompressed) {
9543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9544 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009545 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9546 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9547 }
9548 if (!isImsAvailableOnDevice()) {
9549 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9550 "IMS not available on device.");
9551 }
9552
9553 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009554 try {
Hui Wang761a6682020-10-31 05:12:53 +00009555 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009558 }
9559 }
zoey chene02881a2019-12-30 16:11:23 +08009560
9561 @Override
9562 public boolean isIccLockEnabled(int subId) {
9563 enforceReadPrivilegedPermission("isIccLockEnabled");
9564
9565 // Now that all security checks passes, perform the operation as ourselves.
9566 final long identity = Binder.clearCallingIdentity();
9567 try {
9568 Phone phone = getPhone(subId);
9569 if (phone != null && phone.getIccCard() != null) {
9570 return phone.getIccCard().getIccLockEnabled();
9571 } else {
9572 return false;
9573 }
9574 } finally {
9575 Binder.restoreCallingIdentity(identity);
9576 }
9577 }
9578
9579 /**
9580 * Set the ICC pin lock enabled or disabled.
9581 *
9582 * @return an integer representing the status of IccLock enabled or disabled in the following
9583 * three cases:
9584 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9585 * successfully.
9586 * - Positive number and zero for remaining password attempts.
9587 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9588 *
9589 */
9590 @Override
9591 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9592 enforceModifyPermission();
9593
9594 Phone phone = getPhone(subId);
9595 if (phone == null) {
9596 return 0;
9597 }
9598 // Now that all security checks passes, perform the operation as ourselves.
9599 final long identity = Binder.clearCallingIdentity();
9600 try {
9601 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9602 new Pair<Boolean, String>(enabled, password), phone, null);
9603 return attemptsRemaining;
9604
9605 } catch (Exception e) {
9606 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9607 } finally {
9608 Binder.restoreCallingIdentity(identity);
9609 }
9610 return 0;
9611 }
9612
9613 /**
9614 * Change the ICC password used in ICC pin lock.
9615 *
9616 * @return an integer representing the status of IccLock changed in the following three cases:
9617 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9618 * - Positive number and zero for remaining password attempts.
9619 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9620 *
9621 */
9622 @Override
9623 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9624 enforceModifyPermission();
9625
9626 Phone phone = getPhone(subId);
9627 if (phone == null) {
9628 return 0;
9629 }
9630 // Now that all security checks passes, perform the operation as ourselves.
9631 final long identity = Binder.clearCallingIdentity();
9632 try {
9633 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9634 new Pair<String, String>(oldPassword, newPassword), phone, null);
9635 return attemptsRemaining;
9636
9637 } catch (Exception e) {
9638 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9639 } finally {
9640 Binder.restoreCallingIdentity(identity);
9641 }
9642 return 0;
9643 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009644
9645 /**
9646 * Request for receiving user activity notification
9647 */
9648 @Override
9649 public void requestUserActivityNotification() {
9650 if (!mNotifyUserActivity.get()
9651 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9652 mNotifyUserActivity.set(true);
9653 }
9654 }
9655
9656 /**
9657 * Called when userActivity is signalled in the power manager.
9658 * This is safe to call from any thread, with any window manager locks held or not.
9659 */
9660 @Override
9661 public void userActivity() {
9662 // ***************************************
9663 // * Inherited from PhoneWindowManager *
9664 // ***************************************
9665 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9666 // WITH ITS LOCKS HELD.
9667 //
9668 // This code must be VERY careful about the locks
9669 // it acquires.
9670 // In fact, the current code acquires way too many,
9671 // and probably has lurking deadlocks.
9672
9673 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9674 throw new SecurityException("Only the OS may call notifyUserActivity()");
9675 }
9676
9677 if (mNotifyUserActivity.getAndSet(false)) {
9678 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9679 USER_ACTIVITY_NOTIFICATION_DELAY);
9680 }
9681 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009682
9683 @Override
9684 public boolean canConnectTo5GInDsdsMode() {
9685 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9686 }
Jack Yud10cdd42020-09-28 20:28:01 -07009687
9688 @Override
9689 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9690 String callingFeatureId) {
9691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9692 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9693 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9694 }
9695
9696 Phone phone = getPhone(subId);
9697 if (phone == null) {
9698 throw new RuntimeException("phone is not available");
9699 }
9700 // Now that all security checks passes, perform the operation as ourselves.
9701 final long identity = Binder.clearCallingIdentity();
9702 try {
9703 return phone.getEquivalentHomePlmns();
9704 } finally {
9705 Binder.restoreCallingIdentity(identity);
9706 }
9707 }
Daniel Bright59e67312020-11-13 11:49:37 -08009708
9709 @Override
9710 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009711 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9712 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009713 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009714 if (radioInterfaceCapabilities == null) {
9715 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009716 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009717 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009718 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009719
Hui Wang641e81c2020-10-12 12:14:23 -07009720 @Override
9721 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9722 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009723 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9724 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9725 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9726 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9727 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009728 if (DBG) {
9729 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9730 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9731 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9732 }
9733
9734 if (!SubscriptionManager.isValidSubscriptionId(subId)
9735 || appType < TelephonyManager.APPTYPE_UNKNOWN
9736 || appType > TelephonyManager.APPTYPE_ISIM
9737 || nafUrl == null || securityProtocol == null || callback == null) {
9738 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9739 if (callback != null) {
9740 try {
9741 callback.onAuthenticationFailure(
9742 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9743 } catch (RemoteException exception) {
9744 log("Fail to notify onAuthenticationFailure due to " + exception);
9745 }
9746 return;
9747 }
9748 }
9749
9750 final long token = Binder.clearCallingIdentity();
9751 try {
9752 getGbaManager(subId).bootstrapAuthenticationRequest(
9753 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9754 forceBootStrapping, callback));
9755 } finally {
9756 Binder.restoreCallingIdentity(token);
9757 }
9758 }
9759
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009760 /**
9761 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9762 * requested radio power state will actually be set. See {@link
9763 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9764 *
9765 * @param subId the subscription ID of the phone requesting to set the radio power state.
9766 * @param enable {@code true} if trying to turn radio on.
9767 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9768 * false}.
9769 */
9770 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9771 Phone phone = getPhone(subId);
9772 if (phone != null) {
9773 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9774 return true;
9775 }
9776 return false;
9777 }
9778
9779 private int handleDataThrottlingRequest(int subId,
9780 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009781 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9782 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9783 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9784 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9785 throw new IllegalArgumentException("modem does not support data throttling");
9786 }
9787
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009788 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9789 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9790 if (!setRadioPowerForThermal(subId, true)) {
9791 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9792 }
9793
9794 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9795
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009796 if (isDataThrottlingSupported) {
9797 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009798 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009799 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9800 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9801 } else if (thermalMitigationResult
9802 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009803 log("Modem likely does not support data throttling on secondary carrier. Data " +
9804 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9805 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009806 }
9807 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009808 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009809
9810 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009811 }
9812
Jack Nudelman644b91a2021-03-12 14:09:48 -08009813 private static List<String> getThermalMitigationAllowlist(Context context) {
9814 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9815 for (String pckg : context.getResources()
9816 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9817 sThermalMitigationAllowlistedPackages.add(pckg);
9818 }
9819 }
9820
9821 return sThermalMitigationAllowlistedPackages;
9822 }
9823
9824 /**
9825 * Used by shell commands to add an authorized package name for thermal mitigation.
9826 * @param packageName name of package to be allowlisted
9827 * @param context
9828 */
9829 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9830 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9831 sThermalMitigationAllowlistedPackages.add(packageName);
9832 }
9833
9834 /**
9835 * Used by shell commands to remove an authorized package name for thermal mitigation.
9836 * @param packageName name of package to remove from allowlist
9837 * @param context
9838 */
9839 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9840 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9841 sThermalMitigationAllowlistedPackages.remove(packageName);
9842 }
9843
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009844 /**
9845 * Thermal mitigation request to control functionalities at modem.
9846 *
9847 * @param subId the id of the subscription.
9848 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009849 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009850 *
9851 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9852 */
9853 @Override
9854 @ThermalMitigationResult
9855 public int sendThermalMitigationRequest(
9856 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009857 ThermalMitigationRequest thermalMitigationRequest,
9858 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009859 enforceModifyPermission();
9860
Jack Nudelman644b91a2021-03-12 14:09:48 -08009861 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9862 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9863 .contains(callingPackage)) {
9864 throw new SecurityException("Calling package must be configured in the device config. "
9865 + "calling package: " + callingPackage);
9866 }
9867
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009868 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9869 final long identity = Binder.clearCallingIdentity();
9870
9871 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9872 try {
9873 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9874 switch (thermalMitigationAction) {
9875 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9876 thermalMitigationResult =
9877 handleDataThrottlingRequest(subId,
9878 thermalMitigationRequest.getDataThrottlingRequest());
9879 break;
9880 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9881 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9882 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9883 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9884 }
9885
9886 // Ensure that radio is on. If not able to power on due to phone being
9887 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9888 if (!setRadioPowerForThermal(subId, true)) {
9889 thermalMitigationResult =
9890 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9891 break;
9892 }
9893
9894 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9895 false);
9896 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9897 break;
9898 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9899 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9900 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9901 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9902 }
9903
9904 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9905 if (registry != null) {
9906 TelephonyConnectionService service =
9907 registry.getTelephonyConnectionService();
9908 Phone phone = getPhone(subId);
9909 if (phone == null) {
9910 thermalMitigationResult =
9911 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9912 break;
9913 }
9914
9915 if (PhoneConstantConversions.convertCallState(phone.getState())
9916 != TelephonyManager.CALL_STATE_IDLE
9917 || phone.isInEmergencySmsMode() || phone.isInEcm()
9918 || (service != null && service.isEmergencyCallPending())) {
9919 String errorMessage = "Phone state is not valid. call state = "
9920 + PhoneConstantConversions.convertCallState(phone.getState())
9921 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9922 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9923 errorMessage += service == null
9924 ? " TelephonyConnectionService is null"
9925 : " isEmergencyCallPending = "
9926 + service.isEmergencyCallPending();
9927 Log.e(LOG_TAG, errorMessage);
9928 thermalMitigationResult =
9929 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9930 break;
9931 }
9932 } else {
9933 thermalMitigationResult =
9934 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9935 break;
9936 }
9937
9938 // Turn radio off. If not able to power off due to phone being unavailable,
9939 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9940 if (!setRadioPowerForThermal(subId, false)) {
9941 thermalMitigationResult =
9942 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9943 break;
9944 }
9945 thermalMitigationResult =
9946 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9947 break;
9948 default:
9949 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9950 + "not exist. Requested action: " + thermalMitigationAction);
9951 }
9952 } catch (IllegalArgumentException e) {
9953 throw e;
9954 } catch (Exception e) {
9955 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9956 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9957 } finally {
9958 Binder.restoreCallingIdentity(identity);
9959 }
9960
9961 if (DBG) {
9962 log("thermalMitigationRequest returning with thermalMitigationResult: "
9963 + thermalMitigationResult);
9964 }
9965
9966 return thermalMitigationResult;
9967 }
Hui Wang641e81c2020-10-12 12:14:23 -07009968
9969 /**
9970 * Set the GbaService Package Name that Telephony will bind to.
9971 *
9972 * @param subId The sim that the GbaService is associated with.
9973 * @param packageName The name of the package to be replaced with.
9974 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9975 */
9976 @Override
9977 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9978 enforceModifyPermission();
9979
9980 final long identity = Binder.clearCallingIdentity();
9981 try {
9982 return getGbaManager(subId).overrideServicePackage(packageName);
9983 } finally {
9984 Binder.restoreCallingIdentity(identity);
9985 }
9986 }
9987
9988 /**
9989 * Return the package name of the currently bound GbaService.
9990 *
9991 * @param subId The sim that the GbaService is associated with.
9992 * @return the package name of the GbaService configuration, null if GBA is not supported.
9993 */
9994 @Override
9995 public String getBoundGbaService(int subId) {
9996 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9997
9998 final long identity = Binder.clearCallingIdentity();
9999 try {
10000 return getGbaManager(subId).getServicePackage();
10001 } finally {
10002 Binder.restoreCallingIdentity(identity);
10003 }
10004 }
10005
10006 /**
10007 * Set the release time for telephony to unbind GbaService.
10008 *
10009 * @param subId The sim that the GbaService is associated with.
10010 * @param interval The release time to unbind GbaService by millisecond.
10011 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10012 */
10013 @Override
10014 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10015 enforceModifyPermission();
10016
10017 final long identity = Binder.clearCallingIdentity();
10018 try {
10019 return getGbaManager(subId).overrideReleaseTime(interval);
10020 } finally {
10021 Binder.restoreCallingIdentity(identity);
10022 }
10023 }
10024
10025 /**
10026 * Return the release time for telephony to unbind GbaService.
10027 *
10028 * @param subId The sim that the GbaService is associated with.
10029 * @return The release time to unbind GbaService by millisecond.
10030 */
10031 @Override
10032 public int getGbaReleaseTime(int subId) {
10033 enforceReadPrivilegedPermission("getGbaReleaseTime");
10034
10035 final long identity = Binder.clearCallingIdentity();
10036 try {
10037 return getGbaManager(subId).getReleaseTime();
10038 } finally {
10039 Binder.restoreCallingIdentity(identity);
10040 }
10041 }
10042
10043 private GbaManager getGbaManager(int subId) {
10044 GbaManager instance = GbaManager.getInstance(subId);
10045 if (instance == null) {
10046 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10047 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10048 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10049 }
10050 return instance;
10051 }
Hui Wang761a6682020-10-31 05:12:53 +000010052
10053 /**
10054 * indicate whether the device and the carrier can support
10055 * RCS VoLTE single registration.
10056 */
10057 @Override
10058 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010059 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10060 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10061 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10062 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010063
10064 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10065 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10066 }
10067
10068 final long identity = Binder.clearCallingIdentity();
10069 try {
10070 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10071 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010072 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10073 if (isCapable != null) {
10074 return isCapable;
10075 }
Hui Wang761a6682020-10-31 05:12:53 +000010076 }
Hui Wang67af90e2021-06-04 16:57:15 -070010077 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10078 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010079 } finally {
10080 Binder.restoreCallingIdentity(identity);
10081 }
10082 }
10083
10084 /**
10085 * Register RCS provisioning callback.
10086 */
10087 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010088 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010089 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010090 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010091 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010092 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10093 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010094
10095 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10096 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10097 }
10098 if (!isImsAvailableOnDevice()) {
10099 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10100 "IMS not available on device.");
10101 }
10102
10103 final long identity = Binder.clearCallingIdentity();
10104 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010105 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010106 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010107 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10108 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010109 }
Hui Wang761a6682020-10-31 05:12:53 +000010110 } finally {
10111 Binder.restoreCallingIdentity(identity);
10112 }
10113 }
10114
10115 /**
10116 * Unregister RCS provisioning callback.
10117 */
10118 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010119 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010120 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010121 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010122 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010123 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10124 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010125
10126 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10127 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10128 }
10129 if (!isImsAvailableOnDevice()) {
10130 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10131 "IMS not available on device.");
10132 }
10133
10134 final long identity = Binder.clearCallingIdentity();
10135 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010136 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010137 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010138 } finally {
10139 Binder.restoreCallingIdentity(identity);
10140 }
10141 }
10142
10143 /**
10144 * trigger RCS reconfiguration.
10145 */
10146 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010147 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10148 "triggerRcsReconfiguration",
10149 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010150
10151 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10152 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10153 }
10154 if (!isImsAvailableOnDevice()) {
10155 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10156 "IMS not available on device.");
10157 }
10158
10159 final long identity = Binder.clearCallingIdentity();
10160 try {
10161 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10162 } finally {
10163 Binder.restoreCallingIdentity(identity);
10164 }
10165 }
10166
10167 /**
10168 * Provide the client configuration parameters of the RCS application.
10169 */
10170 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010171 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10172 "setRcsClientConfiguration",
10173 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010174
10175 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10176 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10177 }
10178 if (!isImsAvailableOnDevice()) {
10179 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10180 "IMS not available on device.");
10181 }
10182
10183 final long identity = Binder.clearCallingIdentity();
10184
10185 try {
10186 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10187 if (configBinder == null) {
10188 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010189 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10190 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010191 } else {
10192 configBinder.setRcsClientConfiguration(rcc);
10193 }
10194 } catch (RemoteException e) {
10195 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010196 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10197 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010198 } finally {
10199 Binder.restoreCallingIdentity(identity);
10200 }
10201 }
10202
10203 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010204 * Enables or disables the test mode for RCS VoLTE single registration.
10205 */
10206 @Override
10207 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10208 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10209 "setRcsSingleRegistrationTestModeEnabled");
10210
10211 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10212 }
10213
10214 /**
10215 * Gets the test mode for RCS VoLTE single registration.
10216 */
10217 @Override
10218 public boolean getRcsSingleRegistrationTestModeEnabled() {
10219 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10220 "getRcsSingleRegistrationTestModeEnabled");
10221
10222 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10223 }
10224
10225 /**
Hui Wang761a6682020-10-31 05:12:53 +000010226 * Overrides the config of RCS VoLTE single registration enabled for the device.
10227 */
10228 @Override
10229 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10230 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10231 "setDeviceSingleRegistrationEnabledOverride");
10232 enforceModifyPermission();
10233
10234 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10235 : Boolean.parseBoolean(enabledStr);
10236 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010237 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010238 }
10239
10240 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010241 * Sends a device to device communication message. Only usable via shell.
10242 * @param message message to send.
10243 * @param value message value.
10244 */
10245 @Override
10246 public void sendDeviceToDeviceMessage(int message, int value) {
10247 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010248 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010249 enforceModifyPermission();
10250
10251 final long identity = Binder.clearCallingIdentity();
10252 try {
10253 TelephonyConnectionService service =
10254 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10255 if (service == null) {
10256 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10257 return;
10258 }
10259 service.sendTestDeviceToDeviceMessage(message, value);
10260 } finally {
10261 Binder.restoreCallingIdentity(identity);
10262 }
10263 }
10264
Tyler Gunnbabbda02021-02-10 11:05:02 -080010265 /**
10266 * Sets the specified device to device transport active.
10267 * @param transport The transport to set active.
10268 */
10269 @Override
10270 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10272 "setActiveDeviceToDeviceTransport");
10273 enforceModifyPermission();
10274
10275 final long identity = Binder.clearCallingIdentity();
10276 try {
10277 TelephonyConnectionService service =
10278 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10279 if (service == null) {
10280 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10281 return;
10282 }
10283 service.setActiveDeviceToDeviceTransport(transport);
10284 } finally {
10285 Binder.restoreCallingIdentity(identity);
10286 }
10287 }
Tyler Gunn92479152021-01-20 16:30:10 -080010288
Tyler Gunnd4575212021-05-03 14:46:49 -070010289 @Override
10290 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10291 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10292 "setDeviceToDeviceForceEnabled");
10293
10294 final long identity = Binder.clearCallingIdentity();
10295 try {
10296 Arrays.stream(PhoneFactory.getPhones()).forEach(
10297 p -> {
10298 Phone thePhone = p.getImsPhone();
10299 if (thePhone != null && thePhone instanceof ImsPhone) {
10300 ImsPhone imsPhone = (ImsPhone) thePhone;
10301 CallTracker tracker = imsPhone.getCallTracker();
10302 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10303 ImsPhoneCallTracker imsPhoneCallTracker =
10304 (ImsPhoneCallTracker) tracker;
10305 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10306 }
10307 }
10308 }
10309 );
10310 } finally {
10311 Binder.restoreCallingIdentity(identity);
10312 }
10313 }
10314
Tyler Gunn92479152021-01-20 16:30:10 -080010315 /**
Hui Wang761a6682020-10-31 05:12:53 +000010316 * Gets the config of RCS VoLTE single registration enabled for the device.
10317 */
10318 @Override
10319 public boolean getDeviceSingleRegistrationEnabled() {
10320 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10321 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10322 }
10323
10324 /**
10325 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10326 */
10327 @Override
10328 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10329 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10330 "setCarrierSingleRegistrationEnabledOverride");
10331 enforceModifyPermission();
10332
10333 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10334 : Boolean.parseBoolean(enabledStr);
10335 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10336 subId, enabled);
10337 }
10338
10339 /**
10340 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10341 */
10342 @Override
10343 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10344 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10345 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10346 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010347
10348 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010349 * Overrides the ims feature validation result
10350 */
10351 @Override
10352 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10353 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10354 "setImsFeatureValidationOverride");
10355
10356 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10357 : Boolean.parseBoolean(enabledStr);
10358 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10359 subId, enabled);
10360 }
10361
10362 /**
10363 * Gets the ims feature validation override value
10364 */
10365 @Override
10366 public boolean getImsFeatureValidationOverride(int subId) {
10367 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10368 "getImsFeatureValidationOverride");
10369 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10370 }
10371
10372 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010373 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10374 * their mobile plan.
10375 */
10376 @Override
10377 public String getMobileProvisioningUrl() {
10378 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 return getDefaultPhone().getMobileProvisioningUrl();
10382 } finally {
10383 Binder.restoreCallingIdentity(identity);
10384 }
10385 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010386
James.cf Linbcdf8b32021-01-14 16:44:13 +080010387 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010388 * Get the EAB contact from the EAB database.
10389 */
10390 @Override
10391 public String getContactFromEab(String contact) {
10392 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10393 enforceModifyPermission();
10394 final long identity = Binder.clearCallingIdentity();
10395 try {
10396 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10397 } finally {
10398 Binder.restoreCallingIdentity(identity);
10399 }
10400 }
10401
10402 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010403 * Remove the EAB contacts from the EAB database.
10404 */
10405 @Override
10406 public int removeContactFromEab(int subId, String contacts) {
10407 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10408 enforceModifyPermission();
10409 final long identity = Binder.clearCallingIdentity();
10410 try {
10411 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10412 } finally {
10413 Binder.restoreCallingIdentity(identity);
10414 }
10415 }
10416
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010417 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010418 public boolean getDeviceUceEnabled() {
10419 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10420 final long identity = Binder.clearCallingIdentity();
10421 try {
10422 return mApp.getDeviceUceEnabled();
10423 } finally {
10424 Binder.restoreCallingIdentity(identity);
10425 }
10426 }
10427
10428 @Override
10429 public void setDeviceUceEnabled(boolean isEnabled) {
10430 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10431 final long identity = Binder.clearCallingIdentity();
10432 try {
10433 mApp.setDeviceUceEnabled(isEnabled);
10434 } finally {
10435 Binder.restoreCallingIdentity(identity);
10436 }
10437 }
10438
Brad Ebinger14d467f2021-02-12 06:18:28 +000010439 /**
10440 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10441 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10442 */
10443 // Used for SHELL command only right now.
10444 @Override
10445 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10446 List<String> featureTags) {
10447 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10448 "addUceRegistrationOverrideShell");
10449 final long identity = Binder.clearCallingIdentity();
10450 try {
10451 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10452 new ArraySet<>(featureTags));
10453 } catch (ImsException e) {
10454 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10455 } finally {
10456 Binder.restoreCallingIdentity(identity);
10457 }
10458 }
10459
10460 /**
10461 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10462 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10463 */
10464 // Used for SHELL command only right now.
10465 @Override
10466 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10467 List<String> featureTags) {
10468 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10469 "removeUceRegistrationOverrideShell");
10470 final long identity = Binder.clearCallingIdentity();
10471 try {
10472 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10473 new ArraySet<>(featureTags));
10474 } catch (ImsException e) {
10475 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10476 } finally {
10477 Binder.restoreCallingIdentity(identity);
10478 }
10479 }
10480
10481 /**
10482 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10483 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10484 */
10485 // Used for SHELL command only right now.
10486 @Override
10487 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10488 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10489 "clearUceRegistrationOverrideShell");
10490 final long identity = Binder.clearCallingIdentity();
10491 try {
10492 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10493 } catch (ImsException e) {
10494 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10495 } finally {
10496 Binder.restoreCallingIdentity(identity);
10497 }
10498 }
10499
10500 /**
10501 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10502 */
10503 // Used for SHELL command only right now.
10504 @Override
10505 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10506 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10507 "getLatestRcsContactUceCapabilityShell");
10508 final long identity = Binder.clearCallingIdentity();
10509 try {
10510 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10511 } catch (ImsException e) {
10512 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10513 } finally {
10514 Binder.restoreCallingIdentity(identity);
10515 }
10516 }
10517
10518 /**
10519 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10520 * device does not have an active PUBLISH.
10521 */
10522 // Used for SHELL command only right now.
10523 @Override
10524 public String getLastUcePidfXmlShell(int subId) {
10525 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10526 final long identity = Binder.clearCallingIdentity();
10527 try {
10528 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10529 } catch (ImsException e) {
10530 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10531 } finally {
10532 Binder.restoreCallingIdentity(identity);
10533 }
10534 }
10535
James.cf Line8713a42021-04-29 16:04:26 +080010536 /**
10537 * Remove UCE requests cannot be sent to the network status.
10538 */
10539 // Used for SHELL command only right now.
10540 @Override
10541 public boolean removeUceRequestDisallowedStatus(int subId) {
10542 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10543 final long identity = Binder.clearCallingIdentity();
10544 try {
10545 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10546 } catch (ImsException e) {
10547 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10548 } finally {
10549 Binder.restoreCallingIdentity(identity);
10550 }
10551 }
10552
James.cf Lin0fc71b02021-05-25 01:37:38 +080010553 /**
10554 * Remove UCE requests cannot be sent to the network status.
10555 */
10556 // Used for SHELL command only.
10557 @Override
10558 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10559 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10560 final long identity = Binder.clearCallingIdentity();
10561 try {
10562 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10563 } catch (ImsException e) {
10564 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10565 } finally {
10566 Binder.restoreCallingIdentity(identity);
10567 }
10568 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010569
James.cf Lin4b784aa2021-01-31 03:25:15 +080010570 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010571 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10572 String callingPackage) {
10573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10574 mApp, subId, "setSignalStrengthUpdateRequest");
10575
10576 final int callingUid = Binder.getCallingUid();
10577 // Verify that tha callingPackage belongs to the calling UID
10578 mApp.getSystemService(AppOpsManager.class)
10579 .checkPackage(callingUid, callingPackage);
10580
10581 validateSignalStrengthUpdateRequest(request, callingUid);
10582
10583 final long identity = Binder.clearCallingIdentity();
10584 try {
10585 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10586 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10587
10588 if (result instanceof IllegalStateException) {
10589 throw (IllegalStateException) result;
10590 }
10591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 }
10595
10596 @Override
10597 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10598 String callingPackage) {
10599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10600 mApp, subId, "clearSignalStrengthUpdateRequest");
10601
10602 final int callingUid = Binder.getCallingUid();
10603 // Verify that tha callingPackage belongs to the calling UID
10604 mApp.getSystemService(AppOpsManager.class)
10605 .checkPackage(callingUid, callingPackage);
10606
10607 final long identity = Binder.clearCallingIdentity();
10608 try {
10609 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10610 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10611
10612 if (result instanceof IllegalStateException) {
10613 throw (IllegalStateException) result;
10614 }
10615 } finally {
10616 Binder.restoreCallingIdentity(identity);
10617 }
10618 }
10619
10620 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10621 int callingUid) {
10622 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10623 // phone/system process do not have further restriction on request
10624 return;
10625 }
10626
10627 // Applications has restrictions on how to use the request:
10628 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10629 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10630 // This is not system caller which has been checked above
10631 throw new IllegalArgumentException(
10632 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10633 }
10634
10635 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10636 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10637 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10638 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10639 || info.isEnabled()) {
10640 throw new IllegalArgumentException(
10641 "Only system can set hide fields in SignalThresholdInfo");
10642 }
10643
10644 // Thresholds length for each RAN need in range. This has been validated in
10645 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10646 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10647 final int[] thresholds = info.getThresholds();
10648 Objects.requireNonNull(thresholds);
10649 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10650 || thresholds.length
10651 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10652 throw new IllegalArgumentException(
10653 "thresholds length is out of range: " + thresholds.length);
10654 }
10655 }
10656 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010657
10658 /**
10659 * Gets the current phone capability.
10660 *
10661 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10662 * @return the PhoneCapability which describes the data connection capability of modem.
10663 * It's used to evaluate possible phone config change, for example from single
10664 * SIM device to multi-SIM device.
10665 */
10666 @Override
10667 public PhoneCapability getPhoneCapability() {
10668 enforceReadPrivilegedPermission("getPhoneCapability");
10669 final long identity = Binder.clearCallingIdentity();
10670 try {
10671 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10672 } finally {
10673 Binder.restoreCallingIdentity(identity);
10674 }
10675 }
Michele Berionne5e411512020-11-13 02:36:59 +000010676
10677 /**
10678 * Prepare TelephonyManager for an unattended reboot. The reboot is
10679 * required to be done shortly after the API is invoked.
10680 */
10681 @Override
10682 @TelephonyManager.PrepareUnattendedRebootResult
10683 public int prepareForUnattendedReboot() {
10684 enforceRebootPermission();
10685
10686 final long identity = Binder.clearCallingIdentity();
10687 try {
10688 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10689 } finally {
10690 Binder.restoreCallingIdentity(identity);
10691 }
10692 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010693
10694 /**
10695 * Request to get the current slicing configuration including URSP rules and
10696 * NSSAIs (configured, allowed and rejected).
10697 *
10698 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10699 */
10700 @Override
10701 public void getSlicingConfig(ResultReceiver callback) {
10702 enforceReadPrivilegedPermission("getSlicingConfig");
10703
10704 final long identity = Binder.clearCallingIdentity();
10705 try {
10706 Phone phone = getDefaultPhone();
10707 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010712}