blob: eeccf0ff2581ae3fbea246dbb6fbcbd74e1ba36b [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000032import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080033import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070034import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070035import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.content.Context;
37import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070039import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080040import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070041import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
43import android.os.AsyncResult;
44import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080045import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Bundle;
47import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Looper;
50import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080052import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070053import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070054import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080055import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080056import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070057import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070058import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080059import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070061import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070063import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070064import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080065import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070066import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090067import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080068import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080069import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070070import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070071import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080072import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080073import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800111import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800140import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700143import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700144import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800145import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700150import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800151import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800152import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800153import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700154import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800156import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700160import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700163import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800164import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700165import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700166import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700167import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700168import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800169import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800170import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700172import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800174import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800175import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800176import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700177import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700179import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800180import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700181import com.android.internal.telephony.imsphone.ImsPhone;
182import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800183import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700184import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800186import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccUtils;
Grace Jia59437e82021-09-21 15:47:32 -0700188import com.android.internal.telephony.uicc.PinStorage;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700190import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800191import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700192import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800193import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000194import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800195import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700196import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700197import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800198import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800199import com.android.phone.callcomposer.CallComposerPictureManager;
200import com.android.phone.callcomposer.CallComposerPictureTransfer;
201import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700202import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700203import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800204import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700205import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700206import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800207import com.android.services.telephony.TelecomAccountRegistry;
208import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800209import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800210
Hall Liu82694d52020-12-11 18:22:04 -0800211import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700212import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800213import java.io.IOException;
214import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700215import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800217import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800218import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800219import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800220import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100221import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700223import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800226import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800227import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800228import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
230/**
231 * Implementation of the ITelephony interface.
232 */
Santos Cordon117fee72014-05-16 17:56:12 -0700233public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234 private static final String LOG_TAG = "PhoneInterfaceManager";
235 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
236 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800237 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238
239 // Message codes used with mMainThreadHandler
240 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700241 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
242 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243 private static final int CMD_OPEN_CHANNEL = 9;
244 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
245 private static final int CMD_CLOSE_CHANNEL = 11;
246 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800247 private static final int CMD_NV_READ_ITEM = 13;
248 private static final int EVENT_NV_READ_ITEM_DONE = 14;
249 private static final int CMD_NV_WRITE_ITEM = 15;
250 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
251 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
252 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700253 private static final int CMD_RESET_MODEM_CONFIG = 19;
254 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800255 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
256 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800257 private static final int CMD_SEND_ENVELOPE = 25;
258 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000259 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
260 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700261 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
262 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
263 private static final int CMD_EXCHANGE_SIM_IO = 31;
264 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800265 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
266 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700267 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
268 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700269 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
270 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700271 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
272 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
273 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
274 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700275 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
276 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
277 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
278 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700279 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800280 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
281 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000282 private static final int CMD_SWITCH_SLOTS = 50;
283 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700284 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
285 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
286 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
287 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
288 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
289 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
290 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
291 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700292 private static final int CMD_GET_ALL_CELL_INFO = 60;
293 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
294 private static final int CMD_GET_CELL_LOCATION = 62;
295 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700296 private static final int CMD_MODEM_REBOOT = 64;
297 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700298 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
299 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800300 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
301 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700302 private static final int CMD_GET_MODEM_STATUS = 70;
303 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700304 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
305 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700306 private static final int CMD_ERASE_MODEM_CONFIG = 74;
307 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800308 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
309 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
310 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
311 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800312 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
313 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800315 private static final int CMD_GET_CALL_FORWARDING = 83;
316 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
317 private static final int CMD_SET_CALL_FORWARDING = 85;
318 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
319 private static final int CMD_GET_CALL_WAITING = 87;
320 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
321 private static final int CMD_SET_CALL_WAITING = 89;
322 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700323 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
324 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
325 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
326 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700327 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
328 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800329 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
330 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800331 private static final int CMD_SET_DATA_THROTTLING = 99;
332 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800333 private static final int CMD_SET_SIM_POWER = 101;
334 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800335 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
336 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
337 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
338 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800339 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
340 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000341 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800342 private static final int CMD_GET_SLICING_CONFIG = 110;
343 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800344 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800346 // Parameters of select command.
347 private static final int SELECT_COMMAND = 0xA4;
348 private static final int SELECT_P1 = 0x04;
349 private static final int SELECT_P2 = 0;
350 private static final int SELECT_P3 = 0x10;
351
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 /** The singleton instance. */
353 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800354 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355
Wink Saville3ab207e2014-11-20 13:07:20 -0800356 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800357 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800358 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700359 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700361 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800362 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800363 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800364 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700365 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800366 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367
Peter Wangdafb9ac2020-01-15 14:13:38 -0800368 /** User Activity */
369 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800370 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
371
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700372 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
373
Derek Tan97ebb422014-09-05 16:55:38 -0700374 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
375 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800376 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800377 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700378
Michelecea4cf22018-12-21 15:00:11 -0800379 // String to store multi SIM allowed
380 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
381
Derek Tan740e1672017-06-27 14:56:27 -0700382 // The AID of ISD-R.
383 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
384
yinxub1bed742017-04-17 11:45:04 -0700385 private NetworkScanRequestTracker mNetworkScanRequestTracker;
386
David Kelly5e06a7f2018-03-12 14:10:59 +0000387 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
388 private static final int MANUFACTURER_CODE_LENGTH = 8;
389
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800390 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800391 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800392
Derek Tan89e89d42014-07-08 17:00:10 -0700393 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700394 * Experiment flag to enable erase modem config on reset network, default value is false
395 */
396 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
397 "reset_network_erase_modem_config_enabled";
398
Rambo Wang0f050d82021-02-12 11:43:36 -0800399 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
400
Naina Nallurid63128d2019-09-17 14:10:30 -0700401 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700402 * A request object to use for transmitting data to an ICC.
403 */
404 private static final class IccAPDUArgument {
405 public int channel, cla, command, p1, p2, p3;
406 public String data;
407
408 public IccAPDUArgument(int channel, int cla, int command,
409 int p1, int p2, int p3, String data) {
410 this.channel = channel;
411 this.cla = cla;
412 this.command = command;
413 this.p1 = p1;
414 this.p2 = p2;
415 this.p3 = p3;
416 this.data = data;
417 }
418 }
419
420 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700421 * A request object to use for transmitting data to an ICC.
422 */
423 private static final class ManualNetworkSelectionArgument {
424 public OperatorInfo operatorInfo;
425 public boolean persistSelection;
426
427 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
428 this.operatorInfo = operatorInfo;
429 this.persistSelection = persistSelection;
430 }
431 }
432
433 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
435 * request after sending. The main thread will notify the request when it is complete.
436 */
437 private static final class MainThreadRequest {
438 /** The argument to use for the request */
439 public Object argument;
440 /** The result of the request that is run on the main thread */
441 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800442 // The subscriber id that this request applies to. Defaults to
443 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
444 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Nathan Harold92bed182018-10-12 18:16:49 -0700446 // In cases where subId is unavailable, the caller needs to specify the phone.
447 public Phone phone;
448
vagdeviaf9a5b92018-08-15 16:01:53 -0700449 public WorkSource workSource;
450
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 public MainThreadRequest(Object argument) {
452 this.argument = argument;
453 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800454
Nathan Harold92bed182018-10-12 18:16:49 -0700455 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
456 this.argument = argument;
457 if (phone != null) {
458 this.phone = phone;
459 }
460 this.workSource = workSource;
461 }
462
vagdeviaf9a5b92018-08-15 16:01:53 -0700463 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800464 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800465 if (subId != null) {
466 this.subId = subId;
467 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700468 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 }
471
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800472 private static final class IncomingThirdPartyCallArgs {
473 public final ComponentName component;
474 public final String callId;
475 public final String callerDisplayName;
476
477 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
478 String callerDisplayName) {
479 this.component = component;
480 this.callId = callId;
481 this.callerDisplayName = callerDisplayName;
482 }
483 }
484
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 /**
486 * A handler that processes messages on the main thread in the phone process. Since many
487 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
488 * inbound binder threads to the main thread in the phone process. The Binder thread
489 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
490 * on, which will be notified when the operation completes and will contain the result of the
491 * request.
492 *
493 * <p>If a MainThreadRequest object is provided in the msg.obj field,
494 * note that request.result must be set to something non-null for the calling thread to
495 * unblock.
496 */
497 private final class MainThreadHandler extends Handler {
498 @Override
499 public void handleMessage(Message msg) {
500 MainThreadRequest request;
501 Message onCompleted;
502 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800503 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800505 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506
507 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 case CMD_HANDLE_USSD_REQUEST: {
509 request = (MainThreadRequest) msg.obj;
510 final Phone phone = getPhoneFromRequest(request);
511 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
512 String ussdRequest = ussdObject.first;
513 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700514
Pengquan Menga1bb6272018-09-06 09:59:22 -0700515 if (!isUssdApiAllowed(request.subId)) {
516 // Carrier does not support use of this API, return failure.
517 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
518 UssdResponse response = new UssdResponse(ussdRequest, null);
519 Bundle returnData = new Bundle();
520 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
521 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700522
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 request.result = true;
524 notifyRequester(request);
525 return;
526 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700527
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 try {
529 request.result = phone != null
530 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
531 } catch (CallStateException cse) {
532 request.result = false;
533 }
534 // Wake up the requesting thread
535 notifyRequester(request);
536 break;
pkanwar32d516d2016-10-14 19:37:38 -0700537 }
538
Yorke Lee716f67e2015-06-17 15:39:16 -0700539 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700541 final Phone phone = getPhoneFromRequest(request);
542 request.result = phone != null ?
543 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
544 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700547 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700550 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800553 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 if (uiccCard == null) {
555 loge("iccTransmitApduLogicalChannel: No UICC");
556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
560 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 iccArgument.channel, iccArgument.cla, iccArgument.command,
563 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 break;
567
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
571 if (ar.exception == null && ar.result != null) {
572 request.result = ar.result;
573 } else {
574 request.result = new IccIoResult(0x6F, 0, (byte[])null);
575 if (ar.result == null) {
576 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800577 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800579 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 } else {
581 loge("iccTransmitApduLogicalChannel: Unknown exception");
582 }
583 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 break;
586
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
588 request = (MainThreadRequest) msg.obj;
589 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 if (uiccCard == null) {
592 loge("iccTransmitApduBasicChannel: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
597 request);
598 uiccCard.iccTransmitApduBasicChannel(
599 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
600 iccArgument.p3, iccArgument.data, onCompleted);
601 }
602 break;
603
604 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
609 } else {
610 request.result = new IccIoResult(0x6F, 0, (byte[])null);
611 if (ar.result == null) {
612 loge("iccTransmitApduBasicChannel: Empty response");
613 } else if (ar.exception instanceof CommandException) {
614 loge("iccTransmitApduBasicChannel: CommandException: " +
615 ar.exception);
616 } else {
617 loge("iccTransmitApduBasicChannel: Unknown exception");
618 }
619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 break;
622
623 case CMD_EXCHANGE_SIM_IO:
624 request = (MainThreadRequest) msg.obj;
625 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800626 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 if (uiccCard == null) {
628 loge("iccExchangeSimIO: No UICC");
629 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
633 request);
634 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
635 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
636 iccArgument.data, onCompleted);
637 }
638 break;
639
640 case EVENT_EXCHANGE_SIM_IO_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
646 request.result = new IccIoResult(0x6f, 0, (byte[])null);
647 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 break;
650
Derek Tan4d5e5c12014-02-04 11:54:58 -0800651 case CMD_SEND_ENVELOPE:
652 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800653 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 if (uiccCard == null) {
655 loge("sendEnvelopeWithStatus: No UICC");
656 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 } else {
659 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
660 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
661 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800662 break;
663
664 case EVENT_SEND_ENVELOPE_DONE:
665 ar = (AsyncResult) msg.obj;
666 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700667 if (ar.exception == null && ar.result != null) {
668 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800669 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700670 request.result = new IccIoResult(0x6F, 0, (byte[])null);
671 if (ar.result == null) {
672 loge("sendEnvelopeWithStatus: Empty response");
673 } else if (ar.exception instanceof CommandException) {
674 loge("sendEnvelopeWithStatus: CommandException: " +
675 ar.exception);
676 } else {
677 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
678 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800679 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800681 break;
682
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 case CMD_OPEN_CHANNEL:
684 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800685 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800686 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700687 if (uiccCard == null) {
688 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800689 request.result = new IccOpenLogicalChannelResponse(-1,
690 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 } else {
693 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800694 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
695 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700696 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 break;
698
699 case EVENT_OPEN_CHANNEL_DONE:
700 ar = (AsyncResult) msg.obj;
701 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700702 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 int[] result = (int[]) ar.result;
705 int channelId = result[0];
706 byte[] selectResponse = null;
707 if (result.length > 1) {
708 selectResponse = new byte[result.length - 1];
709 for (int i = 1; i < result.length; ++i) {
710 selectResponse[i - 1] = (byte) result[i];
711 }
712 }
713 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700714 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 if (ar.result == null) {
717 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 if (ar.exception != null) {
720 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
721 }
722
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700723 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700724 if (ar.exception instanceof CommandException) {
725 CommandException.Error error =
726 ((CommandException) (ar.exception)).getCommandError();
727 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700728 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700729 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700730 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700731 }
732 }
733 openChannelResp = new IccOpenLogicalChannelResponse(
734 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700736 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 break;
739
740 case CMD_CLOSE_CHANNEL:
741 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800742 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700743 if (uiccCard == null) {
744 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900745 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700746 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700747 } else {
748 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
749 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
750 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700751 break;
752
753 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800754 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
755 break;
756
757 case CMD_NV_READ_ITEM:
758 request = (MainThreadRequest) msg.obj;
759 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800760 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
761 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800762 break;
763
764 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 ar = (AsyncResult) msg.obj;
766 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800767 if (ar.exception == null && ar.result != null) {
768 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800770 request.result = "";
771 if (ar.result == null) {
772 loge("nvReadItem: Empty response");
773 } else if (ar.exception instanceof CommandException) {
774 loge("nvReadItem: CommandException: " +
775 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800777 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 }
779 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 break;
782
Jake Hambye994d462014-02-03 13:10:13 -0800783 case CMD_NV_WRITE_ITEM:
784 request = (MainThreadRequest) msg.obj;
785 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
786 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800787 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700788 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
791 case EVENT_NV_WRITE_ITEM_DONE:
792 handleNullReturnEvent(msg, "nvWriteItem");
793 break;
794
795 case CMD_NV_WRITE_CDMA_PRL:
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800798 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800799 break;
800
801 case EVENT_NV_WRITE_CDMA_PRL_DONE:
802 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
803 break;
804
chen xu6dac5ab2018-10-26 17:39:23 -0700805 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800806 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700807 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800808 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800809 break;
810
chen xu6dac5ab2018-10-26 17:39:23 -0700811 case EVENT_RESET_MODEM_CONFIG_DONE:
812 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800813 break;
814
Sooraj Sasindran37444802020-08-11 10:40:43 -0700815 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
818 request);
819 Phone phone = getPhoneFromRequest(request);
820 if (phone != null) {
821 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
822 } else {
823 loge("isNRDualConnectivityEnabled: No phone object");
824 request.result = false;
825 notifyRequester(request);
826 }
827 break;
828 }
829
830 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
831 ar = (AsyncResult) msg.obj;
832 request = (MainThreadRequest) ar.userObj;
833 if (ar.exception == null && ar.result != null) {
834 request.result = ar.result;
835 } else {
836 // request.result must be set to something non-null
837 // for the calling thread to unblock
838 if (request.result != null) {
839 request.result = ar.result;
840 } else {
841 request.result = false;
842 }
843 if (ar.result == null) {
844 loge("isNRDualConnectivityEnabled: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("isNRDualConnectivityEnabled: CommandException: "
847 + ar.exception);
848 } else {
849 loge("isNRDualConnectivityEnabled: Unknown exception");
850 }
851 }
852 notifyRequester(request);
853 break;
854
855 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
858 Phone phone = getPhoneFromRequest(request);
859 if (phone != null) {
860 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
861 request.workSource);
862 } else {
863 loge("enableNrDualConnectivity: No phone object");
864 request.result =
865 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
866 notifyRequester(request);
867 }
868 break;
869 }
870
871 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
872 ar = (AsyncResult) msg.obj;
873 request = (MainThreadRequest) ar.userObj;
874 if (ar.exception == null) {
875 request.result =
876 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
877 } else {
878 request.result =
879 TelephonyManager
880 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
881 if (ar.exception instanceof CommandException) {
882 CommandException.Error error =
883 ((CommandException) (ar.exception)).getCommandError();
884 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
885 request.result =
886 TelephonyManager
887 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000888 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
889 request.result =
890 TelephonyManager
891 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700892 }
893 loge("enableNrDualConnectivity" + ": CommandException: "
894 + ar.exception);
895 } else {
896 loge("enableNrDualConnectivity" + ": Unknown exception");
897 }
898 }
899 notifyRequester(request);
900 break;
901 }
902
SongFerngWang3ef3e072020-12-21 16:41:52 +0800903 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800905 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
906 request);
907 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 break;
909
SongFerngWang3ef3e072020-12-21 16:41:52 +0800910 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result; // Integer
915 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530916 // request.result must be set to something non-null
917 // for the calling thread to unblock
918 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800920 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800922 loge("getAllowedNetworkTypesBitmask: CommandException: "
923 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800924 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800925 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800926 }
927 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700928 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800929 break;
930
SongFerngWang3ef3e072020-12-21 16:41:52 +0800931 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800932 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800933 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
934 request);
935 Pair<Integer, Long> reasonWithNetworkTypes =
936 (Pair<Integer, Long>) request.argument;
937 getPhoneFromRequest(request).setAllowedNetworkTypes(
938 reasonWithNetworkTypes.first,
939 reasonWithNetworkTypes.second,
940 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800941 break;
942
SongFerngWang3ef3e072020-12-21 16:41:52 +0800943 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
944 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800945 break;
946
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000947 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
948 request = (MainThreadRequest)msg.obj;
949 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800950 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000951 break;
952
953 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
954 ar = (AsyncResult)msg.obj;
955 request = (MainThreadRequest)ar.userObj;
956 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700957 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000958 break;
959
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800960 case CMD_SET_VOICEMAIL_NUMBER:
961 request = (MainThreadRequest) msg.obj;
962 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
963 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800964 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
965 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800966 break;
967
968 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
969 handleNullReturnEvent(msg, "setVoicemailNumber");
970 break;
971
Stuart Scott54788802015-03-30 13:18:01 -0700972 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
973 request = (MainThreadRequest) msg.obj;
974 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
975 request);
976 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
977 break;
978
979 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
980 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
981 break;
982
Shishir Agrawal302c8692015-06-19 13:49:39 -0700983 case CMD_PERFORM_NETWORK_SCAN:
984 request = (MainThreadRequest) msg.obj;
985 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
986 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
987 break;
988
Hall Liu27d24262020-09-18 19:04:59 -0700989 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700992 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
993 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
994 request.argument;
995 int callForwardingReason = args.first;
996 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800997 break;
Hall Liu27d24262020-09-18 19:04:59 -0700998 }
999 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001002 TelephonyManager.CallForwardingInfoCallback callback =
1003 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1004 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001005 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001006 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001007 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1008 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1009 // Service Class is a bit mask per 3gpp 27.007. Search for
1010 // any service for voice call.
1011 if ((callForwardInfo.serviceClass
1012 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001013 callForwardingInfo = new CallForwardingInfo(true,
1014 callForwardInfo.reason,
1015 callForwardInfo.number,
1016 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001017 break;
1018 }
1019 }
1020 // Didn't find a call forward info for voice call.
1021 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001022 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1023 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001024 }
Hall Liu27d24262020-09-18 19:04:59 -07001025 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001026 } else {
1027 if (ar.result == null) {
1028 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1029 }
1030 if (ar.exception != null) {
1031 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1032 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001033 int errorCode = TelephonyManager
1034 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001035 if (ar.exception instanceof CommandException) {
1036 CommandException.Error error =
1037 ((CommandException) (ar.exception)).getCommandError();
1038 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001039 errorCode = TelephonyManager
1040 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001041 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001042 errorCode = TelephonyManager
1043 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001044 }
1045 }
Hall Liu27d24262020-09-18 19:04:59 -07001046 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001047 }
Shuo Qian4a594052020-01-23 11:59:30 -08001048 break;
Hall Liu27d24262020-09-18 19:04:59 -07001049 }
Shuo Qian4a594052020-01-23 11:59:30 -08001050
Hall Liu27d24262020-09-18 19:04:59 -07001051 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001052 request = (MainThreadRequest) msg.obj;
1053 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001054 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001055 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001056 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1057 request.argument).first;
1058 request.phone.setCallForwardingOption(
1059 callForwardingInfoToSet.isEnabled()
1060 ? CommandsInterface.CF_ACTION_ENABLE
1061 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001062 callForwardingInfoToSet.getReason(),
1063 callForwardingInfoToSet.getNumber(),
1064 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1065 break;
Hall Liu27d24262020-09-18 19:04:59 -07001066 }
Shuo Qian4a594052020-01-23 11:59:30 -08001067
Hall Liu27d24262020-09-18 19:04:59 -07001068 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001069 ar = (AsyncResult) msg.obj;
1070 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001071 Consumer<Integer> callback =
1072 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1073 request.argument).second;
1074 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001075 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001076 int errorCode = TelephonyManager.CallForwardingInfoCallback
1077 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001078 if (ar.exception instanceof CommandException) {
1079 CommandException.Error error =
1080 ((CommandException) (ar.exception)).getCommandError();
1081 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001082 errorCode = TelephonyManager.CallForwardingInfoCallback
1083 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001084 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001085 errorCode = TelephonyManager.CallForwardingInfoCallback
1086 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001087 }
1088 }
1089 callback.accept(errorCode);
1090 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001091 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001092 }
Shuo Qian4a594052020-01-23 11:59:30 -08001093 break;
Hall Liu27d24262020-09-18 19:04:59 -07001094 }
Shuo Qian4a594052020-01-23 11:59:30 -08001095
Hall Liu27d24262020-09-18 19:04:59 -07001096 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001097 request = (MainThreadRequest) msg.obj;
1098 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1099 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1100 break;
Hall Liu27d24262020-09-18 19:04:59 -07001101 }
Shuo Qian4a594052020-01-23 11:59:30 -08001102
Hall Liu27d24262020-09-18 19:04:59 -07001103 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001104 ar = (AsyncResult) msg.obj;
1105 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001106 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001107 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1108 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001109 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001110 // Service Class is a bit mask per 3gpp 27.007.
1111 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001112 if (callForwardResults.length > 1
1113 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001114 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001115 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001116 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1117 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001118 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001119 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001120 }
1121 } else {
1122 if (ar.result == null) {
1123 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1124 }
1125 if (ar.exception != null) {
1126 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1127 }
1128 if (ar.exception instanceof CommandException) {
1129 CommandException.Error error =
1130 ((CommandException) (ar.exception)).getCommandError();
1131 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1132 callForwardingStatus =
1133 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1134 }
1135 }
1136 }
Hall Liu27d24262020-09-18 19:04:59 -07001137 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001138 break;
Hall Liu27d24262020-09-18 19:04:59 -07001139 }
Shuo Qian4a594052020-01-23 11:59:30 -08001140
Hall Liu27d24262020-09-18 19:04:59 -07001141 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001142 request = (MainThreadRequest) msg.obj;
1143 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001144 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1145 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001146 break;
Hall Liu27d24262020-09-18 19:04:59 -07001147 }
Shuo Qian4a594052020-01-23 11:59:30 -08001148
Hall Liu27d24262020-09-18 19:04:59 -07001149 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001152 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1153 Consumer<Integer> callback =
1154 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1155 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001156 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001157 if (ar.exception instanceof CommandException) {
1158 CommandException.Error error =
1159 ((CommandException) (ar.exception)).getCommandError();
1160 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1161 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1162 } else {
1163 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1164 }
1165 } else {
1166 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1167 }
1168 } else {
1169 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1170 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001171 }
Shuo Qian4a594052020-01-23 11:59:30 -08001172 break;
Hall Liu27d24262020-09-18 19:04:59 -07001173 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001174 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1175 ar = (AsyncResult) msg.obj;
1176 request = (MainThreadRequest) ar.userObj;
1177 CellNetworkScanResult cellScanResult;
1178 if (ar.exception == null && ar.result != null) {
1179 cellScanResult = new CellNetworkScanResult(
1180 CellNetworkScanResult.STATUS_SUCCESS,
1181 (List<OperatorInfo>) ar.result);
1182 } else {
1183 if (ar.result == null) {
1184 loge("getCellNetworkScanResults: Empty response");
1185 }
1186 if (ar.exception != null) {
1187 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1188 }
1189 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1190 if (ar.exception instanceof CommandException) {
1191 CommandException.Error error =
1192 ((CommandException) (ar.exception)).getCommandError();
1193 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1194 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1195 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1196 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1197 }
1198 }
1199 cellScanResult = new CellNetworkScanResult(errorCode, null);
1200 }
1201 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001202 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001203 break;
1204
1205 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1206 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001207 ManualNetworkSelectionArgument selArg =
1208 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001209 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1210 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001211 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1212 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001213 break;
1214
1215 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001216 ar = (AsyncResult) msg.obj;
1217 request = (MainThreadRequest) ar.userObj;
1218 if (ar.exception == null) {
1219 request.result = true;
1220 } else {
1221 request.result = false;
1222 loge("setNetworkSelectionModeManual " + ar.exception);
1223 }
1224 notifyRequester(request);
1225 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001226 break;
1227
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001228 case CMD_GET_MODEM_ACTIVITY_INFO:
1229 request = (MainThreadRequest) msg.obj;
1230 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001231 if (defaultPhone != null) {
1232 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001233 } else {
1234 ResultReceiver result = (ResultReceiver) request.argument;
1235 Bundle bundle = new Bundle();
1236 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001237 new ModemActivityInfo(0, 0, 0,
1238 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001239 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001240 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001241 break;
1242
Hall Liud0f208c2020-10-14 16:54:44 -07001243 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001244 ar = (AsyncResult) msg.obj;
1245 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001246 ResultReceiver result = (ResultReceiver) request.argument;
1247
Hall Liud0f208c2020-10-14 16:54:44 -07001248 ModemActivityInfo ret = null;
1249 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001250 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001251 // Update the last modem activity info and the result of the request.
1252 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1253 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001254 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001255 int[] txTimeMs = info.getTransmitTimeMillis();
1256 int[] lastModemTxTimeMs = mLastModemActivityInfo
1257 .getTransmitTimeMillis();
1258 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1259 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1260 }
Hall Liu49656c02020-10-09 19:00:11 -07001261 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001262 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1263 + mLastModemActivityInfo.getSleepTimeMillis());
1264 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1265 + mLastModemActivityInfo.getIdleTimeMillis());
1266 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1267 mLastModemActivityInfo.setReceiveTimeMillis(
1268 info.getReceiveTimeMillis()
1269 + mLastModemActivityInfo.getReceiveTimeMillis());
1270 }
Hall Liu49656c02020-10-09 19:00:11 -07001271 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001272 mLastModemActivityInfo.getSleepTimeMillis(),
1273 mLastModemActivityInfo.getIdleTimeMillis(),
1274 mLastModemActivityInfo.getTransmitTimeMillis(),
1275 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001276 } else {
1277 if (ar.result == null) {
1278 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001279 error = TelephonyManager.ModemActivityInfoException
1280 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001281 } else if (ar.exception instanceof CommandException) {
1282 loge("queryModemActivityInfo: CommandException: " +
1283 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001284 error = TelephonyManager.ModemActivityInfoException
1285 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001286 } else {
1287 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001288 error = TelephonyManager.ModemActivityInfoException
1289 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001290 }
1291 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001292 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001293 if (ret != null) {
1294 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1295 } else {
1296 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1297 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001298 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001299 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001300 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001301 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001302
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 case CMD_SET_ALLOWED_CARRIERS:
1304 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001305 CarrierRestrictionRules argument =
1306 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001307 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001308 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001309 break;
1310
1311 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1312 ar = (AsyncResult) msg.obj;
1313 request = (MainThreadRequest) ar.userObj;
1314 if (ar.exception == null && ar.result != null) {
1315 request.result = ar.result;
1316 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001317 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1318 if (ar.exception instanceof CommandException) {
1319 loge("setAllowedCarriers: CommandException: " + ar.exception);
1320 CommandException.Error error =
1321 ((CommandException) (ar.exception)).getCommandError();
1322 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1323 request.result =
1324 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1325 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001326 } else {
1327 loge("setAllowedCarriers: Unknown exception");
1328 }
1329 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001330 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001331 break;
1332
1333 case CMD_GET_ALLOWED_CARRIERS:
1334 request = (MainThreadRequest) msg.obj;
1335 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001336 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001337 break;
1338
1339 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1340 ar = (AsyncResult) msg.obj;
1341 request = (MainThreadRequest) ar.userObj;
1342 if (ar.exception == null && ar.result != null) {
1343 request.result = ar.result;
1344 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001345 request.result = new IllegalStateException(
1346 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001347 if (ar.result == null) {
1348 loge("getAllowedCarriers: Empty response");
1349 } else if (ar.exception instanceof CommandException) {
1350 loge("getAllowedCarriers: CommandException: " +
1351 ar.exception);
1352 } else {
1353 loge("getAllowedCarriers: Unknown exception");
1354 }
1355 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001356 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001357 break;
1358
Nathan Haroldb3014052017-01-25 15:57:32 -08001359 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1360 ar = (AsyncResult) msg.obj;
1361 request = (MainThreadRequest) ar.userObj;
1362 if (ar.exception == null && ar.result != null) {
1363 request.result = ar.result;
1364 } else {
1365 request.result = new IllegalArgumentException(
1366 "Failed to retrieve Forbidden Plmns");
1367 if (ar.result == null) {
1368 loge("getForbiddenPlmns: Empty response");
1369 } else {
1370 loge("getForbiddenPlmns: Unknown exception");
1371 }
1372 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001373 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001374 break;
1375
1376 case CMD_GET_FORBIDDEN_PLMNS:
1377 request = (MainThreadRequest) msg.obj;
1378 uiccCard = getUiccCardFromRequest(request);
1379 if (uiccCard == null) {
1380 loge("getForbiddenPlmns() UiccCard is null");
1381 request.result = new IllegalArgumentException(
1382 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001383 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001384 break;
1385 }
1386 Integer appType = (Integer) request.argument;
1387 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1388 if (uiccApp == null) {
1389 loge("getForbiddenPlmns() no app with specified type -- "
1390 + appType);
1391 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001392 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001393 break;
1394 } else {
1395 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1396 + " specified type -- " + appType);
1397 }
1398 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1399 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1400 onCompleted);
1401 break;
1402
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001403 case CMD_SWITCH_SLOTS:
1404 request = (MainThreadRequest) msg.obj;
1405 int[] physicalSlots = (int[]) request.argument;
1406 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1407 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1408 break;
1409
1410 case EVENT_SWITCH_SLOTS_DONE:
1411 ar = (AsyncResult) msg.obj;
1412 request = (MainThreadRequest) ar.userObj;
1413 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001414 notifyRequester(request);
1415 break;
1416 case CMD_GET_NETWORK_SELECTION_MODE:
1417 request = (MainThreadRequest) msg.obj;
1418 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1419 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1420 break;
1421
1422 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1423 ar = (AsyncResult) msg.obj;
1424 request = (MainThreadRequest) ar.userObj;
1425 if (ar.exception != null) {
1426 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1427 } else {
1428 int mode = ((int[]) ar.result)[0];
1429 if (mode == 0) {
1430 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1431 } else {
1432 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1433 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001434 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001435 notifyRequester(request);
1436 break;
1437 case CMD_GET_CDMA_ROAMING_MODE:
1438 request = (MainThreadRequest) msg.obj;
1439 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1440 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1441 break;
1442 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1443 ar = (AsyncResult) msg.obj;
1444 request = (MainThreadRequest) ar.userObj;
1445 if (ar.exception != null) {
1446 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1447 } else {
1448 request.result = ((int[]) ar.result)[0];
1449 }
1450 notifyRequester(request);
1451 break;
1452 case CMD_SET_CDMA_ROAMING_MODE:
1453 request = (MainThreadRequest) msg.obj;
1454 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1455 int mode = (int) request.argument;
1456 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1457 break;
1458 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1459 ar = (AsyncResult) msg.obj;
1460 request = (MainThreadRequest) ar.userObj;
1461 request.result = ar.exception == null;
1462 notifyRequester(request);
1463 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001464 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1465 request = (MainThreadRequest) msg.obj;
1466 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1467 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1468 break;
1469 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1470 ar = (AsyncResult) msg.obj;
1471 request = (MainThreadRequest) ar.userObj;
1472 if (ar.exception != null) {
1473 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1474 } else {
1475 request.result = ((int[]) ar.result)[0];
1476 }
1477 notifyRequester(request);
1478 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001479 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1480 request = (MainThreadRequest) msg.obj;
1481 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1482 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001483 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1484 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001485 break;
1486 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1487 ar = (AsyncResult) msg.obj;
1488 request = (MainThreadRequest) ar.userObj;
1489 request.result = ar.exception == null;
1490 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001491 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 case CMD_GET_ALL_CELL_INFO:
1493 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001494 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001495 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001496 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001497 case EVENT_GET_ALL_CELL_INFO_DONE:
1498 ar = (AsyncResult) msg.obj;
1499 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001500 // If a timeout occurs, the response will be null
1501 request.result = (ar.exception == null && ar.result != null)
1502 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001503 synchronized (request) {
1504 request.notifyAll();
1505 }
1506 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001507 case CMD_REQUEST_CELL_INFO_UPDATE:
1508 request = (MainThreadRequest) msg.obj;
1509 request.phone.requestCellInfoUpdate(request.workSource,
1510 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1511 break;
1512 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1513 ar = (AsyncResult) msg.obj;
1514 request = (MainThreadRequest) ar.userObj;
1515 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1516 try {
1517 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001518 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001519 cb.onError(
1520 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1521 ar.exception.getClass().getName(),
1522 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001523 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001524 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001525 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001526 } else {
1527 // use the result as returned
1528 cb.onCellInfo((List<CellInfo>) ar.result);
1529 }
1530 } catch (RemoteException re) {
1531 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1532 }
1533 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001534 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001535 request = (MainThreadRequest) msg.obj;
1536 WorkSource ws = (WorkSource) request.argument;
1537 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001538 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001539 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001540 }
1541 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001542 ar = (AsyncResult) msg.obj;
1543 request = (MainThreadRequest) ar.userObj;
1544 if (ar.exception == null) {
1545 request.result = ar.result;
1546 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001547 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001548 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001549 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001550 }
1551
1552 synchronized (request) {
1553 request.notifyAll();
1554 }
1555 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001556 }
chen xu6dac5ab2018-10-26 17:39:23 -07001557 case CMD_MODEM_REBOOT:
1558 request = (MainThreadRequest) msg.obj;
1559 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001560 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001561 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001562 case EVENT_CMD_MODEM_REBOOT_DONE:
1563 handleNullReturnEvent(msg, "rebootModem");
1564 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001565 case CMD_REQUEST_ENABLE_MODEM:
1566 request = (MainThreadRequest) msg.obj;
1567 boolean enable = (boolean) request.argument;
1568 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001569 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001570 PhoneConfigurationManager.getInstance()
1571 .enablePhone(request.phone, enable, onCompleted);
1572 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001573 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001574 ar = (AsyncResult) msg.obj;
1575 request = (MainThreadRequest) ar.userObj;
1576 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001577 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001578 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001579 if ((boolean) request.result) {
1580 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1581 updateModemStateMetrics();
1582 } else {
1583 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1584 + ar.exception);
1585 }
1586 notifyRequester(request);
1587 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001588 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001589 case CMD_GET_MODEM_STATUS:
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1592 PhoneConfigurationManager.getInstance()
1593 .getPhoneStatusFromModem(request.phone, onCompleted);
1594 break;
1595 case EVENT_GET_MODEM_STATUS_DONE:
1596 ar = (AsyncResult) msg.obj;
1597 request = (MainThreadRequest) ar.userObj;
1598 int id = request.phone.getPhoneId();
1599 if (ar.exception == null && ar.result != null) {
1600 request.result = ar.result;
1601 //update the cache as modem status has changed
1602 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1603 (boolean) request.result);
1604 } else {
1605 // Return true if modem status cannot be retrieved. For most cases,
1606 // modem status is on. And for older version modems, GET_MODEM_STATUS
1607 // and disable modem are not supported. Modem is always on.
1608 // TODO: this should be fixed in R to support a third
1609 // status UNKNOWN b/131631629
1610 request.result = true;
1611 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1612 + ar.exception);
1613 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001614 notifyRequester(request);
1615 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001616 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1617 request = (MainThreadRequest) msg.obj;
1618 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1619 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1620 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1621 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1622 break;
1623 }
1624 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1628 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1629 args.second.accept(ar.exception == null);
1630 notifyRequester(request);
1631 break;
1632 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001633 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1634 request = (MainThreadRequest) msg.obj;
1635 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1636 Phone phone = getPhoneFromRequest(request);
1637 if (phone != null) {
1638 phone.getSystemSelectionChannels(onCompleted);
1639 } else {
1640 loge("getSystemSelectionChannels: No phone object");
1641 request.result = new ArrayList<RadioAccessSpecifier>();
1642 notifyRequester(request);
1643 }
1644 break;
1645 }
1646 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1647 ar = (AsyncResult) msg.obj;
1648 request = (MainThreadRequest) ar.userObj;
1649 if (ar.exception == null && ar.result != null) {
1650 request.result = ar.result;
1651 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001652 request.result = new IllegalStateException(
1653 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001654 if (ar.result == null) {
1655 loge("getSystemSelectionChannels: Empty response");
1656 } else {
1657 loge("getSystemSelectionChannels: Unknown exception");
1658 }
1659 }
1660 notifyRequester(request);
1661 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001662 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1663 ar = (AsyncResult) msg.obj;
1664 request = (MainThreadRequest) ar.userObj;
1665 if (ar.exception == null && ar.result != null) {
1666 request.result = ar.result;
1667 } else {
1668 request.result = -1;
1669 loge("Failed to set Forbidden Plmns");
1670 if (ar.result == null) {
1671 loge("setForbidenPlmns: Empty response");
1672 } else if (ar.exception != null) {
1673 loge("setForbiddenPlmns: Exception: " + ar.exception);
1674 request.result = -1;
1675 } else {
1676 loge("setForbiddenPlmns: Unknown exception");
1677 }
1678 }
1679 notifyRequester(request);
1680 break;
1681 case CMD_SET_FORBIDDEN_PLMNS:
1682 request = (MainThreadRequest) msg.obj;
1683 uiccCard = getUiccCardFromRequest(request);
1684 if (uiccCard == null) {
1685 loge("setForbiddenPlmns: UiccCard is null");
1686 request.result = -1;
1687 notifyRequester(request);
1688 break;
1689 }
1690 Pair<Integer, List<String>> setFplmnsArgs =
1691 (Pair<Integer, List<String>>) request.argument;
1692 appType = setFplmnsArgs.first;
1693 List<String> fplmns = setFplmnsArgs.second;
1694 uiccApp = uiccCard.getApplicationByType(appType);
1695 if (uiccApp == null) {
1696 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1697 request.result = -1;
1698 loge("Failed to get UICC App");
1699 notifyRequester(request);
1700 } else {
1701 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1702 ((SIMRecords) uiccApp.getIccRecords())
1703 .setForbiddenPlmns(onCompleted, fplmns);
1704 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001705 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001706 case CMD_ERASE_MODEM_CONFIG:
1707 request = (MainThreadRequest) msg.obj;
1708 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1709 defaultPhone.eraseModemConfig(onCompleted);
1710 break;
1711 case EVENT_ERASE_MODEM_CONFIG_DONE:
1712 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001713 break;
zoey chene02881a2019-12-30 16:11:23 +08001714
Kai Shif70f46f2021-03-03 13:59:46 -08001715 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1716 request = (MainThreadRequest) msg.obj;
1717 request.result = defaultPhone.eraseDataInSharedPreferences();
1718 notifyRequester(request);
1719 break;
1720
zoey chene02881a2019-12-30 16:11:23 +08001721 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1724 Pair<String, String> changed = (Pair<String, String>) request.argument;
1725 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1726 changed.first, changed.second, onCompleted);
1727 break;
1728 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 if (ar.exception == null) {
1732 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001733 // If the operation is successful, update the PIN storage
1734 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1735 int phoneId = getPhoneFromRequest(request).getPhoneId();
Grace Jia59437e82021-09-21 15:47:32 -07001736 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1737 pinStorage.storePin(passwords.second, phoneId,
1738 pinStorage.getIccid(phoneId));
zoey chene02881a2019-12-30 16:11:23 +08001739 } else {
1740 request.result = msg.arg1;
1741 }
1742 notifyRequester(request);
1743 break;
1744
Michele Berionne5e411512020-11-13 02:36:59 +00001745 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1748 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1749 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1750 enabled.first, enabled.second, onCompleted);
1751 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001752 }
zoey chene02881a2019-12-30 16:11:23 +08001753 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756 if (ar.exception == null) {
1757 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001758 // If the operation is successful, update the PIN storage
1759 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1760 int phoneId = getPhoneFromRequest(request).getPhoneId();
1761 if (enabled.first) {
Grace Jia59437e82021-09-21 15:47:32 -07001762 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1763 pinStorage.storePin(enabled.second, phoneId,
1764 pinStorage.getIccid(phoneId));
Michele Berionne5e411512020-11-13 02:36:59 +00001765 } else {
1766 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1767 }
zoey chene02881a2019-12-30 16:11:23 +08001768 } else {
1769 request.result = msg.arg1;
1770 }
Michele Berionne5e411512020-11-13 02:36:59 +00001771
1772
zoey chene02881a2019-12-30 16:11:23 +08001773 notifyRequester(request);
1774 break;
1775
Peter Wangdafb9ac2020-01-15 14:13:38 -08001776 case MSG_NOTIFY_USER_ACTIVITY:
1777 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001778 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001779 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1780 getDefaultPhone().getContext().sendBroadcastAsUser(
1781 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1782 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001783
1784 case CMD_SET_DATA_THROTTLING: {
1785 request = (MainThreadRequest) msg.obj;
1786 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1787 DataThrottlingRequest dataThrottlingRequest =
1788 (DataThrottlingRequest) request.argument;
1789 Phone phone = getPhoneFromRequest(request);
1790 if (phone != null) {
1791 phone.setDataThrottling(onCompleted,
1792 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1793 dataThrottlingRequest.getCompletionDurationMillis());
1794 } else {
1795 loge("setDataThrottling: No phone object");
1796 request.result =
1797 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1798 notifyRequester(request);
1799 }
1800
1801 break;
1802 }
1803 case EVENT_SET_DATA_THROTTLING_DONE:
1804 ar = (AsyncResult) msg.obj;
1805 request = (MainThreadRequest) ar.userObj;
1806
1807 if (ar.exception == null) {
1808 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1809 } else if (ar.exception instanceof CommandException) {
1810 loge("setDataThrottling: CommandException: " + ar.exception);
1811 CommandException.Error error =
1812 ((CommandException) (ar.exception)).getCommandError();
1813
1814 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1815 request.result = TelephonyManager
1816 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1817 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1818 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001819 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1820 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001821 } else {
1822 request.result =
1823 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1824 }
1825 } else {
1826 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1827 }
1828 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1829 notifyRequester(request);
1830 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001831
1832 case CMD_SET_SIM_POWER: {
1833 request = (MainThreadRequest) msg.obj;
1834 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1835 request = (MainThreadRequest) msg.obj;
1836 int stateToSet =
1837 ((Pair<Integer, IIntegerConsumer>)
1838 request.argument).first;
1839 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1840 break;
1841 }
1842 case EVENT_SET_SIM_POWER_DONE: {
1843 ar = (AsyncResult) msg.obj;
1844 request = (MainThreadRequest) ar.userObj;
1845 IIntegerConsumer callback =
1846 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1847 if (ar.exception != null) {
1848 loge("setSimPower exception: " + ar.exception);
1849 int errorCode = TelephonyManager.CallForwardingInfoCallback
1850 .RESULT_ERROR_UNKNOWN;
1851 if (ar.exception instanceof CommandException) {
1852 CommandException.Error error =
1853 ((CommandException) (ar.exception)).getCommandError();
1854 if (error == CommandException.Error.SIM_ERR) {
1855 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1856 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1857 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1858 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1859 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1860 } else {
1861 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1862 }
1863 }
1864 try {
1865 callback.accept(errorCode);
1866 } catch (RemoteException e) {
1867 // Ignore if the remote process is no longer available to call back.
1868 Log.w(LOG_TAG, "setSimPower: callback not available.");
1869 }
1870 } else {
1871 try {
1872 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1873 } catch (RemoteException e) {
1874 // Ignore if the remote process is no longer available to call back.
1875 Log.w(LOG_TAG, "setSimPower: callback not available.");
1876 }
1877 }
1878 break;
1879 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001880 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1881 request = (MainThreadRequest) msg.obj;
1882
1883 final Phone phone = getPhoneFromRequest(request);
1884 if (phone == null || phone.getServiceStateTracker() == null) {
1885 request.result = new IllegalStateException("Phone or SST is null");
1886 notifyRequester(request);
1887 break;
1888 }
1889
1890 Pair<Integer, SignalStrengthUpdateRequest> pair =
1891 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1892 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1893 request);
1894 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1895 request.subId, pair.first /*callingUid*/,
1896 pair.second /*request*/, onCompleted);
1897 break;
1898 }
1899 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1900 ar = (AsyncResult) msg.obj;
1901 request = (MainThreadRequest) ar.userObj;
1902 // request.result will be the exception of ar if present, true otherwise.
1903 // Be cautious not to leave result null which will wait() forever
1904 request.result = ar.exception != null ? ar.exception : true;
1905 notifyRequester(request);
1906 break;
1907 }
1908 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1909 request = (MainThreadRequest) msg.obj;
1910
1911 Phone phone = getPhoneFromRequest(request);
1912 if (phone == null || phone.getServiceStateTracker() == null) {
1913 request.result = new IllegalStateException("Phone or SST is null");
1914 notifyRequester(request);
1915 break;
1916 }
1917
1918 Pair<Integer, SignalStrengthUpdateRequest> pair =
1919 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1920 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1921 request);
1922 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1923 request.subId, pair.first /*callingUid*/,
1924 pair.second /*request*/, onCompleted);
1925 break;
1926 }
1927 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1928 ar = (AsyncResult) msg.obj;
1929 request = (MainThreadRequest) ar.userObj;
1930 request.result = ar.exception != null ? ar.exception : true;
1931 notifyRequester(request);
1932 break;
1933 }
Jordan Liu109698e2020-11-24 14:50:34 -08001934
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001935 case CMD_GET_SLICING_CONFIG: {
1936 request = (MainThreadRequest) msg.obj;
1937 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1938 request.phone.getSlicingConfig(onCompleted);
1939 break;
1940 }
1941 case EVENT_GET_SLICING_CONFIG_DONE: {
1942 ar = (AsyncResult) msg.obj;
1943 request = (MainThreadRequest) ar.userObj;
1944 ResultReceiver result = (ResultReceiver) request.argument;
1945
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001946 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001947 Bundle bundle = new Bundle();
1948 int resultCode = 0;
1949 if (ar.exception != null) {
1950 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1951 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001952 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001953 } else if (ar.result == null) {
1954 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001955 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001956 } else {
1957 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001958 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
1959 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001960 }
1961
1962 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001963 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001964 }
1965 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1966 result.send(resultCode, bundle);
1967 notifyRequester(request);
1968 break;
1969 }
1970
Michele Berionne5e411512020-11-13 02:36:59 +00001971 case CMD_PREPARE_UNATTENDED_REBOOT:
1972 request = (MainThreadRequest) msg.obj;
1973 request.result =
1974 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1975 notifyRequester(request);
1976 break;
1977
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 default:
1979 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1980 break;
1981 }
1982 }
Jake Hambye994d462014-02-03 13:10:13 -08001983
Pengquan Menga1bb6272018-09-06 09:59:22 -07001984 private void notifyRequester(MainThreadRequest request) {
1985 synchronized (request) {
1986 request.notifyAll();
1987 }
1988 }
1989
Jake Hambye994d462014-02-03 13:10:13 -08001990 private void handleNullReturnEvent(Message msg, String command) {
1991 AsyncResult ar = (AsyncResult) msg.obj;
1992 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1993 if (ar.exception == null) {
1994 request.result = true;
1995 } else {
1996 request.result = false;
1997 if (ar.exception instanceof CommandException) {
1998 loge(command + ": CommandException: " + ar.exception);
1999 } else {
2000 loge(command + ": Unknown exception");
2001 }
2002 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002003 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 }
2006
2007 /**
2008 * Posts the specified command to be executed on the main thread,
2009 * waits for the request to complete, and returns the result.
2010 * @see #sendRequestAsync
2011 */
2012 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002013 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2014 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002015 }
2016
2017 /**
2018 * Posts the specified command to be executed on the main thread,
2019 * waits for the request to complete, and returns the result.
2020 * @see #sendRequestAsync
2021 */
2022 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2023 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002024 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002025 }
2026
2027 /**
2028 * Posts the specified command to be executed on the main thread,
2029 * waits for the request to complete, and returns the result.
2030 * @see #sendRequestAsync
2031 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002032 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002033 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2034 }
2035
2036 /**
2037 * Posts the specified command to be executed on the main thread,
2038 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2039 * if not timeout or null otherwise.
2040 * @see #sendRequestAsync
2041 */
2042 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2043 long timeoutInMs) {
2044 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002045 }
2046
2047 /**
2048 * Posts the specified command to be executed on the main thread,
2049 * waits for the request to complete, and returns the result.
2050 * @see #sendRequestAsync
2051 */
Nathan Harold92bed182018-10-12 18:16:49 -07002052 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002053 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002054 }
2055
2056 /**
2057 * Posts the specified command to be executed on the main thread,
2058 * waits for the request to complete, and returns the result.
2059 * @see #sendRequestAsync
2060 */
2061 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002062 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2063 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002064 }
2065
2066 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002067 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2068 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2069 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002070 * @see #sendRequestAsync
2071 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002072 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2073 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2075 throw new RuntimeException("This method will deadlock if called from the main thread.");
2076 }
2077
Nathan Harold92bed182018-10-12 18:16:49 -07002078 MainThreadRequest request = null;
2079 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2080 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2081 } else if (phone != null) {
2082 request = new MainThreadRequest(argument, phone, workSource);
2083 } else {
2084 request = new MainThreadRequest(argument, subId, workSource);
2085 }
2086
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 Message msg = mMainThreadHandler.obtainMessage(command, request);
2088 msg.sendToTarget();
2089
Rambo Wang0f050d82021-02-12 11:43:36 -08002090
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002092 if (timeoutInMs >= 0) {
2093 // Wait for at least timeoutInMs before returning null request result
2094 long now = SystemClock.elapsedRealtime();
2095 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002096 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002097 try {
2098 request.wait(deadline - now);
2099 } catch (InterruptedException e) {
2100 // Do nothing, go back and check if request is completed or timeout
2101 } finally {
2102 now = SystemClock.elapsedRealtime();
2103 }
2104 }
2105 } else {
2106 // Wait for the request to complete
2107 while (request.result == null) {
2108 try {
2109 request.wait();
2110 } catch (InterruptedException e) {
2111 // Do nothing, go back and wait until the request is complete
2112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114 }
2115 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002116 if (request.result == null) {
2117 Log.wtf(LOG_TAG,
2118 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 return request.result;
2121 }
2122
2123 /**
2124 * Asynchronous ("fire and forget") version of sendRequest():
2125 * Posts the specified command to be executed on the main thread, and
2126 * returns immediately.
2127 * @see #sendRequest
2128 */
2129 private void sendRequestAsync(int command) {
2130 mMainThreadHandler.sendEmptyMessage(command);
2131 }
2132
2133 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002134 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002135 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002136 */
2137 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002138 sendRequestAsync(command, argument, null, null);
2139 }
2140
2141 /**
2142 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2143 * @see {@link #sendRequest(int,Object)}
2144 */
2145 private void sendRequestAsync(
2146 int command, Object argument, Phone phone, WorkSource workSource) {
2147 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002148 Message msg = mMainThreadHandler.obtainMessage(command, request);
2149 msg.sendToTarget();
2150 }
2151
2152 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 * Initialize the singleton PhoneInterfaceManager instance.
2154 * This is only done once, at startup, from PhoneApp.onCreate().
2155 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002156 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 synchronized (PhoneInterfaceManager.class) {
2158 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002159 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 } else {
2161 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2162 }
2163 return sInstance;
2164 }
2165 }
2166
2167 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002168 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002171 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002172 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002174 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002176 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002177 mTelephonySharedPreferences =
2178 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002179 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002180 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002181 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002182 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002183
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 publish();
2185 }
2186
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002187 private Phone getDefaultPhone() {
2188 Phone thePhone = getPhone(getDefaultSubscription());
2189 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2190 }
2191
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 private void publish() {
2193 if (DBG) log("publish: " + this);
2194
Peter Wangc035ce42020-01-08 21:00:22 -08002195 TelephonyFrameworkInitializer
2196 .getTelephonyServiceManager()
2197 .getTelephonyServiceRegisterer()
2198 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200
Stuart Scott584921c2015-01-15 17:10:34 -08002201 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002202 if (request.phone != null) {
2203 return request.phone;
2204 } else {
2205 return getPhoneFromSubId(request.subId);
2206 }
2207 }
2208
2209 private Phone getPhoneFromSubId(int subId) {
2210 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2211 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002212 }
2213
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002214 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2215 Phone phone = getPhoneFromRequest(request);
2216 return phone == null ? null :
2217 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2218 }
2219
Wink Saville36469e72014-06-11 15:17:00 -07002220 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002221 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002222 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224
Kai Shif70f46f2021-03-03 13:59:46 -08002225 private void sendEraseModemConfig(@NonNull Phone phone) {
2226 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2227 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2228 }
2229
2230 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2231 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2232 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002233 }
2234
Peter Wang44b186e2020-01-13 23:33:09 -08002235 private boolean isImsAvailableOnDevice() {
2236 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2237 if (pm == null) {
2238 // For some reason package manger is not available.. This will fail internally anyway,
2239 // so do not throw error and allow.
2240 return true;
2241 }
2242 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2243 }
2244
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002246 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002247 }
2248
Wink Savilleb564aae2014-10-23 10:18:09 -07002249 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 if (DBG) log("dial: " + number);
2251 // No permission check needed here: This is just a wrapper around the
2252 // ACTION_DIAL intent, which is available to any app since it puts up
2253 // the UI before it does anything.
2254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 String url = createTelUrl(number);
2258 if (url == null) {
2259 return;
2260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 // PENDING: should we just silently fail if phone is offhook or ringing?
2263 PhoneConstants.State state = mCM.getState(subId);
2264 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2265 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2266 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2267 mApp.startActivity(intent);
2268 }
2269 } finally {
2270 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272 }
2273
2274 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002275 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002276 }
2277
Wink Savilleb564aae2014-10-23 10:18:09 -07002278 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 if (DBG) log("call: " + number);
2280
2281 // This is just a wrapper around the ACTION_CALL intent, but we still
2282 // need to do a permission check since we're calling startActivity()
2283 // from the context of the phone app.
2284 enforceCallPermission();
2285
Jordan Liu1617b712019-07-10 15:06:26 -07002286 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 != AppOpsManager.MODE_ALLOWED) {
2288 return;
2289 }
2290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002291 final long identity = Binder.clearCallingIdentity();
2292 try {
2293 String url = createTelUrl(number);
2294 if (url == null) {
2295 return;
2296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 boolean isValid = false;
2299 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2300 if (slist != null) {
2301 for (SubscriptionInfo subInfoRecord : slist) {
2302 if (subInfoRecord.getSubscriptionId() == subId) {
2303 isValid = true;
2304 break;
2305 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002306 }
Wink Saville08874612014-08-31 19:19:58 -07002307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002308 if (!isValid) {
2309 return;
2310 }
Wink Saville08874612014-08-31 19:19:58 -07002311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2313 intent.putExtra(SUBSCRIPTION_KEY, subId);
2314 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2315 mApp.startActivity(intent);
2316 } finally {
2317 Binder.restoreCallingIdentity(identity);
2318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 }
2320
Wink Savilleb564aae2014-10-23 10:18:09 -07002321 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002322 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002323 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2324 }
2325
Wink Savilleb564aae2014-10-23 10:18:09 -07002326 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002327 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002328 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2329 }
2330
Wink Savilleb564aae2014-10-23 10:18:09 -07002331 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002333
2334 final long identity = Binder.clearCallingIdentity();
2335 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002336 Phone phone = getPhone(subId);
2337 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338 checkSimPin.start();
2339 return checkSimPin.unlockSim(null, pin);
2340 } finally {
2341 Binder.restoreCallingIdentity(identity);
2342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 }
2344
Wink Savilleb564aae2014-10-23 10:18:09 -07002345 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002350 Phone phone = getPhone(subId);
2351 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352 checkSimPuk.start();
2353 return checkSimPuk.unlockSim(puk, pin);
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
2356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 }
2358
2359 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002360 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 * a synchronous one.
2362 */
2363 private static class UnlockSim extends Thread {
2364
2365 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002366 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367
2368 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002369 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2370 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371
2372 // For replies from SimCard interface
2373 private Handler mHandler;
2374
2375 // For async handler to identify request type
2376 private static final int SUPPLY_PIN_COMPLETE = 100;
2377
Michele Berionne5e411512020-11-13 02:36:59 +00002378 UnlockSim(int phoneId, IccCard simCard) {
2379 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 mSimCard = simCard;
2381 }
2382
2383 @Override
2384 public void run() {
2385 Looper.prepare();
2386 synchronized (UnlockSim.this) {
2387 mHandler = new Handler() {
2388 @Override
2389 public void handleMessage(Message msg) {
2390 AsyncResult ar = (AsyncResult) msg.obj;
2391 switch (msg.what) {
2392 case SUPPLY_PIN_COMPLETE:
2393 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2394 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002395 mRetryCount = msg.arg1;
2396 if (ar.exception != null) {
2397 if (ar.exception instanceof CommandException &&
2398 ((CommandException)(ar.exception)).getCommandError()
2399 == CommandException.Error.PASSWORD_INCORRECT) {
2400 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002401 } //When UiccCardApp dispose,handle message and return exception
2402 else if (ar.exception instanceof CommandException &&
2403 ((CommandException) (ar.exception)).getCommandError()
2404 == CommandException.Error.ABORTED) {
2405 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002406 } else {
2407 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2408 }
2409 } else {
2410 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 mDone = true;
2413 UnlockSim.this.notifyAll();
2414 }
2415 break;
2416 }
2417 }
2418 };
2419 UnlockSim.this.notifyAll();
2420 }
2421 Looper.loop();
2422 }
2423
2424 /*
2425 * Use PIN or PUK to unlock SIM card
2426 *
2427 * If PUK is null, unlock SIM card with PIN
2428 *
2429 * If PUK is not null, unlock SIM card with PUK and set PIN code
2430 */
Wink Saville9de0f752013-10-22 19:04:03 -07002431 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432
2433 while (mHandler == null) {
2434 try {
2435 wait();
2436 } catch (InterruptedException e) {
2437 Thread.currentThread().interrupt();
2438 }
2439 }
2440 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2441
2442 if (puk == null) {
2443 mSimCard.supplyPin(pin, callback);
2444 } else {
2445 mSimCard.supplyPuk(puk, pin, callback);
2446 }
2447
2448 while (!mDone) {
2449 try {
2450 Log.d(LOG_TAG, "wait for done");
2451 wait();
2452 } catch (InterruptedException e) {
2453 // Restore the interrupted status
2454 Thread.currentThread().interrupt();
2455 }
2456 }
2457 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002458 int[] resultArray = new int[2];
2459 resultArray[0] = mResult;
2460 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002461
2462 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Grace Jia59437e82021-09-21 15:47:32 -07002463 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
2464 pinStorage.storePin(pin, mPhoneId, pinStorage.getIccid(mPhoneId));
Michele Berionne5e411512020-11-13 02:36:59 +00002465 }
2466
Wink Saville9de0f752013-10-22 19:04:03 -07002467 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469 }
2470
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002471 /**
2472 * This method has been removed due to privacy and stability concerns.
2473 */
2474 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002476 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2477 return;
Wink Saville36469e72014-06-11 15:17:00 -07002478 }
2479
Nathan Harold1f889d82020-06-04 17:05:26 -07002480 @Override
2481 public void updateServiceLocationWithPackageName(String callingPackage) {
2482 mApp.getSystemService(AppOpsManager.class)
2483 .checkPackage(Binder.getCallingUid(), callingPackage);
2484
Nathan Haroldf096d982020-11-18 17:18:06 -08002485 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002486 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2487 // Callers targeting S have no business invoking this method.
2488 return;
2489 }
2490
2491 LocationAccessPolicy.LocationPermissionResult locationResult =
2492 LocationAccessPolicy.checkLocationPermission(mApp,
2493 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2494 .setCallingPackage(callingPackage)
2495 .setCallingFeatureId(null)
2496 .setCallingPid(Binder.getCallingPid())
2497 .setCallingUid(Binder.getCallingUid())
2498 .setMethod("updateServiceLocation")
2499 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2500 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2501 .build());
2502 // Apps that lack location permission have no business calling this method;
2503 // however, because no permission was declared in the public API, denials must
2504 // all be "soft".
2505 switch (locationResult) {
2506 case DENIED_HARD: /* fall through */
2507 case DENIED_SOFT:
2508 return;
2509 }
2510
2511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 final long identity = Binder.clearCallingIdentity();
2513 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002514 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002515 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002516 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517 }
2518 } finally {
2519 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 }
2522
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002523 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002524 @Override
2525 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002526 return isRadioOnWithFeature(callingPackage, null);
2527 }
2528
2529
2530 @Override
2531 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2532 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2533 callingFeatureId);
2534 }
2535
2536 @Deprecated
2537 @Override
2538 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2539 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002540 }
2541
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002542 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002543 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2544 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002546 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002547 return false;
2548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549
2550 final long identity = Binder.clearCallingIdentity();
2551 try {
2552 return isRadioOnForSubscriber(subId);
2553 } finally {
2554 Binder.restoreCallingIdentity(identity);
2555 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002556 }
2557
2558 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 final long identity = Binder.clearCallingIdentity();
2560 try {
2561 final Phone phone = getPhone(subId);
2562 if (phone != null) {
2563 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2564 } else {
2565 return false;
2566 }
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 }
2571
2572 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002573 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
Wink Saville36469e72014-06-11 15:17:00 -07002575
Wink Savilleb564aae2014-10-23 10:18:09 -07002576 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 final Phone phone = getPhone(subId);
2582 if (phone != null) {
2583 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002587 }
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
2590 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002591 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002592 }
2593
Wink Savilleb564aae2014-10-23 10:18:09 -07002594 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002595 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 final Phone phone = getPhone(subId);
2600 if (phone == null) {
2601 return false;
2602 }
2603 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2604 toggleRadioOnOffForSubscriber(subId);
2605 }
2606 return true;
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 }
Wink Saville36469e72014-06-11 15:17:00 -07002611
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002612 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002613 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002614 /*
2615 * If any of the Radios are available, it will need to be
2616 * shutdown. So return true if any Radio is available.
2617 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2621 Phone phone = PhoneFactory.getPhone(i);
2622 if (phone != null && phone.isRadioAvailable()) return true;
2623 }
2624 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2625 return false;
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002628 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002629 }
2630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002632 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 enforceModifyPermission();
2634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2638 logv("Shutting down Phone " + i);
2639 shutdownRadioUsingPhoneId(i);
2640 }
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002643 }
2644 }
2645
2646 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002647 Phone phone = PhoneFactory.getPhone(phoneId);
2648 if (phone != null && phone.isRadioAvailable()) {
2649 phone.shutdownRadio();
2650 }
2651 }
2652
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2659 if (defaultPhone != null) {
2660 defaultPhone.setRadioPower(turnOn);
2661 return true;
2662 } else {
2663 loge("There's no default phone.");
2664 return false;
2665 }
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002668 }
Wink Saville36469e72014-06-11 15:17:00 -07002669 }
2670
Wink Savilleb564aae2014-10-23 10:18:09 -07002671 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002673
2674 final long identity = Binder.clearCallingIdentity();
2675 try {
2676 final Phone phone = getPhone(subId);
2677 if (phone != null) {
2678 phone.setRadioPower(turnOn);
2679 return true;
2680 } else {
2681 return false;
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 }
2687
Wink Saville36469e72014-06-11 15:17:00 -07002688 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 public boolean enableDataConnectivity() {
2691 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692
2693 final long identity = Binder.clearCallingIdentity();
2694 try {
2695 int subId = mSubscriptionController.getDefaultDataSubId();
2696 final Phone phone = getPhone(subId);
2697 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002698 phone.getDataEnabledSettings().setDataEnabled(
2699 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700 return true;
2701 } else {
2702 return false;
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 }
2708
Wink Saville36469e72014-06-11 15:17:00 -07002709 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002710 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002711 public boolean disableDataConnectivity() {
2712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713
2714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 int subId = mSubscriptionController.getDefaultDataSubId();
2717 final Phone phone = getPhone(subId);
2718 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002719 phone.getDataEnabledSettings().setDataEnabled(
2720 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721 return true;
2722 } else {
2723 return false;
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728 }
2729
Sanket Padawe356d7632015-06-22 14:03:32 -07002730 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002731 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 final long identity = Binder.clearCallingIdentity();
2733 try {
2734 final Phone phone = getPhone(subId);
2735 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002736 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 } else {
2738 return false;
2739 }
2740 } finally {
2741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 }
2744
2745 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002746 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002747 }
2748
pkanwarae03a6b2016-11-06 20:37:09 -08002749 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750 enforceCallPermission();
2751
2752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2755 return;
2756 }
2757 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2758 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2759 } finally {
2760 Binder.restoreCallingIdentity(identity);
2761 }
pkanwar32d516d2016-10-14 19:37:38 -07002762 };
2763
Wink Savilleb564aae2014-10-23 10:18:09 -07002764 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2770 return false;
2771 }
2772 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 }
2777
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002778 /**
2779 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2780 * tag on getCallState Binder call.
2781 */
2782 @Deprecated
2783 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002785 if (CompatChanges.isChangeEnabled(
2786 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2787 Binder.getCallingUid())) {
2788 // Do not allow this API to be called on API version 31+, it should only be
2789 // called on old apps using this Binder call directly.
2790 throw new SecurityException("This method can only be used for applications "
2791 + "targeting API version 30 or less.");
2792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 final long identity = Binder.clearCallingIdentity();
2794 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002795 Phone phone = getPhone(getDefaultSubscription());
2796 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2797 PhoneConstantConversions.convertCallState(phone.getState());
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
2800 }
2801 }
2802
2803 @Override
2804 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2805 if (CompatChanges.isChangeEnabled(
2806 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2807 Binder.getCallingUid())) {
2808 // Check READ_PHONE_STATE for API version 31+
2809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2810 featureId, "getCallStateForSubscription")) {
2811 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2812 + "targeting API level 31+.");
2813 }
2814 }
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2819 PhoneConstantConversions.convertCallState(phone.getState());
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
2822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 }
2824
Sanket Padawe356d7632015-06-22 14:03:32 -07002825 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002826 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002827 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2828 }
2829
2830 @Override
2831 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832 final long identity = Binder.clearCallingIdentity();
2833 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002834 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 if (phone != null) {
2836 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2837 } else {
2838 return PhoneConstantConversions.convertDataState(
2839 PhoneConstants.DataState.DISCONNECTED);
2840 }
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
2845
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002847 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002848 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2849 }
2850
2851 @Override
2852 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 final long identity = Binder.clearCallingIdentity();
2854 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002855 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 if (phone != null) {
2857 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2858 } else {
2859 return TelephonyManager.DATA_ACTIVITY_NONE;
2860 }
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 }
2865
2866 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002867 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002868 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002869 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002870
2871 LocationAccessPolicy.LocationPermissionResult locationResult =
2872 LocationAccessPolicy.checkLocationPermission(mApp,
2873 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2874 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002875 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002876 .setCallingPid(Binder.getCallingPid())
2877 .setCallingUid(Binder.getCallingUid())
2878 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002879 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002880 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2881 .build());
2882 switch (locationResult) {
2883 case DENIED_HARD:
2884 throw new SecurityException("Not allowed to access cell location");
2885 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002886 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2887 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 }
2889
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002890 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002894 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002895 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896 } finally {
2897 Binder.restoreCallingIdentity(identity);
2898 }
Svetoslav64fad262015-04-14 14:35:21 -07002899 }
2900
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002902 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002903 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2904 // registered cell info, so return a NULL country instead.
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002907 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2908 // Get default phone in this case.
2909 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2910 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002911 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002913 if (phone == null) return "";
2914 ServiceStateTracker sst = phone.getServiceStateTracker();
2915 if (sst == null) return "";
2916 LocaleTracker lt = sst.getLocaleTracker();
2917 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002918 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002919 } finally {
2920 Binder.restoreCallingIdentity(identity);
2921 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002922 }
2923
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002924 /**
2925 * This method was removed due to potential issues caused by performing partial
2926 * updates of service state, and lack of a credible use case.
2927 *
2928 * This has the ability to break the telephony implementation by disabling notification of
2929 * changes in device connectivity. DO NOT USE THIS!
2930 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002931 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 public void enableLocationUpdates() {
2933 mApp.enforceCallingOrSelfPermission(
2934 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002935 }
2936
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002937 /**
2938 * This method was removed due to potential issues caused by performing partial
2939 * updates of service state, and lack of a credible use case.
2940 *
2941 * This has the ability to break the telephony implementation by disabling notification of
2942 * changes in device connectivity. DO NOT USE THIS!
2943 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002944 @Override
2945 public void disableLocationUpdates() {
2946 mApp.enforceCallingOrSelfPermission(
2947 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 }
2949
2950 @Override
2951 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002952 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2953 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002954 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002955 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2956 throw new SecurityException(
2957 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2958 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002959
Jordan Liu1617b712019-07-10 15:06:26 -07002960 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2962 return null;
2963 }
Svetoslav64fad262015-04-14 14:35:21 -07002964
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002965 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002966
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002967 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002968 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002969
Nathan Haroldf180aac2018-06-01 18:43:55 -07002970 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2971 for (CellInfo ci : info) {
2972 if (ci instanceof CellInfoGsm) {
2973 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2974 } else if (ci instanceof CellInfoWcdma) {
2975 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002978 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002979 }
2980
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002981 private List<CellInfo> getCachedCellInfo() {
2982 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2983 for (Phone phone : PhoneFactory.getPhones()) {
2984 List<CellInfo> info = phone.getAllCellInfo();
2985 if (info != null) cellInfos.addAll(info);
2986 }
2987 return cellInfos;
2988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002989
2990 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002991 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002992 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002993 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002994
2995 LocationAccessPolicy.LocationPermissionResult locationResult =
2996 LocationAccessPolicy.checkLocationPermission(mApp,
2997 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2998 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002999 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003000 .setCallingPid(Binder.getCallingPid())
3001 .setCallingUid(Binder.getCallingUid())
3002 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003003 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003004 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3005 .build());
3006 switch (locationResult) {
3007 case DENIED_HARD:
3008 throw new SecurityException("Not allowed to access cell info");
3009 case DENIED_SOFT:
3010 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 }
3012
Nathan Haroldf096d982020-11-18 17:18:06 -08003013 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003014 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3015 return getCachedCellInfo();
3016 }
3017
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003018 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3023 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003024 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003025 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 if (info != null) cellInfos.addAll(info);
3027 }
3028 return cellInfos;
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 }
3032 }
3033
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003034 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003035 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3036 String callingFeatureId) {
3037 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3038 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003039 }
3040
3041 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003042 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3043 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003044 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003045 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003046 }
3047
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003048 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3049 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003050 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003051 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003052
3053 LocationAccessPolicy.LocationPermissionResult locationResult =
3054 LocationAccessPolicy.checkLocationPermission(mApp,
3055 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3056 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003057 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003058 .setCallingPid(Binder.getCallingPid())
3059 .setCallingUid(Binder.getCallingUid())
3060 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003061 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3062 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003063 .build());
3064 switch (locationResult) {
3065 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003066 if (TelephonyPermissions
3067 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003068 // Safetynet logging for b/154934934
3069 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3070 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003071 throw new SecurityException("Not allowed to access cell info");
3072 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003073 if (TelephonyPermissions
3074 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003075 // Safetynet logging for b/154934934
3076 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3077 }
Nathan Harold5320c422019-05-09 10:26:08 -07003078 try {
3079 cb.onCellInfo(new ArrayList<CellInfo>());
3080 } catch (RemoteException re) {
3081 // Drop without consequences
3082 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003083 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003084 }
3085
Nathan Harolda939a962019-05-09 10:13:47 -07003086
3087 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003088 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3089
3090 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3091 }
3092
3093 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003095 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003096 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097
3098 final long identity = Binder.clearCallingIdentity();
3099 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003100 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 }
3105
Shishir Agrawala9f32182016-04-12 12:00:16 -07003106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003107 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003108 Phone phone = PhoneFactory.getPhone(slotIndex);
3109 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003110 return null;
3111 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003112 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003113 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003114 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003115 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003116 return null;
3117 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118
3119 final long identity = Binder.clearCallingIdentity();
3120 try {
3121 return phone.getImei();
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003125 }
3126
3127 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003128 public String getTypeAllocationCodeForSlot(int slotIndex) {
3129 Phone phone = PhoneFactory.getPhone(slotIndex);
3130 String tac = null;
3131 if (phone != null) {
3132 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003133 try {
3134 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3135 } catch (IndexOutOfBoundsException e) {
3136 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3137 return null;
3138 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003139 }
3140 return tac;
3141 }
3142
3143 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003144 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003145 Phone phone = PhoneFactory.getPhone(slotIndex);
3146 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003147 return null;
3148 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003149
Jeff Davidson913390f2018-02-23 17:11:49 -08003150 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003151 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003152 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003153 return null;
3154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003155
3156 final long identity = Binder.clearCallingIdentity();
3157 try {
3158 return phone.getMeid();
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
3161 }
Jack Yu2af8d712017-03-15 17:14:14 -07003162 }
3163
3164 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003165 public String getManufacturerCodeForSlot(int slotIndex) {
3166 Phone phone = PhoneFactory.getPhone(slotIndex);
3167 String manufacturerCode = null;
3168 if (phone != null) {
3169 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003170 try {
3171 manufacturerCode =
3172 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3173 } catch (IndexOutOfBoundsException e) {
3174 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3175 return null;
3176 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003177 }
3178 return manufacturerCode;
3179 }
3180
3181 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003182 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3183 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003184 Phone phone = PhoneFactory.getPhone(slotIndex);
3185 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003186 return null;
3187 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003188 int subId = phone.getSubId();
3189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003190 mApp, subId, callingPackage, callingFeatureId,
3191 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003192 return null;
3193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 return phone.getDeviceSvn();
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003201 }
3202
fionaxu43304da2017-11-27 22:51:16 -08003203 @Override
3204 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 final long identity = Binder.clearCallingIdentity();
3206 try {
3207 final Phone phone = getPhone(subId);
3208 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
fionaxu43304da2017-11-27 22:51:16 -08003212 }
3213
3214 @Override
3215 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 final Phone phone = getPhone(subId);
3219 return phone == null ? null : phone.getCarrierName();
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
fionaxu43304da2017-11-27 22:51:16 -08003223 }
3224
calvinpanffe225e2018-11-01 19:43:06 +08003225 @Override
chen xu0026ca62019-03-06 15:28:50 -08003226 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 final Phone phone = getPhone(subId);
3230 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003231 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
3235 }
3236
3237 @Override
chen xu0026ca62019-03-06 15:28:50 -08003238 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003242 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
3246 }
3247
chen xu651eec72018-11-11 19:03:44 -08003248 @Override
chen xu864e11c2018-12-06 22:10:03 -08003249 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3250 if (!isSubscriptionMccMnc) {
3251 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3252 }
chen xu651eec72018-11-11 19:03:44 -08003253 final Phone phone = PhoneFactory.getPhone(slotIndex);
3254 if (phone == null) {
3255 return TelephonyManager.UNKNOWN_CARRIER_ID;
3256 }
3257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3260 } finally {
3261 Binder.restoreCallingIdentity(identity);
3262 }
3263 }
3264
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265 //
3266 // Internal helper methods.
3267 //
3268
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003269 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003270 * Make sure the caller is the calling package itself
3271 *
3272 * @throws SecurityException if the caller is not the calling package
3273 */
3274 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3275 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003276 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3277 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003278 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003279 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003280 } catch (PackageManager.NameNotFoundException e) {
3281 // packageUid is -1
3282 }
3283 if (packageUid != callingUid) {
3284 throw new SecurityException(message + ": Package " + callingPackage
3285 + " does not belong to " + callingUid);
3286 }
3287 }
3288
3289 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003290 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3291 *
3292 * @throws SecurityException if the caller does not have the required permission
3293 */
3294 private void enforceModifyPermission() {
3295 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3296 }
3297
Shuo Qiancd19c462020-01-16 20:51:11 -08003298 /**
3299 * Make sure the caller is system.
3300 *
3301 * @throws SecurityException if the caller is not system.
3302 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003303 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003304 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3305 throw new SecurityException("Caller must be system");
3306 }
3307 }
3308
Shuo Qian3b6ee772019-11-13 17:43:31 -08003309 private void enforceActiveEmergencySessionPermission() {
3310 mApp.enforceCallingOrSelfPermission(
3311 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3312 }
3313
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003314 /**
3315 * Make sure the caller has the CALL_PHONE permission.
3316 *
3317 * @throws SecurityException if the caller does not have the required permission
3318 */
3319 private void enforceCallPermission() {
3320 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3321 }
3322
paulhu5a773602019-08-23 19:17:33 +08003323 private void enforceSettingsPermission() {
3324 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003325 }
3326
Michele Berionne5e411512020-11-13 02:36:59 +00003327 private void enforceRebootPermission() {
3328 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3329 }
3330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003331 private String createTelUrl(String number) {
3332 if (TextUtils.isEmpty(number)) {
3333 return null;
3334 }
3335
Jake Hambye994d462014-02-03 13:10:13 -08003336 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003337 }
3338
Ihab Awadf9e92732013-12-05 18:02:52 -08003339 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003340 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3341 }
3342
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003343 private static void logv(String msg) {
3344 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3345 }
3346
Ihab Awadf9e92732013-12-05 18:02:52 -08003347 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3349 }
3350
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003351 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003353 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003354 }
3355
Sanket Padawe356d7632015-06-22 14:03:32 -07003356 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003357 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 final Phone phone = PhoneFactory.getPhone(slotIndex);
3361 if (phone == null) {
3362 return PhoneConstants.PHONE_TYPE_NONE;
3363 } else {
3364 return phone.getPhoneType();
3365 }
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003369 }
3370
3371 /**
3372 * Returns the CDMA ERI icon index to display
3373 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003374 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003375 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3376 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3377 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003378 }
3379
Sanket Padawe356d7632015-06-22 14:03:32 -07003380 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003381 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3382 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003384 mApp, subId, callingPackage, callingFeatureId,
3385 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003386 return -1;
3387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003388
3389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 final Phone phone = getPhone(subId);
3392 if (phone != null) {
3393 return phone.getCdmaEriIconIndex();
3394 } else {
3395 return -1;
3396 }
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003400 }
3401
3402 /**
3403 * Returns the CDMA ERI icon mode,
3404 * 0 - ON
3405 * 1 - FLASHING
3406 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003408 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3409 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3410 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003411 }
3412
Sanket Padawe356d7632015-06-22 14:03:32 -07003413 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003414 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3415 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003417 mApp, subId, callingPackage, callingFeatureId,
3418 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003419 return -1;
3420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 final Phone phone = getPhone(subId);
3425 if (phone != null) {
3426 return phone.getCdmaEriIconMode();
3427 } else {
3428 return -1;
3429 }
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003433 }
3434
3435 /**
3436 * Returns the CDMA ERI text,
3437 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003438 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003439 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3440 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3441 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003442 }
3443
Sanket Padawe356d7632015-06-22 14:03:32 -07003444 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003445 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3446 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003448 mApp, subId, callingPackage, callingFeatureId,
3449 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003450 return null;
3451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452
3453 final long identity = Binder.clearCallingIdentity();
3454 try {
3455 final Phone phone = getPhone(subId);
3456 if (phone != null) {
3457 return phone.getCdmaEriText();
3458 } else {
3459 return null;
3460 }
3461 } finally {
3462 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003464 }
3465
3466 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003467 * Returns the CDMA MDN.
3468 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003469 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003470 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3472 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003473
3474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003477 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478 return phone.getLine1Number();
3479 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003480 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003481 return null;
3482 }
3483 } finally {
3484 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003485 }
3486 }
3487
3488 /**
3489 * Returns the CDMA MIN.
3490 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003491 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003492 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3494 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003495
3496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 final Phone phone = getPhone(subId);
3499 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3500 return phone.getCdmaMin();
3501 } else {
3502 return null;
3503 }
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003506 }
3507 }
3508
Hall Liud892bec2018-11-30 14:51:45 -08003509 @Override
3510 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3511 INumberVerificationCallback callback, String callingPackage) {
3512 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3513 != PERMISSION_GRANTED) {
3514 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3515 }
3516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3517
3518 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3519 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003520 throw new SecurityException("Calling package must be configured in the device config: "
3521 + "calling package: " + callingPackage
3522 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003523 }
3524
3525 if (range == null) {
3526 throw new NullPointerException("Range must be non-null");
3527 }
3528
3529 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003530 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003531
3532 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3533 }
3534
Junda Liuca05d5d2014-08-14 22:36:34 -07003535 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 * Returns true if CDMA provisioning needs to run.
3537 */
3538 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539 final long identity = Binder.clearCallingIdentity();
3540 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003541 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003545 }
3546
3547 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003548 * Sets the voice mail number of a given subId.
3549 */
3550 @Override
3551 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003552 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3553 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554
3555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3558 new Pair<String, String>(alphaTag, number), new Integer(subId));
3559 return success;
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003563 }
3564
Ta-wei Yen87c49842016-05-13 21:19:52 -07003565 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003566 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3567 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003568 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3569 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003570 if (!TextUtils.equals(callingPackage, systemDialer)) {
3571 throw new SecurityException("caller must be system dialer");
3572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3577 if (phoneAccountHandle == null) {
3578 return null;
3579 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 } finally {
3582 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003583 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003584 }
3585
3586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003587 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3588 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003591 mApp, subId, callingPackage, callingFeatureId,
3592 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003593 return null;
3594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003596 final long identity = Binder.clearCallingIdentity();
3597 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003598 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003599 } finally {
3600 Binder.restoreCallingIdentity(identity);
3601 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003602 }
3603
3604 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003605 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3606 VisualVoicemailSmsFilterSettings settings) {
3607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003612 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003616 }
3617
3618 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003619 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3620 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621
3622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003625 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626 } finally {
3627 Binder.restoreCallingIdentity(identity);
3628 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003629 }
3630
3631 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003632 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3633 String callingPackage, int subId) {
3634 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635
3636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003643 }
3644
3645 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003646 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003647 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003656 }
3657
3658 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003659 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3660 String callingAttributionTag, int subId, String number, int port, String text,
3661 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003662 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003663 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003664 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003665 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003666 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3667 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003668 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003669
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003670 /**
fionaxu0152e512016-11-14 13:36:14 -08003671 * Sets the voice activation state of a given subId.
3672 */
3673 @Override
3674 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3676 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677
3678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 final Phone phone = getPhone(subId);
3681 if (phone != null) {
3682 phone.setVoiceActivationState(activationState);
3683 } else {
3684 loge("setVoiceActivationState fails with invalid subId: " + subId);
3685 }
3686 } finally {
3687 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003688 }
3689 }
3690
3691 /**
3692 * Sets the data activation state of a given subId.
3693 */
3694 @Override
3695 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3697 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698
3699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 final Phone phone = getPhone(subId);
3702 if (phone != null) {
3703 phone.setDataActivationState(activationState);
3704 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003705 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706 }
3707 } finally {
3708 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003709 }
3710 }
3711
3712 /**
3713 * Returns the voice activation state of a given subId.
3714 */
3715 @Override
3716 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718
fionaxu0152e512016-11-14 13:36:14 -08003719 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 if (phone != null) {
3723 return phone.getVoiceActivationState();
3724 } else {
3725 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3726 }
3727 } finally {
3728 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003729 }
3730 }
3731
3732 /**
3733 * Returns the data activation state of a given subId.
3734 */
3735 @Override
3736 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738
fionaxu0152e512016-11-14 13:36:14 -08003739 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 if (phone != null) {
3743 return phone.getDataActivationState();
3744 } else {
3745 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3746 }
3747 } finally {
3748 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003749 }
3750 }
3751
3752 /**
Wink Saville36469e72014-06-11 15:17:00 -07003753 * Returns the unread count of voicemails for a subId
3754 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003756 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3757 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003758 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003759 mApp, subId, callingPackage, callingFeatureId,
3760 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003761 return 0;
3762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 final Phone phone = getPhone(subId);
3766 if (phone != null) {
3767 return phone.getVoiceMessageCount();
3768 } else {
3769 return 0;
3770 }
3771 } finally {
3772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003774 }
3775
3776 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003777 * returns true, if the device is in a state where both voice and data
3778 * are supported simultaneously. This can change based on location or network condition.
3779 */
3780 @Override
3781 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 final Phone phone = getPhone(subId);
3785 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003789 }
3790
3791 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003792 * Send the dialer code if called from the current default dialer or the caller has
3793 * carrier privilege.
3794 * @param inputCode The dialer code to send
3795 */
3796 @Override
3797 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003798 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003799 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003800 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3801 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003802 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003803 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003804 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806
3807 final long identity = Binder.clearCallingIdentity();
3808 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003809 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
fionaxu235cc5e2017-03-06 22:25:57 -08003813 }
3814
Pengquan Menga1bb6272018-09-06 09:59:22 -07003815 @Override
3816 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003817 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003818 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003819 mApp, subId, "getNetworkSelectionMode");
3820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 if (!isActiveSubscription(subId)) {
3823 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3824 }
3825 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003828 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003829 }
3830
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003832 public boolean isInEmergencySmsMode() {
3833 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 for (Phone phone : PhoneFactory.getPhones()) {
3837 if (phone.isInEmergencySmsMode()) {
3838 return true;
3839 }
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
3843 }
3844 return false;
3845 }
3846
shilu366312e2019-12-17 09:28:10 -08003847 /**
3848 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3849 * @param subId The subscription to use to check the configuration.
3850 * @param c The callback that will be used to send the result.
3851 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003853 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3854 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003855 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003856 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003857
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003858 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3859 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3860 "IMS not available on device.");
3861 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003862 final long token = Binder.clearCallingIdentity();
3863 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003864 int slotId = getSlotIndexOrException(subId);
3865 verifyImsMmTelConfiguredOrThrow(slotId);
3866 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003867 } catch (ImsException e) {
3868 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003869 } finally {
3870 Binder.restoreCallingIdentity(token);
3871 }
3872 }
3873
shilu366312e2019-12-17 09:28:10 -08003874 /**
3875 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3876 * @param subId The subscription to use to check the configuration.
3877 * @param c The callback that will be used to send the result.
3878 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003880 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003881 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003882 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003883 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3884 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3885 }
Meng Wangafbc5852019-09-19 17:37:13 -07003886 final long token = Binder.clearCallingIdentity();
3887 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003888 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3889 .removeRegistrationCallbackForSubscription(c, subId);
3890 } catch (ImsException e) {
3891 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3892 + "is inactive, ignoring unregister.");
3893 // If the subscription is no longer active, just return, since the callback
3894 // will already have been removed internally.
3895 } finally {
3896 Binder.restoreCallingIdentity(token);
3897 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 }
3899
Brad Ebingera34a6c22019-10-22 17:36:18 -07003900 /**
3901 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3902 */
3903 @Override
3904 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3905 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3906 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3907 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3908 "IMS not available on device.");
3909 }
3910 final long token = Binder.clearCallingIdentity();
3911 try {
3912 Phone phone = getPhone(subId);
3913 if (phone == null) {
3914 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3915 + subId + "'");
3916 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3917 }
3918 phone.getImsRegistrationState(regState -> {
3919 try {
3920 consumer.accept((regState == null)
3921 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3922 } catch (RemoteException e) {
3923 // Ignore if the remote process is no longer available to call back.
3924 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3925 }
3926 });
3927 } finally {
3928 Binder.restoreCallingIdentity(token);
3929 }
3930 }
3931
3932 /**
3933 * Get the transport type for the IMS service registration state.
3934 */
3935 @Override
3936 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003937 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003938 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003939 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3940 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3941 "IMS not available on device.");
3942 }
3943 final long token = Binder.clearCallingIdentity();
3944 try {
3945 Phone phone = getPhone(subId);
3946 if (phone == null) {
3947 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3948 + subId + "'");
3949 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3950 }
3951 phone.getImsRegistrationTech(regTech -> {
3952 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3953 int regTechConverted = (regTech == null)
3954 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3955 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3956 regTechConverted);
3957 try {
3958 consumer.accept(regTechConverted);
3959 } catch (RemoteException e) {
3960 // Ignore if the remote process is no longer available to call back.
3961 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3962 }
3963 });
3964 } finally {
3965 Binder.restoreCallingIdentity(token);
3966 }
3967 }
3968
shilu366312e2019-12-17 09:28:10 -08003969 /**
3970 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3971 * @param subId The subscription to use to check the configuration.
3972 * @param c The callback that will be used to send the result.
3973 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003975 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3976 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003977 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003978 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003979 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3980 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3981 "IMS not available on device.");
3982 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 final long token = Binder.clearCallingIdentity();
3984 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003985 int slotId = getSlotIndexOrException(subId);
3986 verifyImsMmTelConfiguredOrThrow(slotId);
3987 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003988 } catch (ImsException e) {
3989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 } finally {
3991 Binder.restoreCallingIdentity(token);
3992 }
3993 }
3994
shilu366312e2019-12-17 09:28:10 -08003995 /**
3996 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3997 * @param subId The subscription to use to check the configuration.
3998 * @param c The callback that will be used to send the result.
3999 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004001 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004002 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004003 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004004 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4005 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4006 }
Meng Wangafbc5852019-09-19 17:37:13 -07004007
4008 final long token = Binder.clearCallingIdentity();
4009 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004010 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004011 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004012 } catch (ImsException e) {
4013 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4014 + "is inactive, ignoring unregister.");
4015 // If the subscription is no longer active, just return, since the callback
4016 // will already have been removed internally.
4017 } finally {
4018 Binder.restoreCallingIdentity(token);
4019 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 }
4021
4022 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004023 public boolean isCapable(int subId, int capability, int regTech) {
4024 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 final long token = Binder.clearCallingIdentity();
4026 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004027 int slotId = getSlotIndexOrException(subId);
4028 verifyImsMmTelConfiguredOrThrow(slotId);
4029 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004030 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4032 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004033 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004034 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4035 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 } finally {
4037 Binder.restoreCallingIdentity(token);
4038 }
4039 }
4040
4041 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004042 public boolean isAvailable(int subId, int capability, int regTech) {
4043 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 final long token = Binder.clearCallingIdentity();
4045 try {
4046 Phone phone = getPhone(subId);
4047 if (phone == null) return false;
4048 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004049 } catch (com.android.ims.ImsException e) {
4050 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4051 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 } finally {
4053 Binder.restoreCallingIdentity(token);
4054 }
4055 }
4056
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004057 /**
4058 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4059 * subscription.
4060 * @param subId The subscription to use to check the configuration.
4061 * @param callback The callback that will be used to send the result.
4062 * @param capability The MmTelFeature capability that will be used to send the result.
4063 * @param transportType The transport type of the MmTelFeature capability.
4064 */
4065 @Override
4066 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4067 int transportType) {
4068 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4069 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4070 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4071 "IMS not available on device.");
4072 }
4073 final long token = Binder.clearCallingIdentity();
4074 try {
4075 int slotId = getSlotIndex(subId);
4076 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4077 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4078 + subId + "'");
4079 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4080 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004081 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004082 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4083 transportType, aBoolean -> {
4084 try {
4085 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4086 } catch (RemoteException e) {
4087 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4088 + "running. Ignore");
4089 }
4090 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004091 } catch (ImsException e) {
4092 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004093 } finally {
4094 Binder.restoreCallingIdentity(token);
4095 }
4096 }
4097
shilu366312e2019-12-17 09:28:10 -08004098 /**
4099 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4100 * @param subId The subscription to use to check the configuration.
4101 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004102 @Override
4103 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004104 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004105 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004106
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 final long token = Binder.clearCallingIdentity();
4108 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004109 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004110 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004111 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
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(token);
4116 }
4117 }
4118
4119 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004120 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004122 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 final long identity = Binder.clearCallingIdentity();
4124 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004125 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004126 // This setting doesn't require an active ImsService connection, so do not verify. The
4127 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004128 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004129 } catch (ImsException e) {
4130 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
4134 }
4135
shilu366312e2019-12-17 09:28:10 -08004136 /**
4137 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4138 * @param subId The subscription to use to check the configuration.
4139 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004141 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004142 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004143 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 final long identity = Binder.clearCallingIdentity();
4145 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004146 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004147 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004148 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004149 } catch (ImsException e) {
4150 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 } finally {
4152 Binder.restoreCallingIdentity(identity);
4153 }
4154 }
4155
4156 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004157 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004159 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 final long identity = Binder.clearCallingIdentity();
4161 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004162 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004163 // This setting doesn't require an active ImsService connection, so do not verify. The
4164 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004165 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
shilu366312e2019-12-17 09:28:10 -08004173 /**
4174 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4175 * @param subId The subscription to use to check the configuration.
4176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 @Override
4178 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004179 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004180 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 final long identity = Binder.clearCallingIdentity();
4182 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004183 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004184 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004185 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004186 } catch (ImsException e) {
4187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
4193 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004194 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004196 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 final long identity = Binder.clearCallingIdentity();
4198 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004199 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004200 // This setting doesn't require an active ImsService connection, so do not verify. The
4201 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004202 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (ImsException e) {
4204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
4208 }
4209
shilu366312e2019-12-17 09:28:10 -08004210 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004211 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4212 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4213 * @param subId The subscription to use to check the configuration.
4214 */
4215 @Override
4216 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004217 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004218 mApp, subId, "isCrossSimCallingEnabledByUser");
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004221 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004222 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004223 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004224 } catch (ImsException e) {
4225 throw new ServiceSpecificException(e.getCode());
4226 } finally {
4227 Binder.restoreCallingIdentity(identity);
4228 }
4229 }
4230
4231 /**
4232 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4233 * Requires MODIFY_PHONE_STATE permission.
4234 * @param subId The subscription to use to check the configuration.
4235 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4236 * false otherwise
4237 */
4238 @Override
4239 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4241 "setCrossSimCallingEnabled");
4242 final long identity = Binder.clearCallingIdentity();
4243 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004244 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004245 // This setting doesn't require an active ImsService connection, so do not verify. The
4246 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004247 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004248 } catch (ImsException e) {
4249 throw new ServiceSpecificException(e.getCode());
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
4253 }
4254
4255 /**
shilu366312e2019-12-17 09:28:10 -08004256 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4257 * @param subId The subscription to use to check the configuration.
4258 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004260
Brad Ebinger35c841c2018-10-01 10:40:55 -07004261 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004262 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004263 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 final long identity = Binder.clearCallingIdentity();
4265 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004266 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004267 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004268 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004269 } catch (ImsException e) {
4270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
4274 }
4275
4276 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004277 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004279 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 final long identity = Binder.clearCallingIdentity();
4281 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004282 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004283 // This setting doesn't require an active ImsService connection, so do not verify. The
4284 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004285 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004286 } catch (ImsException e) {
4287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 } finally {
4289 Binder.restoreCallingIdentity(identity);
4290 }
4291 }
4292
4293 @Override
4294 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4296 "setVoWiFiNonPersistent");
4297 final long identity = Binder.clearCallingIdentity();
4298 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004300 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004301 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004302 } catch (ImsException e) {
4303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
4307 }
4308
shilu366312e2019-12-17 09:28:10 -08004309 /**
4310 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4311 * @param subId The subscription to use to check the configuration.
4312 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 @Override
4314 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004315 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004316 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004317 final long identity = Binder.clearCallingIdentity();
4318 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004319 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004320 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004321 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004322 } catch (ImsException e) {
4323 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
4327 }
4328
4329 @Override
4330 public void setVoWiFiModeSetting(int subId, int mode) {
4331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4332 "setVoWiFiModeSetting");
4333 final long identity = Binder.clearCallingIdentity();
4334 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004336 // This setting doesn't require an active ImsService connection, so do not verify. The
4337 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004339 } catch (ImsException e) {
4340 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
4344 }
4345
4346 @Override
4347 public int getVoWiFiRoamingModeSetting(int subId) {
4348 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4349 final long identity = Binder.clearCallingIdentity();
4350 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004351 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004352 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004354 } catch (ImsException e) {
4355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
4359 }
4360
4361 @Override
4362 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4364 "setVoWiFiRoamingModeSetting");
4365 final long identity = Binder.clearCallingIdentity();
4366 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004367 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004368 // This setting doesn't require an active ImsService connection, so do not verify. The
4369 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004370 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004371 } catch (ImsException e) {
4372 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
4376 }
4377
4378 @Override
4379 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4381 "setRttCapabilityEnabled");
4382 final long identity = Binder.clearCallingIdentity();
4383 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004384 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004385 // This setting doesn't require an active ImsService connection, so do not verify. The
4386 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004387 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004388 } catch (ImsException e) {
4389 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004390 } finally {
4391 Binder.restoreCallingIdentity(identity);
4392 }
4393 }
4394
shilu366312e2019-12-17 09:28:10 -08004395 /**
4396 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4397 * @param subId The subscription to use to check the configuration.
4398 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004399 @Override
4400 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004401 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004402 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004403 final long identity = Binder.clearCallingIdentity();
4404 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004405 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004406 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004407 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004408 } catch (ImsException e) {
4409 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
4413 }
4414
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004415 @Override
4416 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4417 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4418 final long identity = Binder.clearCallingIdentity();
4419 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004420 if (!isImsAvailableOnDevice()) {
4421 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4422 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004423 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004424 int slotId = getSlotIndexOrException(subId);
4425 verifyImsMmTelConfiguredOrThrow(slotId);
4426 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004427 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004428 } catch (ImsException e) {
4429 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
4433 }
4434
4435 @Override
4436 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4437 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4438 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004439 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4440 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4441 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004442 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004443 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004444 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004445 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004446 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4447 + "is inactive, ignoring unregister.");
4448 // If the subscription is no longer active, just return, since the callback will already
4449 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
4453 }
4454
allenwtsu99c623b2020-01-03 18:24:23 +08004455
4456 private void checkModifyPhoneStatePermission(int subId, String message) {
4457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4458 message);
4459 }
4460
4461 private boolean isImsProvisioningRequired(int subId, int capability,
4462 boolean isMmtelCapability) {
4463 Phone phone = getPhone(subId);
4464 if (phone == null) {
4465 loge("phone instance null for subid " + subId);
4466 return false;
4467 }
4468 if (isMmtelCapability) {
4469 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4470 return false;
4471 }
4472 } else {
4473 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4474 return false;
4475 }
4476 }
4477 return true;
4478 }
4479
4480 @Override
4481 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4482 boolean isProvisioned) {
4483 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4484
4485 final long identity = Binder.clearCallingIdentity();
4486 try {
4487 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4488 if (!isImsProvisioningRequired(subId, capability, false)) {
4489 return;
4490 }
4491
4492 // this capability requires provisioning, route to the correct API.
4493 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4494 switch (capability) {
4495 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4496 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4497 ims.setEabProvisioned(isProvisioned);
4498 break;
4499 default: {
4500 throw new IllegalArgumentException("Tried to set provisioning for "
4501 + "rcs capability '" + capability + "', which does not require "
4502 + "provisioning.");
4503 }
4504 }
4505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
4508
4509 }
4510
4511
4512 @Override
4513 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4514 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4518 if (!isImsProvisioningRequired(subId, capability, false)) {
4519 return true;
4520 }
4521
4522 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4523 switch (capability) {
4524 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4525 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4526 return ims.isEabProvisionedOnDevice();
4527
4528 default: {
4529 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4530 + "capability '" + capability + "', which does not require "
4531 + "provisioning.");
4532 }
4533 }
4534
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
4538 }
4539
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004540 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004541 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4542 boolean isProvisioned) {
4543 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004544 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4545 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4546 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004547 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4548 }
allenwtsu99c623b2020-01-03 18:24:23 +08004549 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004550 final long identity = Binder.clearCallingIdentity();
4551 try {
4552 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004553 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004554 return;
4555 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004556 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4557 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4558 loge("setImsProvisioningStatusForCapability: called for technology that does "
4559 + "not support provisioning - " + tech);
4560 return;
4561 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004562
4563 // this capability requires provisioning, route to the correct API.
4564 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4565 switch (capability) {
4566 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4567 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4568 ims.setVolteProvisioned(isProvisioned);
4569 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4570 ims.setWfcProvisioned(isProvisioned);
4571 }
4572 break;
4573 }
4574 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4575 // There is currently no difference in VT provisioning type.
4576 ims.setVtProvisioned(isProvisioned);
4577 break;
4578 }
4579 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4580 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4581 // change the capability of the feature instead if needed.
4582 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4583 == isProvisioned) {
4584 // No change in provisioning.
4585 return;
4586 }
4587 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4588 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004589 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004590 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004591 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4592 + ", Exception" + e.getMessage());
4593 }
4594 break;
4595 }
4596 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004597 throw new IllegalArgumentException("Tried to set provisioning for "
4598 + "MmTel capability '" + capability + "', which does not require "
4599 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004600 }
4601 }
4602
4603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
4606 }
4607
4608 @Override
4609 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4610 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004611 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4612 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4613 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004614 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4615 }
4616 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4617 final long identity = Binder.clearCallingIdentity();
4618 try {
4619 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004620 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004621 return true;
4622 }
4623
Brad Ebinger0d79c572021-04-17 15:20:49 -07004624 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4625 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4626 loge("getImsProvisioningStatusForCapability: called for technology that does "
4627 + "not support provisioning - " + tech);
4628 return true;
4629 }
4630
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004631 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4632 switch (capability) {
4633 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4634 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4635 return ims.isVolteProvisionedOnDevice();
4636 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4637 return ims.isWfcProvisionedOnDevice();
4638 }
4639 // This should never happen, since we are checking tech above to make sure it
4640 // is either LTE or IWLAN.
4641 throw new IllegalArgumentException("Invalid radio technology for voice "
4642 + "capability.");
4643 }
4644 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4645 // There is currently no difference in VT provisioning type.
4646 return ims.isVtProvisionedOnDevice();
4647 }
4648 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4649 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4650 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4651 }
4652 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004653 throw new IllegalArgumentException(
4654 "Tried to get provisioning for MmTel capability '" + capability
4655 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004656 }
4657 }
4658
4659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
4662 }
4663
4664 @Override
4665 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4666 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4667 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4668 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4669 }
4670 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4671 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4672 return (provisionedBits & capability) > 0;
4673 }
4674
4675 @Override
4676 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4677 boolean isProvisioned) {
4678 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4679 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4680 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4681 }
4682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4683 "setProvisioningStatusForCapability");
4684 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4685 // If the current provisioning status for capability already matches isProvisioned,
4686 // do nothing.
4687 if (((provisionedBits & capability) > 0) == isProvisioned) {
4688 return;
4689 }
4690 if (isProvisioned) {
4691 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4692 } else {
4693 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4694 }
4695 }
4696
4697 /**
4698 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4699 * technology. The bitfield should mirror the bitfield defined by
4700 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4701 */
4702 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4703 String key = getMmTelProvisioningKey(subId, tech);
4704 // Default is no capabilities are provisioned.
4705 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4706 }
4707
4708 /**
4709 * Sets the MmTel capability provisioning bitfield (defined by
4710 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4711 * technology specified.
4712 *
4713 * Note: This is a synchronous command and should not be called on UI thread.
4714 */
4715 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4716 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4717 String key = getMmTelProvisioningKey(subId, tech);
4718 editor.putInt(key, newField);
4719 editor.commit();
4720 }
4721
4722 private static String getMmTelProvisioningKey(int subId, int tech) {
4723 // resulting key is provision_ims_mmtel_{subId}_{tech}
4724 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4725 }
4726
4727 /**
4728 * Query CarrierConfig to see if the specified capability requires provisioning for the
4729 * carrier associated with the subscription id.
4730 */
4731 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4732 int capability) {
4733 CarrierConfigManager configManager = new CarrierConfigManager(context);
4734 PersistableBundle c = configManager.getConfigForSubId(subId);
4735 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004736 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004737 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4738 false);
4739 boolean requireVoiceVtProvisioning = c.getBoolean(
4740 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4741
4742 // First check to make sure that the capability requires provisioning.
4743 switch (capability) {
4744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4745 // intentional fallthrough
4746 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4747 if (requireVoiceVtProvisioning) {
4748 // Voice and Video requires provisioning
4749 return true;
4750 }
4751 break;
4752 }
4753 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4754 if (requireUtProvisioning) {
4755 // UT requires provisioning
4756 return true;
4757 }
4758 break;
4759 }
4760 }
4761 return false;
4762 }
4763
allenwtsu99c623b2020-01-03 18:24:23 +08004764 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4765 int capability) {
4766 CarrierConfigManager configManager = new CarrierConfigManager(context);
4767 PersistableBundle c = configManager.getConfigForSubId(subId);
4768
4769 boolean requireRcsProvisioning = c.getBoolean(
4770 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4771
4772 // First check to make sure that the capability requires provisioning.
4773 switch (capability) {
4774 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4775 // intentional fallthrough
4776 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4777 if (requireRcsProvisioning) {
4778 // OPTION or PRESENCE requires provisioning
4779 return true;
4780 }
4781 break;
4782 }
4783 }
4784 return false;
4785 }
4786
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004787 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004788 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4790 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4791 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004792 enforceReadPrivilegedPermission("getImsProvisioningInt");
4793 final long identity = Binder.clearCallingIdentity();
4794 try {
4795 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004796 int slotId = getSlotIndex(subId);
4797 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4798 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4799 + subId + "' for key:" + key);
4800 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4801 }
calvinpanb5a34062021-02-08 19:59:36 +08004802 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004803 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004804 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4805 + subId + "' for key:" + key);
4806 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004807 } finally {
4808 Binder.restoreCallingIdentity(identity);
4809 }
4810 }
4811
4812 @Override
4813 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004814 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4815 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4816 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004817 enforceReadPrivilegedPermission("getImsProvisioningString");
4818 final long identity = Binder.clearCallingIdentity();
4819 try {
4820 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004821 int slotId = getSlotIndex(subId);
4822 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4823 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4824 + subId + "' for key:" + key);
4825 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4826 }
calvinpanb5a34062021-02-08 19:59:36 +08004827 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004828 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004829 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4830 + subId + "' for key:" + key);
4831 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004832 } finally {
4833 Binder.restoreCallingIdentity(identity);
4834 }
4835 }
4836
4837 @Override
4838 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004839 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4840 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4841 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4843 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004844 final long identity = Binder.clearCallingIdentity();
4845 try {
4846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004847 int slotId = getSlotIndex(subId);
4848 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4849 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4850 + subId + "' for key:" + key);
4851 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4852 }
calvinpanb5a34062021-02-08 19:59:36 +08004853 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4854 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004856 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004857 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004858 } finally {
4859 Binder.restoreCallingIdentity(identity);
4860 }
4861 }
4862
4863 @Override
4864 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004865 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4866 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4867 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4869 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004873 int slotId = getSlotIndex(subId);
4874 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4875 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4876 + subId + "' for key:" + key);
4877 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4878 }
calvinpanb5a34062021-02-08 19:59:36 +08004879 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4880 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004881 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004882 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004883 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004884 } finally {
4885 Binder.restoreCallingIdentity(identity);
4886 }
4887 }
4888
Brad Ebinger919631e2021-06-02 17:46:35 -07004889 /**
4890 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4891 * for the given slot ID or no ImsResolver instance has been created.
4892 * @param slotId The slot ID that the IMS service is created for.
4893 * @throws ImsException If there is no ImsService configured for this slot.
4894 */
4895 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4896 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4897 ImsFeature.FEATURE_MMTEL)) {
4898 throw new ImsException("This subscription does not support MMTEL over IMS",
4899 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4900 }
4901 }
4902
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004903 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004904 int slotId = SubscriptionManager.getSlotIndex(subId);
4905 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004906 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4907 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004908 }
4909 return slotId;
4910 }
4911
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912 private int getSlotIndex(int subId) {
4913 int slotId = SubscriptionManager.getSlotIndex(subId);
4914 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4915 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4916 }
4917 return slotId;
4918 }
4919
Wink Saville36469e72014-06-11 15:17:00 -07004920 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004921 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004922 */
4923 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004924 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4925 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004926 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004927 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004928 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004929 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004930 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004931 mApp, subId, callingPackage, callingFeatureId,
4932 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004933 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4934 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 final long identity = Binder.clearCallingIdentity();
4937 try {
4938 final Phone phone = getPhone(subId);
4939 if (phone != null) {
4940 return phone.getServiceState().getDataNetworkType();
4941 } else {
4942 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4943 }
4944 } finally {
4945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004947 }
4948
4949 /**
4950 * Returns the data network type
4951 */
4952 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004953 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004954 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4955 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004956 }
4957
4958 /**
4959 * Returns the data network type for a subId
4960 */
4961 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004962 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4963 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004965 mApp, subId, callingPackage, callingFeatureId,
4966 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004967 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4968 }
4969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 final Phone phone = getPhone(subId);
4973 if (phone != null) {
4974 return phone.getServiceState().getDataNetworkType();
4975 } else {
4976 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4977 }
4978 } finally {
4979 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004980 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004981 }
4982
4983 /**
Wink Saville36469e72014-06-11 15:17:00 -07004984 * Returns the Voice network type for a subId
4985 */
4986 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004987 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4988 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004990 mApp, subId, callingPackage, callingFeatureId,
4991 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004992 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4993 }
4994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 final long identity = Binder.clearCallingIdentity();
4996 try {
4997 final Phone phone = getPhone(subId);
4998 if (phone != null) {
4999 return phone.getServiceState().getVoiceNetworkType();
5000 } else {
5001 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5002 }
5003 } finally {
5004 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005006 }
5007
5008 /**
5009 * @return true if a ICC card is present
5010 */
5011 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005012 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005013 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5014 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005015 }
5016
5017 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005018 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005019 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005020 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005021 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 final long identity = Binder.clearCallingIdentity();
5023 try {
5024 final Phone phone = PhoneFactory.getPhone(slotIndex);
5025 if (phone != null) {
5026 return phone.getIccCard().hasIccCard();
5027 } else {
5028 return false;
5029 }
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005033 }
5034
5035 /**
5036 * Return if the current radio is LTE on CDMA. This
5037 * is a tri-state return value as for a period of time
5038 * the mode may be unknown.
5039 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005040 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005041 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005042 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005043 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005044 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005045 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5046 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5047 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005048 }
5049
Sanket Padawe356d7632015-06-22 14:03:32 -07005050 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005051 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5052 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005053 try {
5054 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5055 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005056 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5057 }
5058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 final Phone phone = getPhone(subId);
5062 if (phone == null) {
5063 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5064 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005065 return TelephonyProperties.lte_on_cdma_device()
5066 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 }
5068 } finally {
5069 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005070 }
Wink Saville36469e72014-06-11 15:17:00 -07005071 }
5072
Wink Saville36469e72014-06-11 15:17:00 -07005073 /**
5074 * {@hide}
5075 * Returns Default subId, 0 in the case of single standby.
5076 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005077 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005078 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005079 }
5080
Shishir Agrawala9f32182016-04-12 12:00:16 -07005081 private int getSlotForDefaultSubscription() {
5082 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5083 }
5084
Wink Savilleb564aae2014-10-23 10:18:09 -07005085 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005086 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005087 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005088
Pengquan Menge92a50d2018-09-21 15:54:48 -07005089 private boolean isActiveSubscription(int subId) {
5090 return mSubscriptionController.isActiveSubId(subId);
5091 }
5092
Ihab Awadf2177b72013-11-25 13:33:23 -08005093 /**
5094 * @see android.telephony.TelephonyManager.WifiCallingChoices
5095 */
5096 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 final long identity = Binder.clearCallingIdentity();
5098 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005099 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5101 getWhenToMakeWifiCallsDefaultPreference());
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005105 }
5106
5107 /**
5108 * @see android.telephony.TelephonyManager.WifiCallingChoices
5109 */
5110 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
5113 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005114 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005119 }
5120
Sailesh Nepald1e68152013-12-12 19:08:02 -08005121 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005122 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005123 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005124 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005125
Jordan Liu4c733742019-02-28 12:03:40 -08005126 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5127 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5128 if (phoneId == -1) {
5129 throw new IllegalArgumentException("Given slot index: " + slotIndex
5130 + " does not correspond to an active phone");
5131 }
5132 return PhoneFactory.getPhone(phoneId);
5133 }
5134
Shishir Agrawal566b7612013-10-28 14:41:00 -07005135 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005136 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5137 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5139 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005141 if (DBG) {
5142 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5143 }
5144 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5145 p2);
5146 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005147
Jordan Liu4c733742019-02-28 12:03:40 -08005148
5149 @Override
5150 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5151 int slotIndex, String callingPackage, String aid, int p2) {
5152 enforceModifyPermission();
5153 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5154 if (DBG) {
5155 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5156 }
5157 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5158 callingPackage, aid, p2);
5159 }
5160
5161 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5162 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 final long identity = Binder.clearCallingIdentity();
5164 try {
5165 if (TextUtils.equals(ISDR_AID, aid)) {
5166 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005167 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5168 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 if (bestComponent == null
5170 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5171 loge("The calling package is not allowed to access ISD-R.");
5172 throw new SecurityException(
5173 "The calling package is not allowed to access ISD-R.");
5174 }
Derek Tan740e1672017-06-27 14:56:27 -07005175 }
Derek Tan740e1672017-06-27 14:56:27 -07005176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005178 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5179 null /* workSource */);
5180 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 return response;
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
5184 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005185 }
5186
5187 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005188 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5190 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005191 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5192 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5193 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005194
Jordan Liu4c733742019-02-28 12:03:40 -08005195 @Override
5196 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5197 enforceModifyPermission();
5198 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5199 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5200 channel);
5201 }
5202
5203 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 final long identity = Binder.clearCallingIdentity();
5205 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 if (channel < 0) {
5207 return false;
5208 }
Jordan Liu4c733742019-02-28 12:03:40 -08005209 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5210 null /* workSource */);
5211 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 return success;
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005215 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005216 }
5217
5218 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005219 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005220 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5222 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005223 if (DBG) {
5224 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5225 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5226 + p3 + " data=" + data);
5227 }
5228 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5229 command, p1, p2, p3, data);
5230 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005231
Jordan Liu4c733742019-02-28 12:03:40 -08005232 @Override
5233 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5234 int command, int p1, int p2, int p3, String data) {
5235 enforceModifyPermission();
5236 if (DBG) {
5237 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5238 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5239 + p3 + " data=" + data);
5240 }
5241 return iccTransmitApduLogicalChannelWithPermission(
5242 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5243 data);
5244 }
5245
5246 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5247 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 final long identity = Binder.clearCallingIdentity();
5249 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005250 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 return "";
5252 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005255 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5256 null /* workSource */);
5257 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 // Append the returned status code to the end of the response payload.
5260 String s = Integer.toHexString(
5261 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5262 if (response.payload != null) {
5263 s = IccUtils.bytesToHexString(response.payload) + s;
5264 }
5265 return s;
5266 } finally {
5267 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005268 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005269 }
Jake Hambye994d462014-02-03 13:10:13 -08005270
Evan Charltonc66da362014-05-16 14:06:40 -07005271 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005272 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5273 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5275 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005277 if (DBG) {
5278 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5279 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5280 }
5281 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5282 cla, command, p1, p2, p3, data);
5283 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005284
Jordan Liu4c733742019-02-28 12:03:40 -08005285 @Override
5286 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5287 int command, int p1, int p2, int p3, String data) {
5288 enforceModifyPermission();
5289 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5290 if (DBG) {
5291 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5292 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5293 + " data=" + data);
5294 }
5295
5296 return iccTransmitApduBasicChannelWithPermission(
5297 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5298 p2, p3, data);
5299 }
5300
5301 // open APDU basic channel assuming the caller has sufficient permissions
5302 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5303 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304 final long identity = Binder.clearCallingIdentity();
5305 try {
5306 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5307 && TextUtils.equals(ISDR_AID, data)) {
5308 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005309 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5310 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 if (bestComponent == null
5312 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5313 loge("The calling package is not allowed to select ISD-R.");
5314 throw new SecurityException(
5315 "The calling package is not allowed to select ISD-R.");
5316 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005317 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005320 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5321 null /* workSource */);
5322 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 // Append the returned status code to the end of the response payload.
5325 String s = Integer.toHexString(
5326 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5327 if (response.payload != null) {
5328 s = IccUtils.bytesToHexString(response.payload) + s;
5329 }
5330 return s;
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005333 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005334 }
5335
5336 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005337 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005338 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5340 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342 final long identity = Binder.clearCallingIdentity();
5343 try {
5344 if (DBG) {
5345 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5346 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5347 }
5348
5349 IccIoResult response =
5350 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5351 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5352 subId);
5353
5354 if (DBG) {
5355 log("Exchange SIM_IO [R]" + response);
5356 }
5357
5358 byte[] result = null;
5359 int length = 2;
5360 if (response.payload != null) {
5361 length = 2 + response.payload.length;
5362 result = new byte[length];
5363 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5364 } else {
5365 result = new byte[length];
5366 }
5367
5368 result[length - 1] = (byte) response.sw2;
5369 result[length - 2] = (byte) response.sw1;
5370 return result;
5371 } finally {
5372 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005373 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005374 }
5375
Nathan Haroldb3014052017-01-25 15:57:32 -08005376 /**
5377 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5378 * on a particular subscription
5379 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005380 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5381 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005383 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005384 return null;
5385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386
5387 final long identity = Binder.clearCallingIdentity();
5388 try {
5389 if (appType != TelephonyManager.APPTYPE_USIM
5390 && appType != TelephonyManager.APPTYPE_SIM) {
5391 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5392 return null;
5393 }
5394 Object response = sendRequest(
5395 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5396 if (response instanceof String[]) {
5397 return (String[]) response;
5398 }
yincheng zhao2737e882019-09-06 17:06:54 -07005399 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005401 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 } finally {
5403 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005404 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005405 }
5406
yincheng zhao2737e882019-09-06 17:06:54 -07005407 /**
5408 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5409 * subscription.
5410 *
5411 * @param subId the id of the subscription.
5412 * @param appType the uicc app type, must be USIM or SIM.
5413 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5414 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005415 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005416 * @return number of fplmns that is successfully written to the SIM.
5417 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005418 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5419 String callingFeatureId) {
5420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5421 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005422 if (DBG) logv("no permissions for setForbiddenplmns");
5423 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5424 }
5425 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5426 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5427 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5428 }
5429 if (fplmns == null) {
5430 throw new IllegalArgumentException("Fplmn List provided is null");
5431 }
5432 for (String fplmn : fplmns) {
5433 if (!CellIdentity.isValidPlmn(fplmn)) {
5434 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5435 }
5436 }
5437 final long identity = Binder.clearCallingIdentity();
5438 try {
5439 Object response = sendRequest(
5440 CMD_SET_FORBIDDEN_PLMNS,
5441 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5442 subId);
5443 return (int) response;
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
5446 }
5447 }
5448
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005449 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005450 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5452 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005453
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 final long identity = Binder.clearCallingIdentity();
5455 try {
5456 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5457 if (response.payload == null) {
5458 return "";
5459 }
Evan Charltonc66da362014-05-16 14:06:40 -07005460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 // Append the returned status code to the end of the response payload.
5462 String s = Integer.toHexString(
5463 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5464 s = IccUtils.bytesToHexString(response.payload) + s;
5465 return s;
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
5468 }
Evan Charltonc66da362014-05-16 14:06:40 -07005469 }
5470
Jake Hambye994d462014-02-03 13:10:13 -08005471 /**
5472 * Read 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 * @return the NV item as a String, or null on error.
5477 */
5478 @Override
5479 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005480 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5482 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483
5484 final long identity = Binder.clearCallingIdentity();
5485 try {
5486 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005487 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5489 return value;
5490 } finally {
5491 Binder.restoreCallingIdentity(identity);
5492 }
Jake Hambye994d462014-02-03 13:10:13 -08005493 }
5494
5495 /**
5496 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5497 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5498 *
5499 * @param itemID the ID of the item to read
5500 * @param itemValue the value to write, as a String
5501 * @return true on success; false on any failure
5502 */
5503 @Override
5504 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005505 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5507 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508
5509 final long identity = Binder.clearCallingIdentity();
5510 try {
5511 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5512 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005513 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5515 return success;
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
Jake Hambye994d462014-02-03 13:10:13 -08005519 }
5520
5521 /**
5522 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5523 * Used for device configuration by some CDMA operators.
5524 *
5525 * @param preferredRoamingList byte array containing the new PRL
5526 * @return true on success; false on any failure
5527 */
5528 @Override
5529 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5531 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532
5533 final long identity = Binder.clearCallingIdentity();
5534 try {
5535 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5536 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5537 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5538 return success;
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
Jake Hambye994d462014-02-03 13:10:13 -08005542 }
5543
5544 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005545 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005546 * Used for device configuration by some CDMA operators.
5547 *
chen xu6dac5ab2018-10-26 17:39:23 -07005548 * @param slotIndex - device slot.
5549 *
Jake Hambye994d462014-02-03 13:10:13 -08005550 * @return true on success; false on any failure
5551 */
5552 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005553 public boolean resetModemConfig(int slotIndex) {
5554 Phone phone = PhoneFactory.getPhone(slotIndex);
5555 if (phone != null) {
5556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5557 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558
chen xu6dac5ab2018-10-26 17:39:23 -07005559 final long identity = Binder.clearCallingIdentity();
5560 try {
5561 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5562 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5563 return success;
5564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 }
chen xu6dac5ab2018-10-26 17:39:23 -07005568 return false;
5569 }
5570
5571 /**
5572 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5573 *
5574 * @param slotIndex - device slot.
5575 *
5576 * @return true on success; false on any failure
5577 */
5578 @Override
5579 public boolean rebootModem(int slotIndex) {
5580 Phone phone = PhoneFactory.getPhone(slotIndex);
5581 if (phone != null) {
5582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5583 mApp, phone.getSubId(), "rebootModem");
5584
5585 final long identity = Binder.clearCallingIdentity();
5586 try {
5587 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5588 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5589 return success;
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
5593 }
5594 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005595 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005596
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005597 public String[] getPcscfAddress(String apnType, String callingPackage,
5598 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005599 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5601 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005602 return new String[0];
5603 }
5604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605 final long identity = Binder.clearCallingIdentity();
5606 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005607 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
Wink Saville36469e72014-06-11 15:17:00 -07005611 }
5612
Brad Ebinger51f743a2017-01-23 13:50:20 -08005613 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005614 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5615 * {@link #disableIms(int)}.
5616 * @param slotIndex device slot.
5617 */
5618 public void resetIms(int slotIndex) {
5619 enforceModifyPermission();
5620
5621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 if (mImsResolver == null) {
5624 // may happen if the does not support IMS.
5625 return;
5626 }
5627 mImsResolver.disableIms(slotIndex);
5628 mImsResolver.enableIms(slotIndex);
5629 } finally {
5630 Binder.restoreCallingIdentity(identity);
5631 }
5632 }
5633
5634 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005635 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5636 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005637 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005638 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005639 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640
5641 final long identity = Binder.clearCallingIdentity();
5642 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005643 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005644 // may happen if the device does not support IMS.
5645 return;
5646 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005647 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005651 }
5652
5653 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005654 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5655 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005656 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005657 public void disableIms(int slotId) {
5658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659
5660 final long identity = Binder.clearCallingIdentity();
5661 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005662 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005663 // may happen if the device does not support IMS.
5664 return;
5665 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005666 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005670 }
5671
5672 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005673 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5674 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005675 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005676 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005677 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005678 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679
5680 final long identity = Binder.clearCallingIdentity();
5681 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005682 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005683 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5684 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005685 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005686 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 } finally {
5688 Binder.restoreCallingIdentity(identity);
5689 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005690 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005691 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005692 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5693 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005694 @Override
5695 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005696 enforceModifyPermission();
5697
5698 final long identity = Binder.clearCallingIdentity();
5699 try {
5700 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005701 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
5705 }
5706
5707 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005708 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005709 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005710 */
5711 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713
5714 final long identity = Binder.clearCallingIdentity();
5715 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005717 // may happen if the device does not support IMS.
5718 return null;
5719 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005720 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 } finally {
5722 Binder.restoreCallingIdentity(identity);
5723 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005724 }
5725
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005726 /**
5727 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005728 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005729 */
5730 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005735 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005736 // may happen if the device does not support IMS.
5737 return null;
5738 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005739 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005743 }
5744
Brad Ebinger884c07b2018-02-15 16:17:40 -08005745 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005746 * Sets the ImsService Package Name that Telephony will bind to.
5747 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005748 * @param slotIndex the slot ID that the ImsService should bind for.
5749 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005750 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005751 * @param featureTypes An integer array of feature types associated with a packageName.
5752 * @param packageName The name of the package that the current configuration will be replaced
5753 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005754 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005755 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005756 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5757 int[] featureTypes, String packageName) {
5758 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5759 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5761 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005762 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 final long identity = Binder.clearCallingIdentity();
5765 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005767 // may happen if the device does not support IMS.
5768 return false;
5769 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 Map<Integer, String> featureConfig = new HashMap<>();
5771 for (int featureType : featureTypes) {
5772 featureConfig.put(featureType, packageName);
5773 }
5774 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5775 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005779 }
5780
5781 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005782 * Clears any carrier ImsService overrides for the slot index specified that were previously
5783 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5784 *
5785 * This should only be used for testing.
5786 *
5787 * @param slotIndex the slot ID that the ImsService should bind for.
5788 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5789 */
5790 @Override
5791 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5792 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5793 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5794 "clearCarrierImsServiceOverride");
5795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5796 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5797 "clearCarrierImsServiceOverride");
5798
5799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 if (mImsResolver == null) {
5802 // may happen if the device does not support IMS.
5803 return false;
5804 }
5805 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
5809 }
5810
5811 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005812 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005813 *
5814 * @param slotId The slot that the ImsService is associated with.
5815 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5816 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005818 * @return the package name of the ImsService configuration.
5819 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005820 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5821 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005822 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005823 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005824 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005825 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5826 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828 final long identity = Binder.clearCallingIdentity();
5829 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005830 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005831 // may happen if the device does not support IMS.
5832 return "";
5833 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005834 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005835 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5836 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005840 }
5841
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005842 /**
5843 * Get the MmTelFeature state associated with the requested subscription id.
5844 * @param subId The subscription that the MmTelFeature is associated with.
5845 * @param callback A callback with an integer containing the
5846 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5847 */
5848 @Override
5849 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5850 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5851 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5852 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5853 "IMS not available on device.");
5854 }
5855 final long token = Binder.clearCallingIdentity();
5856 try {
5857 int slotId = getSlotIndex(subId);
5858 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5859 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5860 + subId + "'");
5861 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5862 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005863 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005864 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5865 try {
5866 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5867 } catch (RemoteException e) {
5868 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5869 + "Ignore");
5870 }
5871 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005872 } catch (ImsException e) {
5873 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005874 } finally {
5875 Binder.restoreCallingIdentity(token);
5876 }
5877 }
5878
Daniel Brightbb5840b2021-01-12 15:48:18 -08005879 /**
5880 * Sets the ims registration state on all valid {@link Phone}s.
5881 */
5882 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005883 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884
5885 final long identity = Binder.clearCallingIdentity();
5886 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005887 // NOTE: Before S, this method only set the default phone.
5888 for (final Phone phone : PhoneFactory.getPhones()) {
5889 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5890 phone.setImsRegistrationState(registered);
5891 }
5892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
Wink Saville36469e72014-06-11 15:17:00 -07005896 }
5897
5898 /**
Stuart Scott54788802015-03-30 13:18:01 -07005899 * Set the network selection mode to automatic.
5900 *
5901 */
5902 @Override
5903 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5905 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906
5907 final long identity = Binder.clearCallingIdentity();
5908 try {
shilufc958392020-01-20 11:36:01 -08005909 if (!isActiveSubscription(subId)) {
5910 return;
5911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005913 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5914 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Stuart Scott54788802015-03-30 13:18:01 -07005918 }
5919
Jack Yud10cdd42020-09-28 20:28:01 -07005920 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005921 * Ask the radio to connect to the input network and change selection mode to manual.
5922 *
5923 * @param subId the id of the subscription.
5924 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5925 * the operator to attach to.
5926 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5927 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5928 * normal network selection next time.
5929 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005930 */
5931 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005932 public boolean setNetworkSelectionModeManual(
5933 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5935 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005936
5937 if (!isActiveSubscription(subId)) {
5938 return false;
5939 }
5940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 final long identity = Binder.clearCallingIdentity();
5942 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005943 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005945 if (DBG) {
5946 log("setNetworkSelectionModeManual: subId: " + subId
5947 + " operator: " + operatorInfo);
5948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5950 } finally {
5951 Binder.restoreCallingIdentity(identity);
5952 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005953 }
shilu84f6e8b2019-12-19 13:58:01 -08005954 /**
5955 * Get the manual network selection
5956 *
5957 * @param subId the id of the subscription.
5958 *
5959 * @return the previously saved user selected PLMN
5960 */
5961 @Override
5962 public String getManualNetworkSelectionPlmn(int subId) {
5963 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005964 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005965 mApp, subId, "getManualNetworkSelectionPlmn");
5966
5967 final long identity = Binder.clearCallingIdentity();
5968 try {
5969 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005970 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005971 }
5972
5973 final Phone phone = getPhone(subId);
5974 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005975 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005976 }
5977 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5978 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5979 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5980 } finally {
5981 Binder.restoreCallingIdentity(identity);
5982 }
5983 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005984
5985 /**
5986 * Scans for available networks.
5987 */
5988 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005989 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5990 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5992 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005993 LocationAccessPolicy.LocationPermissionResult locationResult =
5994 LocationAccessPolicy.checkLocationPermission(mApp,
5995 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5996 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005997 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005998 .setCallingPid(Binder.getCallingPid())
5999 .setCallingUid(Binder.getCallingUid())
6000 .setMethod("getCellNetworkScanResults")
6001 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006002 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6003 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006004 .build());
6005 switch (locationResult) {
6006 case DENIED_HARD:
6007 throw new SecurityException("Not allowed to access scan results -- location");
6008 case DENIED_SOFT:
6009 return null;
6010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011
Pengquan Menga1bb6272018-09-06 09:59:22 -07006012 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 try {
6014 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006015 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 } finally {
6018 Binder.restoreCallingIdentity(identity);
6019 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006020 }
6021
6022 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006023 * Get the call forwarding info, given the call forwarding reason.
6024 */
6025 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006026 public void getCallForwarding(int subId, int callForwardingReason,
6027 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006028 enforceReadPrivilegedPermission("getCallForwarding");
6029 long identity = Binder.clearCallingIdentity();
6030 try {
6031 if (DBG) {
6032 log("getCallForwarding: subId " + subId
6033 + " callForwardingReason" + callForwardingReason);
6034 }
Hall Liu27d24262020-09-18 19:04:59 -07006035
6036 Phone phone = getPhone(subId);
6037 if (phone == null) {
6038 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006039 callback.onError(
6040 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006041 } catch (RemoteException e) {
6042 // ignore
6043 }
6044 return;
6045 }
6046
6047 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6048 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6049 @Override
6050 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6051 try {
6052 callback.onCallForwardingInfoAvailable(info);
6053 } catch (RemoteException e) {
6054 // ignore
6055 }
6056 }
6057
6058 @Override
6059 public void onError(int error) {
6060 try {
6061 callback.onError(error);
6062 } catch (RemoteException e) {
6063 // ignore
6064 }
6065 }
6066 });
6067 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
6071 }
6072
6073 /**
6074 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6075 * reason, the number to forward, and the timeout before the forwarding is attempted.
6076 */
6077 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006078 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6079 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006080 enforceModifyPermission();
6081 long identity = Binder.clearCallingIdentity();
6082 try {
6083 if (DBG) {
6084 log("setCallForwarding: subId " + subId
6085 + " callForwardingInfo" + callForwardingInfo);
6086 }
Hall Liu27d24262020-09-18 19:04:59 -07006087
6088 Phone phone = getPhone(subId);
6089 if (phone == null) {
6090 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006091 callback.accept(
6092 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006093 } catch (RemoteException e) {
6094 // ignore
6095 }
6096 return;
6097 }
6098
6099 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6100 FunctionalUtils.ignoreRemoteException(callback::accept));
6101
6102 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006103 } finally {
6104 Binder.restoreCallingIdentity(identity);
6105 }
6106 }
6107
6108 /**
Hall Liu27d24262020-09-18 19:04:59 -07006109 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006110 */
6111 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006112 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006113 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006114 long identity = Binder.clearCallingIdentity();
6115 try {
Hall Liu27d24262020-09-18 19:04:59 -07006116 Phone phone = getPhone(subId);
6117 if (phone == null) {
6118 try {
6119 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6120 } catch (RemoteException e) {
6121 // ignore
6122 }
6123 return;
6124 }
SongFerngWang0e767992021-03-31 22:08:45 +08006125 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6126 PersistableBundle c = configManager.getConfigForSubId(subId);
6127 boolean requireUssd = c.getBoolean(
6128 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006129
Shuo Qian4a594052020-01-23 11:59:30 -08006130 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006131 if (requireUssd) {
6132 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6133 getSubscriptionCarrierId(subId));
6134 String newUssdCommand = "";
6135 try {
6136 newUssdCommand = carrierXmlParser.getFeature(
6137 CarrierXmlParser.FEATURE_CALL_WAITING)
6138 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6139 } catch (NullPointerException e) {
6140 loge("Failed to generate USSD number" + e);
6141 }
6142 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6143 mMainThreadHandler, callback, carrierXmlParser,
6144 CarrierXmlParser.SsEntry.SSAction.QUERY);
6145 final String ussdCommand = newUssdCommand;
6146 Executors.newSingleThreadExecutor().execute(() -> {
6147 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6148 });
6149 } else {
6150 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6151 callback::accept);
6152 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6153 }
Shuo Qian4a594052020-01-23 11:59:30 -08006154 } finally {
6155 Binder.restoreCallingIdentity(identity);
6156 }
6157 }
6158
6159 /**
Hall Liu27d24262020-09-18 19:04:59 -07006160 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006161 */
6162 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006163 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006164 enforceModifyPermission();
6165 long identity = Binder.clearCallingIdentity();
6166 try {
Hall Liu27d24262020-09-18 19:04:59 -07006167 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6168
6169 Phone phone = getPhone(subId);
6170 if (phone == null) {
6171 try {
6172 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6173 } catch (RemoteException e) {
6174 // ignore
6175 }
6176 return;
6177 }
6178
SongFerngWang0e767992021-03-31 22:08:45 +08006179 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6180 PersistableBundle c = configManager.getConfigForSubId(subId);
6181 boolean requireUssd = c.getBoolean(
6182 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006183
SongFerngWang0e767992021-03-31 22:08:45 +08006184 if (DBG) log("getCallWaitingStatus: subId " + subId);
6185 if (requireUssd) {
6186 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6187 getSubscriptionCarrierId(subId));
6188 CarrierXmlParser.SsEntry.SSAction ssAction =
6189 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6190 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6191 String newUssdCommand = "";
6192 try {
6193 newUssdCommand = carrierXmlParser.getFeature(
6194 CarrierXmlParser.FEATURE_CALL_WAITING)
6195 .makeCommand(ssAction, null);
6196 } catch (NullPointerException e) {
6197 loge("Failed to generate USSD number" + e);
6198 }
6199 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6200 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6201 final String ussdCommand = newUssdCommand;
6202 Executors.newSingleThreadExecutor().execute(() -> {
6203 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6204 });
6205 } else {
6206 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6207 FunctionalUtils.ignoreRemoteException(callback::accept));
6208
6209 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6210 }
Shuo Qian4a594052020-01-23 11:59:30 -08006211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
6214 }
6215
6216 /**
yinxub1bed742017-04-17 11:45:04 -07006217 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006218 *
yinxub1bed742017-04-17 11:45:04 -07006219 * @param subId id of the subscription
6220 * @param request contains the radio access networks with bands/channels to scan
6221 * @param messenger callback messenger for scan results or errors
6222 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006223 * @return the id of the requested scan which can be used to stop the scan.
6224 */
6225 @Override
6226 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006227 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6229 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006230 LocationAccessPolicy.LocationPermissionResult locationResult =
6231 LocationAccessPolicy.checkLocationPermission(mApp,
6232 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6233 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006234 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006235 .setCallingPid(Binder.getCallingPid())
6236 .setCallingUid(Binder.getCallingUid())
6237 .setMethod("requestNetworkScan")
6238 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006239 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6240 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006241 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006242 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006243 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6244 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006245 if (e != null) {
6246 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6247 throw e;
6248 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006249 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006250 return TelephonyScanManager.INVALID_SCAN_ID;
6251 }
6252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 }
Hall Liu912dfd32019-04-25 14:02:26 -07006254 int callingUid = Binder.getCallingUid();
6255 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006256 final long identity = Binder.clearCallingIdentity();
6257 try {
6258 return mNetworkScanRequestTracker.startNetworkScan(
6259 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006260 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006261 } finally {
6262 Binder.restoreCallingIdentity(identity);
6263 }
yinxu504e1392017-04-12 16:03:22 -07006264 }
6265
Hall Liub2ac8ef2019-02-28 15:56:23 -08006266 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006267 NetworkScanRequest request, int subId, String callingPackage) {
6268 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006269 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6270 boolean hasNetworkScanPermission =
6271 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6272 == PERMISSION_GRANTED;
6273
6274 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6275 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6276 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006277 }
6278
6279 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6280 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006281 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6282 return new SecurityException("Specific channels must not be"
6283 + " scanned without location access.");
6284 }
6285 }
6286 }
6287
Hall Liub2ac8ef2019-02-28 15:56:23 -08006288 return null;
6289 }
6290
yinxu504e1392017-04-12 16:03:22 -07006291 /**
6292 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006293 *
6294 * @param subId id of the subscription
6295 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006296 */
6297 @Override
6298 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6300 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301
Hall Liu912dfd32019-04-25 14:02:26 -07006302 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 final long identity = Binder.clearCallingIdentity();
6304 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006305 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
yinxu504e1392017-04-12 16:03:22 -07006309 }
6310
6311 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006312 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006313 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006314 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006315 */
6316 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006317 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006318 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006319 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006320 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321
6322 final long identity = Binder.clearCallingIdentity();
6323 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006324 if (DBG) log("getAllowedNetworkTypesBitmask");
6325 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6326 int networkTypesBitmask = (result != null ? result[0] : -1);
6327 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6328 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006332 }
6333
6334 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006335 * Get the allowed network types for certain reason.
6336 *
6337 * @param subId the id of the subscription.
6338 * @param reason the reason the allowed network type change is taking place
6339 * @return the allowed network types.
6340 */
6341 @Override
6342 public long getAllowedNetworkTypesForReason(int subId,
6343 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006344 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006345 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006346 final long identity = Binder.clearCallingIdentity();
6347 try {
6348 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6349 } finally {
6350 Binder.restoreCallingIdentity(identity);
6351 }
6352 }
6353
6354 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006355 * Enable/Disable E-UTRA-NR Dual Connectivity
6356 * @param subId subscription id of the sim card
6357 * @param nrDualConnectivityState expected NR dual connectivity state
6358 * This can be passed following states
6359 * <ol>
6360 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6361 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6362 * <li>Disable NR dual connectivity and force secondary cell to be released
6363 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6364 * </ol>
6365 * @return operation result.
6366 */
6367 @Override
6368 public int setNrDualConnectivityState(int subId,
6369 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6371 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006372 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006373 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6374 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6375 }
6376
Sooraj Sasindran37444802020-08-11 10:40:43 -07006377 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6378 final long identity = Binder.clearCallingIdentity();
6379 try {
6380 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6381 nrDualConnectivityState, subId,
6382 workSource);
6383 if (DBG) log("enableNRDualConnectivity result: " + result);
6384 return result;
6385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
6388 }
6389
6390 /**
6391 * Is E-UTRA-NR Dual Connectivity enabled
6392 * @return true if dual connectivity is enabled else false
6393 */
6394 @Override
6395 public boolean isNrDualConnectivityEnabled(int subId) {
6396 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006397 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006398 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006399 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006400 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6401 return false;
6402 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006403 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6404 final long identity = Binder.clearCallingIdentity();
6405 try {
6406 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6407 null, subId, workSource);
6408 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6409 return isEnabled;
6410 } finally {
6411 Binder.restoreCallingIdentity(identity);
6412 }
6413 }
6414
6415 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006416 * Set the allowed network types of the device and
6417 * provide the reason triggering the allowed network change.
6418 *
6419 * @param subId the id of the subscription.
6420 * @param reason the reason the allowed network type change is taking place
6421 * @param allowedNetworkTypes the allowed network types.
6422 * @return true on success; false on any failure.
6423 */
6424 @Override
6425 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006426 @TelephonyManager.AllowedNetworkTypesReason int reason,
6427 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6429 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006430 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006431 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6432 return false;
6433 }
6434 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6435 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006436 return false;
6437 }
6438
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006439 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6440 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6441
6442
6443 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6444 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6445 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006446 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006447
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006448 final long identity = Binder.clearCallingIdentity();
6449 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006450 Boolean success = (Boolean) sendRequest(
6451 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6452 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6453
6454 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6455 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
6459 }
6460
6461 /**
Miaoa84611c2019-03-15 09:21:10 +08006462 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006463 *
Miaoa84611c2019-03-15 09:21:10 +08006464 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006465 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006466 * @hide
6467 */
6468 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006469 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006470 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006472 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473 try {
Miaoa84611c2019-03-15 09:21:10 +08006474 if (phone != null) {
6475 return phone.hasMatchedTetherApnSetting();
6476 } else {
6477 return false;
6478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479 } finally {
6480 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006481 }
Junda Liu475951f2014-11-07 16:45:03 -08006482 }
6483
6484 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006485 * Enable or disable always reporting signal strength changes from radio.
6486 *
6487 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6488 */
6489 @Override
6490 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6491 enforceModifyPermission();
6492 enforceSystemCaller();
6493
6494 final long identity = Binder.clearCallingIdentity();
6495 final Phone phone = getPhone(subId);
6496 try {
6497 if (phone != null) {
6498 if (DBG) {
6499 log("setAlwaysReportSignalStrength: subId=" + subId
6500 + " isEnable=" + isEnable);
6501 }
6502 phone.setAlwaysReportSignalStrength(isEnable);
6503 } else {
6504 loge("setAlwaysReportSignalStrength: no phone found for subId="
6505 + subId);
6506 }
6507 } finally {
6508 Binder.restoreCallingIdentity(identity);
6509 }
6510 }
6511
6512 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006513 * Get the user enabled state of Mobile Data.
6514 *
6515 * TODO: remove and use isUserDataEnabled.
6516 * This can't be removed now because some vendor codes
6517 * calls through ITelephony directly while they should
6518 * use TelephonyManager.
6519 *
6520 * @return true on enabled
6521 */
6522 @Override
6523 public boolean getDataEnabled(int subId) {
6524 return isUserDataEnabled(subId);
6525 }
6526
6527 /**
6528 * Get whether mobile data is enabled per user setting.
6529 *
6530 * There are other factors deciding whether mobile data is actually enabled, but they are
6531 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006532 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006533 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006534 *
6535 * @return {@code true} if data is enabled else {@code false}
6536 */
6537 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006538 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006539 try {
6540 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6541 null);
6542 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6544 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546
6547 final long identity = Binder.clearCallingIdentity();
6548 try {
6549 int phoneId = mSubscriptionController.getPhoneId(subId);
6550 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6551 Phone phone = PhoneFactory.getPhone(phoneId);
6552 if (phone != null) {
6553 boolean retVal = phone.isUserDataEnabled();
6554 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6555 return retVal;
6556 } else {
6557 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6558 return false;
6559 }
6560 } finally {
6561 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006562 }
6563 }
6564
6565 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006566 * Checks if the device is capable of mobile data by considering whether whether the
6567 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6568 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006569 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006570 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006571 */
6572 @Override
6573 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006574 try {
6575 try {
6576 mApp.enforceCallingOrSelfPermission(
6577 android.Manifest.permission.ACCESS_NETWORK_STATE,
6578 null);
6579 } catch (Exception e) {
6580 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6581 "isDataEnabled");
6582 }
6583 } catch (Exception e) {
6584 enforceReadPrivilegedPermission("isDataEnabled");
6585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586
6587 final long identity = Binder.clearCallingIdentity();
6588 try {
6589 int phoneId = mSubscriptionController.getPhoneId(subId);
6590 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6591 Phone phone = PhoneFactory.getPhone(phoneId);
6592 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006593 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6595 return retVal;
6596 } else {
6597 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6598 return false;
6599 }
6600 } finally {
6601 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006602 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006603 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006604
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006605 /**
6606 * Check if data is enabled for a specific reason
6607 * @param subId Subscription index
6608 * @param reason the reason the data enable change is taking place
6609 * @return {@code true} if the overall data is enabled; {@code false} if not.
6610 */
6611 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006612 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006613 @TelephonyManager.DataEnabledReason int reason) {
6614 try {
6615 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6616 null);
6617 } catch (Exception e) {
6618 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006619 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006620 }
6621
6622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 int phoneId = mSubscriptionController.getPhoneId(subId);
6626 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006627 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006628 + " reason=" + reason);
6629 }
6630 Phone phone = PhoneFactory.getPhone(phoneId);
6631 if (phone != null) {
6632 boolean retVal;
6633 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6634 retVal = phone.isUserDataEnabled();
6635 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006636 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006637 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006638 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006639 return retVal;
6640 } else {
6641 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006642 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006643 + subId + " retVal=false");
6644 }
6645 return false;
6646 }
6647 } finally {
6648 Binder.restoreCallingIdentity(identity);
6649 }
6650 }
6651
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006652 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006653 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006654 if (uid == Process.PHONE_UID) {
6655 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6656 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006657 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6658 }
6659
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006660 //load access rules from carrier configs, and check those as well: b/139133814
6661 SubscriptionController subController = SubscriptionController.getInstance();
6662 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6663 || subController == null) return privilegeFromSim;
6664
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006665 PackageManager pkgMgr = phone.getContext().getPackageManager();
6666 String[] packages = pkgMgr.getPackagesForUid(uid);
6667
6668 final long identity = Binder.clearCallingIdentity();
6669 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006670 int subId = phone.getSubId();
6671 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6672 // A test override is in place for the privileges for this subId, so don't try to
6673 // read the subscription privileges.
6674 return privilegeFromSim;
6675 }
6676 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006677 SubscriptionManager subManager = (SubscriptionManager)
6678 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6679 for (String pkg : packages) {
6680 if (subManager.canManageSubscription(subInfo, pkg)) {
6681 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6682 }
6683 }
6684 return privilegeFromSim;
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
6688 }
6689
6690 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6691 String pkgName) {
6692 //load access rules from carrier configs, and check those as well: b/139133814
6693 SubscriptionController subController = SubscriptionController.getInstance();
6694 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6695 || subController == null) return privilegeFromSim;
6696
6697 final long identity = Binder.clearCallingIdentity();
6698 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006699 int subId = phone.getSubId();
6700 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6701 // A test override is in place for the privileges for this subId, so don't try to
6702 // read the subscription privileges.
6703 return privilegeFromSim;
6704 }
6705 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006706 SubscriptionManager subManager = (SubscriptionManager)
6707 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6708 return subManager.canManageSubscription(subInfo, pkgName)
6709 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6710 } finally {
6711 Binder.restoreCallingIdentity(identity);
6712 }
6713 }
6714
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006715 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006716 public int getCarrierPrivilegeStatus(int subId) {
6717 final Phone phone = getPhone(subId);
6718 if (phone == null) {
6719 loge("getCarrierPrivilegeStatus: Invalid subId");
6720 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6721 }
6722 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006723 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006724 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006725 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6726 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006727
6728 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6729 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006730 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006731 }
Junda Liu29340342014-07-10 15:23:27 -07006732
6733 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006734 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006735 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006736 final Phone phone = getPhone(subId);
6737 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006738 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006739 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6740 }
6741 UiccProfile profile =
6742 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6743 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006744 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006745 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6746 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006747 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006748 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006749 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006750 }
6751
6752 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006753 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006754 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006755 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006757 }
6758
6759 int phoneId = SubscriptionManager.getPhoneId(subId);
6760 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006761 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006762 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006763 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6764 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006765 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6766 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6767 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006768 }
6769
6770 @Override
6771 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006772 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006773 if (TextUtils.isEmpty(pkgName))
6774 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006775 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6776 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6777 UiccCard card = UiccController.getInstance().getUiccCard(i);
6778 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006779 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006780 continue;
6781 }
6782
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006783 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6784 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6785 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006786 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6787 break;
6788 }
6789 }
6790
6791 return result;
Junda Liu29340342014-07-10 15:23:27 -07006792 }
Derek Tan89e89d42014-07-08 17:00:10 -07006793
6794 @Override
Junda Liue64de782015-04-16 17:19:16 -07006795 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006796 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006797 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6798 loge("phoneId " + phoneId + " is not valid.");
6799 return null;
6800 }
6801 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006802 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006803 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006804 return null ;
6805 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006806 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006807 }
6808
Amith Yamasani6e118872016-02-19 12:53:51 -08006809 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006810 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006811 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006812 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006813 List<String> privilegedPackages = new ArrayList<>();
6814 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006815 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6816 // has UICC in that slot.
6817 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006818 if (card.hasCarrierPrivilegeRules()) {
6819 if (packages == null) {
6820 // Only check packages in user 0 for now
6821 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006822 PackageManager.MATCH_DISABLED_COMPONENTS
6823 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006824 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006825 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006826 }
6827 for (int p = packages.size() - 1; p >= 0; p--) {
6828 PackageInfo pkgInfo = packages.get(p);
6829 if (pkgInfo != null && pkgInfo.packageName != null
6830 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006831 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006832 privilegedPackages.add(pkgInfo.packageName);
6833 }
6834 }
6835 }
6836 }
6837 return privilegedPackages;
6838 }
6839
chen xuf7e9fe82019-05-09 19:31:02 -07006840 @Override
6841 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006842 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6843
6844 final long identity = Binder.clearCallingIdentity();
6845
chen xuf7e9fe82019-05-09 19:31:02 -07006846 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006847 try {
6848 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6849 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6850 }
6851 } finally {
6852 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006853 }
6854 return privilegedPackages;
6855 }
6856
Wink Savilleb564aae2014-10-23 10:18:09 -07006857 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006858 final Phone phone = getPhone(subId);
6859 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006860 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006861 return null;
6862 }
6863 String iccId = card.getIccId();
6864 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006865 return null;
6866 }
6867 return iccId;
6868 }
6869
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006870 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006871 public void setCallComposerStatus(int subId, int status) {
6872 enforceModifyPermission();
6873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 Phone phone = getPhone(subId);
6877 if (phone != null) {
6878 Phone defaultPhone = phone.getImsPhone();
6879 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6880 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6881 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006882 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6883 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006884 }
6885 }
Shuo Qian284ae752020-12-22 19:10:14 -08006886 } catch (ImsException e) {
6887 throw new ServiceSpecificException(e.getCode());
6888 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006889 Binder.restoreCallingIdentity(identity);
6890 }
6891 }
6892
6893 @Override
6894 public int getCallComposerStatus(int subId) {
6895 enforceReadPrivilegedPermission("getCallComposerStatus");
6896
6897 final long identity = Binder.clearCallingIdentity();
6898 try {
6899 Phone phone = getPhone(subId);
6900 if (phone != null) {
6901 Phone defaultPhone = phone.getImsPhone();
6902 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6903 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6904 return imsPhone.getCallComposerStatus();
6905 }
6906 }
6907 } finally {
6908 Binder.restoreCallingIdentity(identity);
6909 }
6910 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6911 }
6912
6913 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006914 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6915 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006916 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006917 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 final long identity = Binder.clearCallingIdentity();
6920 try {
6921 final String iccId = getIccId(subId);
6922 final Phone phone = getPhone(subId);
6923 if (phone == null) {
6924 return false;
6925 }
6926 final String subscriberId = phone.getSubscriberId();
6927
6928 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006929 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 + subscriberId + " to " + number);
6931 }
6932
6933 if (TextUtils.isEmpty(iccId)) {
6934 return false;
6935 }
6936
6937 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6938
6939 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6940 if (alphaTag == null) {
6941 editor.remove(alphaTagPrefKey);
6942 } else {
6943 editor.putString(alphaTagPrefKey, alphaTag);
6944 }
6945
6946 // Record both the line number and IMSI for this ICCID, since we need to
6947 // track all merged IMSIs based on line number
6948 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6949 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6950 if (number == null) {
6951 editor.remove(numberPrefKey);
6952 editor.remove(subscriberPrefKey);
6953 } else {
6954 editor.putString(numberPrefKey, number);
6955 editor.putString(subscriberPrefKey, subscriberId);
6956 }
6957
6958 editor.commit();
6959 return true;
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006962 }
Derek Tan7226c842014-07-02 17:42:23 -07006963 }
6964
6965 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006966 public String getLine1NumberForDisplay(int subId, String callingPackage,
6967 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006968 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006970 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006971 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006972 return null;
6973 }
Derek Tan97ebb422014-09-05 16:55:38 -07006974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006975 final long identity = Binder.clearCallingIdentity();
6976 try {
6977 String iccId = getIccId(subId);
6978 if (iccId != null) {
6979 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6980 if (DBG_MERGE) {
6981 log("getLine1NumberForDisplay returning "
6982 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6983 }
6984 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6987 return null;
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006990 }
Derek Tan7226c842014-07-02 17:42:23 -07006991 }
6992
6993 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006994 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6995 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006997 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006998 return null;
6999 }
Derek Tan97ebb422014-09-05 16:55:38 -07007000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 final long identity = Binder.clearCallingIdentity();
7002 try {
7003 String iccId = getIccId(subId);
7004 if (iccId != null) {
7005 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7006 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7007 }
7008 return null;
7009 } finally {
7010 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007011 }
Derek Tan7226c842014-07-02 17:42:23 -07007012 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007013
7014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007015 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7016 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007017 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7018 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007020 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007021 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007022 return null;
7023 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007024
Jordan Liub49b04b2019-05-06 14:45:15 -07007025 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7026 // the process, where TelephonyManager was instantiated.
7027 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007028 final long identity = Binder.clearCallingIdentity();
7029 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007030 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 final TelephonyManager tele = TelephonyManager.from(context);
7032 final SubscriptionManager sub = SubscriptionManager.from(context);
7033
7034 // Figure out what subscribers are currently active
7035 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036
Jordan Liub49b04b2019-05-06 14:45:15 -07007037 // Only consider subs which match the current subId
7038 // This logic can be simplified. See b/131189269 for progress.
7039 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007040 activeSubscriberIds.add(tele.getSubscriberId(subId));
7041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042
7043 // First pass, find a number override for an active subscriber
7044 String mergeNumber = null;
7045 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7046 for (String key : prefs.keySet()) {
7047 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7048 final String subscriberId = (String) prefs.get(key);
7049 if (activeSubscriberIds.contains(subscriberId)) {
7050 final String iccId = key.substring(
7051 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7052 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7053 mergeNumber = (String) prefs.get(numberKey);
7054 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007055 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 + " for active subscriber " + subscriberId);
7057 }
7058 if (!TextUtils.isEmpty(mergeNumber)) {
7059 break;
7060 }
7061 }
7062 }
7063 }
7064
7065 // Shortcut when no active merged subscribers
7066 if (TextUtils.isEmpty(mergeNumber)) {
7067 return null;
7068 }
7069
7070 // Second pass, find all subscribers under that line override
7071 final ArraySet<String> result = new ArraySet<>();
7072 for (String key : prefs.keySet()) {
7073 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7074 final String number = (String) prefs.get(key);
7075 if (mergeNumber.equals(number)) {
7076 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7077 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7078 final String subscriberId = (String) prefs.get(subscriberKey);
7079 if (!TextUtils.isEmpty(subscriberId)) {
7080 result.add(subscriberId);
7081 }
7082 }
7083 }
7084 }
7085
7086 final String[] resultArray = result.toArray(new String[result.size()]);
7087 Arrays.sort(resultArray);
7088 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007089 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7091 }
7092 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007093 } finally {
7094 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007095 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007096 }
7097
7098 @Override
zoey chen38003472019-12-13 17:16:31 +08007099 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7100 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007101
7102 final long identity = Binder.clearCallingIdentity();
7103 try {
7104 final TelephonyManager telephonyManager = mApp.getSystemService(
7105 TelephonyManager.class);
7106 String subscriberId = telephonyManager.getSubscriberId(subId);
7107 if (subscriberId == null) {
7108 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007109 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007110 + subId);
7111 }
7112 return null;
7113 }
7114
7115 final SubscriptionInfo info = SubscriptionController.getInstance()
7116 .getSubscriptionInfo(subId);
7117 final ParcelUuid groupUuid = info.getGroupUuid();
7118 // If it doesn't belong to any group, return just subscriberId of itself.
7119 if (groupUuid == null) {
7120 return new String[]{subscriberId};
7121 }
7122
7123 // Get all subscriberIds from the group.
7124 final List<String> mergedSubscriberIds = new ArrayList<>();
7125 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007126 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007127 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007128 for (SubscriptionInfo subInfo : groupInfos) {
7129 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7130 if (subscriberId != null) {
7131 mergedSubscriberIds.add(subscriberId);
7132 }
7133 }
7134
7135 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138
7139 }
7140 }
7141
7142 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007143 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007144 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007145 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146
7147 final long identity = Binder.clearCallingIdentity();
7148 try {
7149 final Phone phone = getPhone(subId);
7150 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
7153 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007154 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007155
7156 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007157 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007158 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7159 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007160 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7161 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162
7163 final long identity = Binder.clearCallingIdentity();
7164 try {
7165 final Phone phone = getPhone(subId);
7166 if (phone == null) {
7167 return false;
7168 }
7169 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7170 cdmaNonRoamingList);
7171 } finally {
7172 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007173 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007174 }
7175
7176 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007177 @Deprecated
7178 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7179 enforceModifyPermission();
7180
7181 int returnValue = 0;
7182 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007183 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007184 if(result.exception == null) {
7185 if (result.result != null) {
7186 byte[] responseData = (byte[])(result.result);
7187 if(responseData.length > oemResp.length) {
7188 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7189 responseData.length + "bytes. Buffer Size is " +
7190 oemResp.length + "bytes.");
7191 }
7192 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7193 returnValue = responseData.length;
7194 }
7195 } else {
7196 CommandException ex = (CommandException) result.exception;
7197 returnValue = ex.getCommandError().ordinal();
7198 if(returnValue > 0) returnValue *= -1;
7199 }
7200 } catch (RuntimeException e) {
7201 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7202 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7203 if(returnValue > 0) returnValue *= -1;
7204 }
7205
7206 return returnValue;
7207 }
7208
7209 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007210 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007211 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007212 try {
7213 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007214 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007215 mApp, phone.getSubId(), "getRadioAccessFamily");
7216 } catch (SecurityException e) {
7217 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7218 throw e;
7219 }
chen xub97461a2018-10-26 14:17:57 -07007220 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007221 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007222 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 final long identity = Binder.clearCallingIdentity();
7225 try {
chen xub97461a2018-10-26 14:17:57 -07007226 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007227 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007228 mApp, phone.getSubId(), "getRadioAccessFamily");
7229 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
chen xub97461a2018-10-26 14:17:57 -07007233 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007234 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007235
7236 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007237 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007238 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007239 try {
7240 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7241 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007242 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007243 }
7244 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007245 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007246 }
7247 RoleManager rm = mApp.getSystemService(RoleManager.class);
7248 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7249 if (!dialerRoleHolders.contains(callingPackage)) {
7250 throw new SecurityException("App must be the dialer role holder to"
7251 + " upload a call composer pic");
7252 }
7253
7254 Executors.newSingleThreadExecutor().execute(() -> {
7255 ByteArrayOutputStream output = new ByteArrayOutputStream(
7256 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7257 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7258 boolean readUntilEnd = false;
7259 int totalBytesRead = 0;
7260 byte[] buffer = new byte[16 * 1024];
7261 while (true) {
7262 int numRead;
7263 try {
7264 numRead = input.read(buffer);
7265 } catch (IOException e) {
7266 try {
7267 fd.checkError();
7268 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7269 null);
7270 } catch (IOException e1) {
7271 // This means that the other side closed explicitly with an error. If this
7272 // happens, log and ignore.
7273 loge("Remote end of call composer picture pipe closed: " + e1);
7274 }
7275 break;
7276 }
7277 if (numRead == -1) {
7278 readUntilEnd = true;
7279 break;
7280 }
7281 totalBytesRead += numRead;
7282 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7283 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7284 try {
7285 input.close();
7286 } catch (IOException e) {
7287 // ignore
7288 }
7289 break;
7290 }
7291 output.write(buffer, 0, numRead);
7292 }
7293 // Generally, the remote end will close the file descriptors. The only case where we
7294 // close is above, where the picture size is too big.
7295
7296 try {
7297 fd.checkError();
7298 } catch (IOException e) {
7299 loge("Remote end for call composer closed with an error: " + e);
7300 return;
7301 }
7302
Hall Liuaa4211e2021-01-20 15:43:39 -08007303 if (!readUntilEnd) {
7304 loge("Did not finish reading entire image; aborting");
7305 return;
7306 }
Hall Liu82694d52020-12-11 18:22:04 -08007307
Hall Liuaa4211e2021-01-20 15:43:39 -08007308 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7309 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7310 new CallComposerPictureTransfer.Factory() {},
7311 imageData,
7312 (result) -> {
7313 if (result.first != null) {
7314 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7315 Bundle outputResult = new Bundle();
7316 outputResult.putParcelable(
7317 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7318 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7319 outputResult);
7320 } else {
7321 callback.send(result.second, null);
7322 }
7323 }
7324 );
Hall Liu82694d52020-12-11 18:22:04 -08007325 });
7326 }
7327
7328 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007329 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007330 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007331 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332
7333 final long identity = Binder.clearCallingIdentity();
7334 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007335 ImsManager.getInstance(defaultPhone.getContext(),
7336 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007340 }
7341
7342 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007343 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007344 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7346 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007347 return false;
7348 }
Svet Ganovb320e182015-04-16 12:30:10 -07007349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 final long identity = Binder.clearCallingIdentity();
7351 try {
7352 // Check the user preference and the system-level IMS setting. Even if the user has
7353 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7354 // In the long run, we may instead need to check if there exists a connection service
7355 // which can support video calling.
7356 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007357 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 return imsManager.isVtEnabledByPlatform()
7359 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7360 && imsManager.isVtEnabledByUser();
7361 } finally {
7362 Binder.restoreCallingIdentity(identity);
7363 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007364 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007365
Andrew Leea1239f22015-03-02 17:44:07 -08007366 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007367 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7368 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007370 mApp, subId, callingPackage, callingFeatureId,
7371 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 return false;
7373 }
7374
7375 final long identity = Binder.clearCallingIdentity();
7376 try {
7377 CarrierConfigManager configManager =
7378 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007379 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
7383 }
Andrew Leea1239f22015-03-02 17:44:07 -08007384 }
7385
7386 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007387 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007389 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 return false;
7391 }
7392
7393 final long identity = Binder.clearCallingIdentity();
7394 try {
7395 CarrierConfigManager configManager =
7396 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007397 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7399 } finally {
7400 Binder.restoreCallingIdentity(identity);
7401 }
Andrew Leea1239f22015-03-02 17:44:07 -08007402 }
7403
Andrew Lee9431b832015-03-09 18:46:45 -07007404 @Override
7405 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007406 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007407 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007408 }
7409
7410 @Override
7411 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007412 final long identity = Binder.clearCallingIdentity();
7413 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007414 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
Andrew Lee9431b832015-03-09 18:46:45 -07007418 }
7419
Hall Liuf6668912018-10-31 17:05:23 -07007420 /**
7421 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7422 * support for the feature and device firmware support.
7423 *
7424 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7425 */
7426 @Override
7427 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007429 final Phone phone = getPhone(subscriptionId);
7430 if (phone == null) {
7431 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7432 return false;
7433 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007435 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7437 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007438 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 return isCarrierSupported && isDeviceSupported;
7440 } finally {
7441 Binder.restoreCallingIdentity(identity);
7442 }
Hall Liu98187582018-01-22 19:15:32 -08007443 }
7444
Hall Liuf6668912018-10-31 17:05:23 -07007445 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007446 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7447 * RTT setting, will return true if the device and carrier both support RTT.
7448 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007449 */
7450 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 final long identity = Binder.clearCallingIdentity();
7452 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007453 boolean isRttSupported = isRttSupported(subscriptionId);
7454 boolean isUserRttSettingOn = Settings.Secure.getInt(
7455 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7456 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7457 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7458 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 } finally {
7460 Binder.restoreCallingIdentity(identity);
7461 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007462 }
7463
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007464 @Deprecated
7465 @Override
7466 public String getDeviceId(String callingPackage) {
7467 return getDeviceIdWithFeature(callingPackage, null);
7468 }
7469
Sanket Padawe7310cc72015-01-14 09:53:20 -08007470 /**
7471 * Returns the unique device ID of phone, for example, the IMEI for
7472 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7473 *
7474 * <p>Requires Permission:
7475 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7476 */
7477 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007479 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007480 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007481 return null;
7482 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007483 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007484 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007485 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007486 return null;
7487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488
7489 final long identity = Binder.clearCallingIdentity();
7490 try {
7491 return phone.getDeviceId();
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007495 }
7496
Ping Sunc67b7c22016-03-02 19:16:45 +08007497 /**
7498 * {@hide}
7499 * Returns the IMS Registration Status on a particular subid
7500 *
7501 * @param subId
7502 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007503 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007504 Phone phone = getPhone(subId);
7505 if (phone != null) {
7506 return phone.isImsRegistered();
7507 } else {
7508 return false;
7509 }
7510 }
7511
Santos Cordon7a1885b2015-02-03 11:15:19 -08007512 @Override
7513 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514 final long identity = Binder.clearCallingIdentity();
7515 try {
7516 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7517 } finally {
7518 Binder.restoreCallingIdentity(identity);
7519 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007520 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007521
Tyler Gunnf70ed162019-04-03 15:28:53 -07007522 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007523 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007524 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007527 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7528 }
7529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
7535 }
7536
7537 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007538 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007539 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007540 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007541 mApp,
7542 subscriptionId,
7543 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 Phone phone = getPhone(subscriptionId);
7547 if (phone == null) {
7548 return null;
7549 }
7550 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
7554 }
7555
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007556 /**
7557 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007558 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007559 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 final long identity = Binder.clearCallingIdentity();
7561 try {
7562 Phone phone = getPhone(subId);
7563 if (phone != null) {
7564 return phone.isWifiCallingEnabled();
7565 } else {
7566 return false;
7567 }
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007570 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007571 }
7572
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007573 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007574 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007575 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007576 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 Phone phone = getPhone(subId);
7580 if (phone != null) {
7581 return phone.isVideoEnabled();
7582 } else {
7583 return false;
7584 }
7585 } finally {
7586 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007587 }
7588 }
7589
7590 /**
7591 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7592 * defined in {@link ImsRegistrationImplBase}.
7593 */
7594 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 Phone phone = getPhone(subId);
7598 if (phone != null) {
7599 return phone.getImsRegistrationTech();
7600 } else {
7601 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7602 }
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007605 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007606 }
7607
Stuart Scott8eef64f2015-04-08 15:13:54 -07007608 @Override
7609 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007610 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007611 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7612 return;
7613 }
Kai Shif70f46f2021-03-03 13:59:46 -08007614 Phone defaultPhone = getDefaultPhone();
7615 if (defaultPhone != null) {
7616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7617 mApp, getDefaultPhone().getSubId(), "factoryReset");
7618 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007619 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007620
Svet Ganovcc087f82015-05-12 20:35:54 -07007621 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007622 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7623 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007624 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007625 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007626 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007627 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007628 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007629 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007630 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007631 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007632 // There has been issues when Sms raw table somehow stores orphan
7633 // fragments. They lead to garbled message when new fragments come
7634 // in and combined with those stale ones. In case this happens again,
7635 // user can reset all network settings which will clean up this table.
7636 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007637 // Clean up IMS settings as well here.
7638 int slotId = getSlotIndex(subId);
7639 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7640 ImsManager.getInstance(mApp, slotId).factoryReset();
7641 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007642
Kai Shif70f46f2021-03-03 13:59:46 -08007643 if (defaultPhone == null) {
7644 return;
7645 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007646 // Erase modem config if erase modem on network setting is enabled.
7647 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7648 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7649 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007650 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007651 }
Kai Shif70f46f2021-03-03 13:59:46 -08007652
7653 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007654 } finally {
7655 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007656 }
7657 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007658
SongFerngWangfd89b102021-05-27 22:44:54 +08007659 @VisibleForTesting
7660 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7661 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7662 return;
7663 }
7664 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7665 RILConstants.PREFERRED_NETWORK_MODE);
7666 SubscriptionManager.setSubscriptionProperty(subId,
7667 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7668 "user=" + defaultNetworkType);
7669 phone.loadAllowedNetworksFromSubscriptionDatabase();
7670 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7671 defaultNetworkType, null);
7672 }
7673
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007674 private void cleanUpSmsRawTable(Context context) {
7675 ContentResolver resolver = context.getContentResolver();
7676 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7677 resolver.delete(uri, null, null);
7678 }
7679
Narayan Kamath1c496c22015-04-16 14:40:19 +01007680 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007681 public String getSimLocaleForSubscriber(int subId) {
7682 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7683 final Phone phone = getPhone(subId);
7684 if (phone == null) {
7685 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007686 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 final long identity = Binder.clearCallingIdentity();
7689 try {
chen xu5d3637b2019-01-21 23:31:38 -08007690 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007691 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007692 if (info == null) {
7693 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7694 return null;
7695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696 // Try and fetch the locale from the carrier properties or from the SIM language
7697 // preferences (EF-PL and EF-LI)...
7698 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007700 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7701 if (localeFromDefaultSim != null) {
7702 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7703 if (DBG) log("Using locale from subId: " + subId + " locale: "
7704 + localeFromDefaultSim);
7705 return localeFromDefaultSim.toLanguageTag();
7706 } else {
7707 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 }
7709 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 // The SIM language preferences only store a language (e.g. fr = French), not an
7712 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7713 // the SIM and carrier preferences does not include a country we add the country
7714 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007715 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007717 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718 return mccLocale.toLanguageTag();
7719 }
7720
7721 if (DBG) log("No locale found - returning null");
7722 return null;
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007726 }
7727
7728 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007729 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007730 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007731 }
7732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733 /**
7734 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7735 */
7736 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007737 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007738 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007739 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007740
Chenjie Yu1ba97252018-01-11 18:16:20 -08007741 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007742 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007743
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007744 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007745 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7746 * representing the state of the modem.
7747 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007748 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7749 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007750 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007751 */
7752 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007753 public void requestModemActivityInfo(ResultReceiver result) {
7754 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007755 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007759 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 } finally {
7761 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007762 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007763 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007764
Siddharth Rayb8114062018-06-17 15:02:38 -07007765 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7766 // less than total activity duration.
7767 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7768 if (info == null) {
7769 return false;
7770 }
7771 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007772 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7773 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7774
Siddharth Rayb8114062018-06-17 15:02:38 -07007775 return (info.isValid()
7776 && (info.getSleepTimeMillis() <= activityDurationMs)
7777 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007778 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007779 && (totalTxTimeMs <= activityDurationMs));
7780 }
7781
Jack Yu85bd38a2015-11-09 11:34:32 -08007782 /**
7783 * {@hide}
7784 * Returns the service state information on specified subscription.
7785 */
7786 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007787 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7788 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007790 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007791 return null;
7792 }
7793
Hall Liuf19c44f2018-11-27 14:38:17 -08007794 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7795 LocationAccessPolicy.checkLocationPermission(mApp,
7796 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7797 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007798 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007799 .setCallingPid(Binder.getCallingPid())
7800 .setCallingUid(Binder.getCallingUid())
7801 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007802 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007803 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007804 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7805 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007806 .build());
7807
7808 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7809 LocationAccessPolicy.checkLocationPermission(mApp,
7810 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7811 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007812 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007813 .setCallingPid(Binder.getCallingPid())
7814 .setCallingUid(Binder.getCallingUid())
7815 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007816 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007817 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007818 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7819 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007820 .build());
7821 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7822 boolean hasFinePermission =
7823 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7824 boolean hasCoarsePermission =
7825 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7826
Jack Yu479f40e2020-10-27 21:29:25 -07007827 final Phone phone = getPhone(subId);
7828 if (phone == null) {
7829 return null;
7830 }
7831
Jordan Liu0f2bc442020-11-18 16:47:37 -08007832 final long identity = Binder.clearCallingIdentity();
7833
Jack Yu479f40e2020-10-27 21:29:25 -07007834 boolean isCallingPackageDataService = phone.getDataServicePackages()
7835 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007837 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7838 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7839 Rlog.d(LOG_TAG,
7840 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7841 return null;
7842 }
7843
Hall Liuf19c44f2018-11-27 14:38:17 -08007844 ServiceState ss = phone.getServiceState();
7845
7846 // Scrub out the location info in ServiceState depending on what level of access
7847 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007848 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007849 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7850 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 } finally {
7852 Binder.restoreCallingIdentity(identity);
7853 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007854 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007855
7856 /**
7857 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7858 *
7859 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7860 * voicemail ringtone.
7861 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7862 * PhoneAccount.
7863 */
7864 @Override
7865 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 final long identity = Binder.clearCallingIdentity();
7867 try {
7868 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7869 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007870 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007872
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
7876 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007877 }
7878
7879 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007880 * Sets the per-account voicemail ringtone.
7881 *
7882 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7883 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7884 *
7885 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7886 * voicemail ringtone.
7887 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7888 * PhoneAccount.
7889 */
7890 @Override
7891 public void setVoicemailRingtoneUri(String callingPackage,
7892 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007893 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007894 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007895 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7896 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7898 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7899 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901
7902 final long identity = Binder.clearCallingIdentity();
7903 try {
7904 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7905 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007906 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 }
7908 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7909 } finally {
7910 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007911 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007912 }
7913
7914 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007915 * Returns whether vibration is set for voicemail notification in Phone settings.
7916 *
7917 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7918 * voicemail vibration setting.
7919 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7920 */
7921 @Override
7922 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923 final long identity = Binder.clearCallingIdentity();
7924 try {
7925 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7926 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007927 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007928 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7931 } finally {
7932 Binder.restoreCallingIdentity(identity);
7933 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007934 }
7935
Youhan Wange64578a2016-05-02 15:32:42 -07007936 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007937 * Sets the per-account voicemail vibration.
7938 *
7939 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7940 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7941 *
7942 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7943 * voicemail vibration setting.
7944 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7945 * specific PhoneAccount.
7946 */
7947 @Override
7948 public void setVoicemailVibrationEnabled(String callingPackage,
7949 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007950 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007952 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7953 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7955 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7956 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007957 }
7958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 final long identity = Binder.clearCallingIdentity();
7960 try {
7961 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7962 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007963 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964 }
7965 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7966 } finally {
7967 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007968 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007969 }
7970
7971 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007972 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7973 *
7974 * @throws SecurityException if the caller does not have the required permission
7975 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007976 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007977 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007978 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007979 }
7980
7981 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007982 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7983 * permission.
7984 *
7985 * @throws SecurityException if the caller does not have the required permission
7986 */
7987 private void enforceSendSmsPermission() {
7988 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7989 }
7990
7991 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007992 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007993 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007994 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007995 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007996 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 final long identity = Binder.clearCallingIdentity();
7998 try {
7999 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 if (componentName == null) {
8002 throw new SecurityException(
8003 "Caller not current active visual voicemail package[null]");
8004 }
8005 String vvmPackage = componentName.getPackageName();
8006 if (!callingPackage.equals(vvmPackage)) {
8007 throw new SecurityException("Caller not current active visual voicemail package["
8008 + vvmPackage + "]");
8009 }
8010 } finally {
8011 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008012 }
8013 }
8014
8015 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008016 * Return the application ID for the app type.
8017 *
8018 * @param subId the subscription ID that this request applies to.
8019 * @param appType the uicc app type.
8020 * @return Application ID for specificied app type, or null if no uicc.
8021 */
8022 @Override
8023 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008024 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008025 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026
8027 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008028 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029 if (phone == null) {
8030 return null;
8031 }
8032 String aid = null;
8033 try {
8034 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8035 .getApplicationByType(appType).getAid();
8036 } catch (Exception e) {
8037 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8038 }
8039 return aid;
8040 } finally {
8041 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008042 }
Youhan Wange64578a2016-05-02 15:32:42 -07008043 }
8044
Youhan Wang4001d252016-05-11 10:29:41 -07008045 /**
8046 * Return the Electronic Serial Number.
8047 *
8048 * @param subId the subscription ID that this request applies to.
8049 * @return ESN or null if error.
8050 */
8051 @Override
8052 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008053 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008054 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055
8056 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008057 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 if (phone == null) {
8059 return null;
8060 }
8061 String esn = null;
8062 try {
8063 esn = phone.getEsn();
8064 } catch (Exception e) {
8065 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8066 }
8067 return esn;
8068 } finally {
8069 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008070 }
Youhan Wang4001d252016-05-11 10:29:41 -07008071 }
8072
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008073 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008074 * Return the Preferred Roaming List Version.
8075 *
8076 * @param subId the subscription ID that this request applies to.
8077 * @return PRLVersion or null if error.
8078 */
8079 @Override
8080 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008081 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008082 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083
8084 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008085 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 if (phone == null) {
8087 return null;
8088 }
8089 String cdmaPrlVersion = null;
8090 try {
8091 cdmaPrlVersion = phone.getCdmaPrlVersion();
8092 } catch (Exception e) {
8093 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8094 }
8095 return cdmaPrlVersion;
8096 } finally {
8097 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008098 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008099 }
8100
8101 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008102 * Get snapshot of Telephony histograms
8103 * @return List of Telephony histograms
8104 * @hide
8105 */
8106 @Override
8107 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8109 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110
8111 final long identity = Binder.clearCallingIdentity();
8112 try {
8113 return RIL.getTelephonyRILTimingHistograms();
8114 } finally {
8115 Binder.restoreCallingIdentity(identity);
8116 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008117 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008118
8119 /**
8120 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008121 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8122 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008123 * Require system privileges. In the future we may add this to carrier APIs.
8124 *
Michele Berionne482f8202018-11-27 18:57:59 -08008125 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008126 */
8127 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008128 @TelephonyManager.SetCarrierRestrictionResult
8129 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008130 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008131 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008132
Michele Berionne482f8202018-11-27 18:57:59 -08008133 if (carrierRestrictionRules == null) {
8134 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008135 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008137 final long identity = Binder.clearCallingIdentity();
8138 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008139 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008140 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141 } finally {
8142 Binder.restoreCallingIdentity(identity);
8143 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008144 }
8145
8146 /**
8147 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008148 * Get the allowed carrier list and the excluded carrier list, including the priority between
8149 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008150 * Require system privileges. In the future we may add this to carrier APIs.
8151 *
Michele Berionne482f8202018-11-27 18:57:59 -08008152 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008153 */
8154 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008155 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008156 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008157 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158
8159 final long identity = Binder.clearCallingIdentity();
8160 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008161 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8162 if (response instanceof CarrierRestrictionRules) {
8163 return (CarrierRestrictionRules) response;
8164 }
8165 // Response is an Exception of some kind,
8166 // which is signalled to the user as a NULL retval
8167 return null;
8168 } catch (Exception e) {
8169 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8170 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008171 } finally {
8172 Binder.restoreCallingIdentity(identity);
8173 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008174 }
8175
fionaxu59545b42016-05-25 15:53:37 -07008176 /**
fionaxu59545b42016-05-25 15:53:37 -07008177 * Action set from carrier signalling broadcast receivers to enable/disable radio
8178 * @param subId the subscription ID that this action applies to.
8179 * @param enabled control enable or disable radio.
8180 * {@hide}
8181 */
8182 @Override
8183 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8184 enforceModifyPermission();
8185 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186
8187 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008188 if (phone == null) {
8189 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8190 return;
8191 }
8192 try {
8193 phone.carrierActionSetRadioEnabled(enabled);
8194 } catch (Exception e) {
8195 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 } finally {
8197 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008198 }
8199 }
8200
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008201 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008202 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8203 * network status based on which carrier apps could apply actions accordingly,
8204 * enable/disable default url handler for example.
8205 *
8206 * @param subId the subscription ID that this action applies to.
8207 * @param report control start/stop reporting the default network status.
8208 * {@hide}
8209 */
8210 @Override
8211 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8212 enforceModifyPermission();
8213 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214
8215 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008216 if (phone == null) {
8217 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8218 return;
8219 }
8220 try {
8221 phone.carrierActionReportDefaultNetworkStatus(report);
8222 } catch (Exception e) {
8223 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 } finally {
8225 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008226 }
8227 }
8228
8229 /**
fionaxud9622282017-07-17 17:51:30 -07008230 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8231 * @param subId the subscription ID that this action applies to.
8232 * {@hide}
8233 */
8234 @Override
8235 public void carrierActionResetAll(int subId) {
8236 enforceModifyPermission();
8237 final Phone phone = getPhone(subId);
8238 if (phone == null) {
8239 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8240 return;
8241 }
8242 try {
8243 phone.carrierActionResetAll();
8244 } catch (Exception e) {
8245 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8246 }
8247 }
8248
8249 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008250 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8251 * bug report is being generated.
8252 */
8253 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008254 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008255 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8256 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008257 writer.println("Permission Denial: can't dump Phone from pid="
8258 + Binder.getCallingPid()
8259 + ", uid=" + Binder.getCallingUid()
8260 + "without permission "
8261 + android.Manifest.permission.DUMP);
8262 return;
8263 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008264 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008265 }
Jack Yueb89b242016-06-22 13:27:47 -07008266
Brad Ebingerdac2f002018-04-03 15:17:52 -07008267 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008268 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8269 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8270 @NonNull String[] args) {
8271 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8272 this, in.getFileDescriptor(), out.getFileDescriptor(),
8273 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008274 }
8275
Jack Yueb89b242016-06-22 13:27:47 -07008276 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008277 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008278 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008279 * @param reason the reason the data enable change is taking place
8280 * @param enabled True if enabling the data, otherwise disabling.
8281 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008282 */
8283 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008284 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008285 boolean enabled) {
8286 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8287 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8288 try {
8289 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008290 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008291 } catch (SecurityException se) {
8292 enforceModifyPermission();
8293 }
8294 } else {
8295 enforceModifyPermission();
8296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 Phone phone = getPhone(subId);
8301 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008302 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8303 phone.carrierActionSetMeteredApnsEnabled(enabled);
8304 } else {
8305 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 }
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008310 }
8311 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008312
8313 /**
8314 * Get Client request stats
8315 * @return List of Client Request Stats
8316 * @hide
8317 */
8318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008319 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8320 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008322 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008323 return null;
8324 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008325 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 final long identity = Binder.clearCallingIdentity();
8328 try {
8329 if (phone != null) {
8330 return phone.getClientRequestStats();
8331 }
8332
8333 return null;
8334 } finally {
8335 Binder.restoreCallingIdentity(identity);
8336 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008337 }
8338
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008339 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008340 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008341 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008342 }
Jack Yueb4124c2017-02-16 15:32:43 -08008343
8344 /**
Grace Chen70990072017-03-24 17:21:30 -07008345 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008346 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008347 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008348 * @param state State of SIM (power down, power up, pass through)
8349 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8350 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8351 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008352 *
8353 **/
8354 @Override
Grace Chen70990072017-03-24 17:21:30 -07008355 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008356 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008357 Phone phone = PhoneFactory.getPhone(slotIndex);
8358
vagdeviaf9a5b92018-08-15 16:01:53 -07008359 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361 final long identity = Binder.clearCallingIdentity();
8362 try {
8363 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008364 phone.setSimPowerState(state, null, workSource);
8365 }
8366 } finally {
8367 Binder.restoreCallingIdentity(identity);
8368 }
8369 }
8370
8371 /**
8372 * Set SIM card power state.
8373 *
8374 * @param slotIndex SIM slot id.
8375 * @param state State of SIM (power down, power up, pass through)
8376 * @param callback callback to trigger after success or failure
8377 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8378 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8379 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8380 *
8381 **/
8382 @Override
8383 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8384 IIntegerConsumer callback) {
8385 enforceModifyPermission();
8386 Phone phone = PhoneFactory.getPhone(slotIndex);
8387
8388 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8389
8390 final long identity = Binder.clearCallingIdentity();
8391 try {
8392 if (phone != null) {
8393 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8394 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 }
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008398 }
8399 }
Shuo Qiandd210312017-04-12 22:11:33 +00008400
Tyler Gunn65d45c22017-06-05 11:22:26 -07008401 private boolean isUssdApiAllowed(int subId) {
8402 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008403 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008404 if (configManager == null) {
8405 return false;
8406 }
8407 PersistableBundle pb = configManager.getConfigForSubId(subId);
8408 if (pb == null) {
8409 return false;
8410 }
8411 return pb.getBoolean(
8412 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8413 }
8414
Shuo Qiandd210312017-04-12 22:11:33 +00008415 /**
8416 * Check if phone is in emergency callback mode
8417 * @return true if phone is in emergency callback mode
8418 * @param subId sub id
8419 */
goneil9c5f4872017-12-05 14:07:56 -08008420 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008421 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008422 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008423 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008424
8425 final long identity = Binder.clearCallingIdentity();
8426 try {
8427 if (phone != null) {
8428 return phone.isInEcm();
8429 } else {
8430 return false;
8431 }
8432 } finally {
8433 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008434 }
8435 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008436
8437 /**
8438 * Get the current signal strength information for the given subscription.
8439 * Because this information is not updated when the device is in a low power state
8440 * it should not be relied-upon to be current.
8441 * @param subId Subscription index
8442 * @return the most recent cached signal strength info from the modem
8443 */
8444 @Override
8445 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 Phone p = getPhone(subId);
8449 if (p == null) {
8450 return null;
8451 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008453 return p.getSignalStrength();
8454 } finally {
8455 Binder.restoreCallingIdentity(identity);
8456 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008457 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008458
Pengquan Meng77b7f132018-08-22 14:49:57 -07008459 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008460 * Get the current modem radio state for the given slot.
8461 * @param slotIndex slot index.
8462 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008463 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008464 * @return the current radio power state from the modem
8465 */
8466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008467 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008468 Phone phone = PhoneFactory.getPhone(slotIndex);
8469 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8471 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008472 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8473 }
8474
8475 final long identity = Binder.clearCallingIdentity();
8476 try {
8477 return phone.getRadioPowerState();
8478 } finally {
8479 Binder.restoreCallingIdentity(identity);
8480 }
8481 }
8482 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8483 }
8484
8485 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008486 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8487 *
8488 * <p>Requires one of the following permissions:
8489 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8490 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8491 * privileges.
8492 *
8493 * @param subId subscription id
8494 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8495 * {@code false}.
8496 */
8497 @Override
8498 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008499 try {
8500 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8501 null);
8502 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008503 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008504 mApp, subId, "isDataRoamingEnabled");
8505 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008506
Pengquan Menga1bb6272018-09-06 09:59:22 -07008507 boolean isEnabled = false;
8508 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008509 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008510 Phone phone = getPhone(subId);
8511 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008512 } finally {
8513 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008514 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008515 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008516 }
8517
8518
8519 /**
8520 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8521 *
8522 * <p> Requires permission:
8523 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8524 * privileges.
8525 *
8526 * @param subId subscription id
8527 * @param isEnabled {@code true} means enable, {@code false} means disable.
8528 */
8529 @Override
8530 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8532 mApp, subId, "setDataRoamingEnabled");
8533
Pengquan Menga1bb6272018-09-06 09:59:22 -07008534 final long identity = Binder.clearCallingIdentity();
8535 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008536 Phone phone = getPhone(subId);
8537 if (phone != null) {
8538 phone.setDataRoamingEnabled(isEnabled);
8539 }
8540 } finally {
8541 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008542 }
8543 }
8544
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008545 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008546 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008547 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008548 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008549 mApp, subId, "isManualNetworkSelectionAllowed");
8550
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008551 boolean isAllowed = true;
8552 final long identity = Binder.clearCallingIdentity();
8553 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008554 Phone phone = getPhone(subId);
8555 if (phone != null) {
8556 isAllowed = phone.isCspPlmnEnabled();
8557 }
8558 } finally {
8559 Binder.restoreCallingIdentity(identity);
8560 }
8561 return isAllowed;
8562 }
8563
8564 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008565 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008566 // Verify that tha callingPackage belongs to the calling UID
8567 mApp.getSystemService(AppOpsManager.class)
8568 .checkPackage(Binder.getCallingUid(), callingPackage);
8569
Jordan Liu1e142fc2019-04-22 15:10:43 -07008570 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008571 try {
8572 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008573 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008574 } catch (SecurityException e) {
8575 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8576 // has carrier privileges on an active UICC
8577 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8578 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008579 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008580 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008581 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008582
8583 final long identity = Binder.clearCallingIdentity();
8584 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008585 UiccController uiccController = UiccController.getInstance();
8586 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008587 if (hasReadPermission) {
8588 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008589 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008590
8591 // Remove private info if the caller doesn't have access
8592 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8593 for (UiccCardInfo cardInfo : cardInfos) {
8594 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8595 // is available
8596 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8597 if (card == null || card.getUiccProfile() == null) {
8598 // assume no access if the card or profile is unavailable
8599 filteredInfos.add(cardInfo.getUnprivileged());
8600 continue;
8601 }
8602 UiccProfile profile = card.getUiccProfile();
8603 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8604 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8605 filteredInfos.add(cardInfo);
8606 } else {
8607 filteredInfos.add(cardInfo.getUnprivileged());
8608 }
8609 }
8610 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
8614 }
8615
8616 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008617 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008618 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008620 final long identity = Binder.clearCallingIdentity();
8621 try {
8622 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8623 if (slots == null) {
8624 Rlog.i(LOG_TAG, "slots is null.");
8625 return null;
8626 }
8627
8628 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8629 for (int i = 0; i < slots.length; i++) {
8630 UiccSlot slot = slots[i];
8631 if (slot == null) {
8632 continue;
8633 }
8634
Jordan Liu7be7e652019-05-06 18:55:02 +00008635 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008636 UiccCard card = slot.getUiccCard();
8637 if (card != null) {
8638 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008639 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008640 cardId = slot.getEid();
8641 if (TextUtils.isEmpty(cardId)) {
8642 cardId = slot.getIccId();
8643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008644 }
8645
Jordan Liu857451f2019-05-09 16:35:35 -07008646 if (cardId != null) {
8647 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8648 // if cardId is an EID, it's all digits so this is fine
8649 cardId = IccUtils.stripTrailingFs(cardId);
8650 }
8651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008652 int cardState = 0;
8653 switch (slot.getCardState()) {
8654 case CARDSTATE_ABSENT:
8655 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8656 break;
8657 case CARDSTATE_PRESENT:
8658 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8659 break;
8660 case CARDSTATE_ERROR:
8661 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8662 break;
8663 case CARDSTATE_RESTRICTED:
8664 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8665 break;
8666 default:
8667 break;
8668
8669 }
8670
8671 infos[i] = new UiccSlotInfo(
8672 slot.isActive(),
8673 slot.isEuicc(),
8674 cardId,
8675 cardState,
8676 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008677 slot.isExtendedApduSupported(),
8678 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008679 }
8680 return infos;
8681 } finally {
8682 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008683 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008684 }
8685
8686 @Override
8687 public boolean switchSlots(int[] physicalSlots) {
8688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008689
8690 final long identity = Binder.clearCallingIdentity();
8691 try {
8692 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8693 } finally {
8694 Binder.restoreCallingIdentity(identity);
8695 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008696 }
Jack Yu4c988042018-02-27 15:30:01 -08008697
8698 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008699 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008700 final long identity = Binder.clearCallingIdentity();
8701 try {
8702 return UiccController.getInstance().getCardIdForDefaultEuicc();
8703 } finally {
8704 Binder.restoreCallingIdentity(identity);
8705 }
8706 }
8707
Pengquan Meng85728fb2018-03-12 16:31:21 -07008708 /**
goneil47ffb6e2018-04-06 15:40:58 -07008709 * A test API to reload the UICC profile.
8710 *
8711 * <p>Requires that the calling app has permission
8712 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8713 * @hide
8714 */
8715 @Override
8716 public void refreshUiccProfile(int subId) {
8717 enforceModifyPermission();
8718
8719 final long identity = Binder.clearCallingIdentity();
8720 try {
8721 Phone phone = getPhone(subId);
8722 if (phone == null) {
8723 return;
8724 }
8725 UiccCard uiccCard = phone.getUiccCard();
8726 if (uiccCard == null) {
8727 return;
8728 }
8729 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8730 if (uiccProfile == null) {
8731 return;
8732 }
8733 uiccProfile.refresh();
8734 } finally {
8735 Binder.restoreCallingIdentity(identity);
8736 }
8737 }
8738
8739 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008740 * Returns false if the mobile data is disabled by default, otherwise return true.
8741 */
8742 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008743 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008744 }
8745
8746 /**
8747 * Returns true if the data roaming is enabled by default, i.e the system property
8748 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8749 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8750 */
8751 private boolean getDefaultDataRoamingEnabled(int subId) {
8752 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008753 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008754 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008755 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8756 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8757 return isDataRoamingEnabled;
8758 }
8759
8760 /**
8761 * Returns the default network type for the given {@code subId}, if the default network type is
8762 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8763 */
8764 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008765 List<Integer> list = TelephonyProperties.default_network();
8766 int phoneId = mSubscriptionController.getPhoneId(subId);
8767 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8768 return list.get(phoneId);
8769 }
8770 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008771 }
fionaxua13278b2018-03-21 00:08:13 -07008772
8773 @Override
8774 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008775 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008777
8778 final long identity = Binder.clearCallingIdentity();
8779 try {
8780 final Phone phone = getPhone(subId);
8781 if (phone == null) {
8782 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8783 return;
8784 }
chen xueaba88a2019-03-15 13:15:10 -07008785 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8786 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008787 if (carrierPrivilegeRules == null) {
8788 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8789 } else {
8790 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008792 } finally {
8793 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008794 }
fionaxua13278b2018-03-21 00:08:13 -07008795 }
8796
8797 @Override
8798 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008799 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008800
8801 final long identity = Binder.clearCallingIdentity();
8802 try {
8803 final Phone phone = getPhone(subId);
8804 if (phone == null) {
8805 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8806 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8807 }
8808 return phone.getCarrierIdListVersion();
8809 } finally {
8810 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008811 }
fionaxua13278b2018-03-21 00:08:13 -07008812 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008813
8814 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008815 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8816 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008817 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008818 mApp, subId, callingPackage, callingFeatureId,
8819 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008820 return -1;
8821 }
8822
8823 final long identity = Binder.clearCallingIdentity();
8824 try {
8825 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8826 } finally {
8827 Binder.restoreCallingIdentity(identity);
8828 }
8829 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008830
8831 @Override
8832 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008833 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008834 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008835 mApp, subId, "getCdmaRoamingMode");
8836
8837 final long identity = Binder.clearCallingIdentity();
8838 try {
8839 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8840 } finally {
8841 Binder.restoreCallingIdentity(identity);
8842 }
8843 }
8844
8845 @Override
8846 public boolean setCdmaRoamingMode(int subId, int mode) {
8847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8848 mApp, subId, "setCdmaRoamingMode");
8849
8850 final long identity = Binder.clearCallingIdentity();
8851 try {
8852 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8853 } finally {
8854 Binder.restoreCallingIdentity(identity);
8855 }
8856 }
8857
8858 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008859 public int getCdmaSubscriptionMode(int subId) {
8860 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008861 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008862 mApp, subId, "getCdmaSubscriptionMode");
8863
8864 final long identity = Binder.clearCallingIdentity();
8865 try {
8866 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8867 } finally {
8868 Binder.restoreCallingIdentity(identity);
8869 }
8870 }
8871
8872 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008873 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8875 mApp, subId, "setCdmaSubscriptionMode");
8876
8877 final long identity = Binder.clearCallingIdentity();
8878 try {
8879 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8880 } finally {
8881 Binder.restoreCallingIdentity(identity);
8882 }
8883 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008884
sqianc5eccab2018-10-19 18:46:41 -07008885 @Override
sqian8c685422019-02-22 15:55:18 -08008886 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008887 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008889 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8890 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008891 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8892 }
8893 final long identity = Binder.clearCallingIdentity();
8894 try {
sqian854d44b2018-12-12 16:48:18 -08008895 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8896 for (Phone phone: PhoneFactory.getPhones()) {
8897 if (phone.getEmergencyNumberTracker() != null
8898 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8899 emergencyNumberListInternal.put(
8900 phone.getSubId(),
8901 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8902 }
sqian11b7a0e2018-12-05 18:48:28 -08008903 }
sqian854d44b2018-12-12 16:48:18 -08008904 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008905 } finally {
8906 Binder.restoreCallingIdentity(identity);
8907 }
sqianc5eccab2018-10-19 18:46:41 -07008908 }
8909
8910 @Override
sqian8c685422019-02-22 15:55:18 -08008911 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008912 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008913 if (!exactMatch) {
8914 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008915 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008916 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008917 }
8918 final long identity = Binder.clearCallingIdentity();
8919 try {
sqian854d44b2018-12-12 16:48:18 -08008920 for (Phone phone: PhoneFactory.getPhones()) {
8921 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008922 && phone.getEmergencyNumberTracker()
8923 .isEmergencyNumber(number, exactMatch)) {
8924 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008925 }
sqian11b7a0e2018-12-05 18:48:28 -08008926 }
8927 return false;
8928 } finally {
8929 Binder.restoreCallingIdentity(identity);
8930 }
8931 }
8932
sqianf4ca7ed2019-01-15 18:32:07 -08008933 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008934 * Start emergency callback mode for GsmCdmaPhone for testing.
8935 */
8936 @Override
8937 public void startEmergencyCallbackMode() {
8938 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8939 "startEmergencyCallbackMode");
8940 enforceModifyPermission();
8941 final long identity = Binder.clearCallingIdentity();
8942 try {
8943 for (Phone phone : PhoneFactory.getPhones()) {
8944 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8945 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8946 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8947 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8948 gsmCdmaPhone.obtainMessage(
8949 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8950 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8951 }
8952 }
8953 } finally {
8954 Binder.restoreCallingIdentity(identity);
8955 }
8956 }
8957
8958 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008959 * Update emergency number list for test mode.
8960 */
8961 @Override
8962 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8964 "updateEmergencyNumberListTestMode");
8965
8966 final long identity = Binder.clearCallingIdentity();
8967 try {
8968 for (Phone phone: PhoneFactory.getPhones()) {
8969 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8970 if (tracker != null) {
8971 tracker.executeEmergencyNumberTestModeCommand(action, num);
8972 }
8973 }
8974 } finally {
8975 Binder.restoreCallingIdentity(identity);
8976 }
8977 }
8978
8979 /**
8980 * Get the full emergency number list for test mode.
8981 */
8982 @Override
8983 public List<String> getEmergencyNumberListTestMode() {
8984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8985 "getEmergencyNumberListTestMode");
8986
8987 final long identity = Binder.clearCallingIdentity();
8988 try {
8989 Set<String> emergencyNumbers = new HashSet<>();
8990 for (Phone phone: PhoneFactory.getPhones()) {
8991 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8992 if (tracker != null) {
8993 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8994 emergencyNumbers.add(num.getNumber());
8995 }
8996 }
8997 }
8998 return new ArrayList<>(emergencyNumbers);
8999 } finally {
9000 Binder.restoreCallingIdentity(identity);
9001 }
9002 }
9003
chen xud6b45bd2018-10-30 22:27:10 -07009004 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009005 public int getEmergencyNumberDbVersion(int subId) {
9006 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9007
9008 final long identity = Binder.clearCallingIdentity();
9009 try {
9010 final Phone phone = getPhone(subId);
9011 if (phone == null) {
9012 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9013 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9014 }
9015 return phone.getEmergencyNumberDbVersion();
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
9018 }
9019 }
9020
9021 @Override
9022 public void notifyOtaEmergencyNumberDbInstalled() {
9023 enforceModifyPermission();
9024
9025 final long identity = Binder.clearCallingIdentity();
9026 try {
9027 for (Phone phone: PhoneFactory.getPhones()) {
9028 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9029 if (tracker != null) {
9030 tracker.updateOtaEmergencyNumberDatabase();
9031 }
9032 }
9033 } finally {
9034 Binder.restoreCallingIdentity(identity);
9035 }
9036 }
9037
9038 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009039 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009040 enforceActiveEmergencySessionPermission();
9041
9042 final long identity = Binder.clearCallingIdentity();
9043 try {
9044 for (Phone phone: PhoneFactory.getPhones()) {
9045 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9046 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009047 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9048 }
9049 }
9050 } finally {
9051 Binder.restoreCallingIdentity(identity);
9052 }
9053 }
9054
9055 @Override
9056 public void resetOtaEmergencyNumberDbFilePath() {
9057 enforceActiveEmergencySessionPermission();
9058
9059 final long identity = Binder.clearCallingIdentity();
9060 try {
9061 for (Phone phone: PhoneFactory.getPhones()) {
9062 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9063 if (tracker != null) {
9064 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009065 }
9066 }
9067 } finally {
9068 Binder.restoreCallingIdentity(identity);
9069 }
9070 }
9071
9072 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009073 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9074 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9075 Phone phone = getPhone(subId);
9076 if (phone == null) {
9077 return null;
9078 }
9079 final long identity = Binder.clearCallingIdentity();
9080 try {
9081 UiccProfile profile = UiccController.getInstance()
9082 .getUiccProfileForPhone(phone.getPhoneId());
9083 if (profile != null) {
9084 return profile.getCertsFromCarrierPrivilegeAccessRules();
9085 }
9086 } finally {
9087 Binder.restoreCallingIdentity(identity);
9088 }
9089 return null;
9090 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009091
9092 /**
9093 * Enable or disable a modem stack.
9094 */
9095 @Override
9096 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9097 enforceModifyPermission();
9098
9099 final long identity = Binder.clearCallingIdentity();
9100 try {
9101 Phone phone = PhoneFactory.getPhone(slotIndex);
9102 if (phone == null) {
9103 return false;
9104 } else {
9105 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9106 }
9107 } finally {
9108 Binder.restoreCallingIdentity(identity);
9109 }
9110 }
Michelecea4cf22018-12-21 15:00:11 -08009111
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009112 /**
9113 * Whether a modem stack is enabled or not.
9114 */
9115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009116 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9117 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009118 Phone phone = PhoneFactory.getPhone(slotIndex);
9119 if (phone == null) return false;
9120
9121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009122 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9123 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009124 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9125 }
9126
9127 final long identity = Binder.clearCallingIdentity();
9128 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009129 try {
9130 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9131 } catch (NoSuchElementException ex) {
9132 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9133 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009134 } finally {
9135 Binder.restoreCallingIdentity(identity);
9136 }
9137 }
9138
Michelecea4cf22018-12-21 15:00:11 -08009139 @Override
Michele0ea7d782019-03-19 14:58:42 -07009140 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009141 enforceModifyPermission();
9142
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009146 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009147 .commit();
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
9152
9153 @Override
Michele0ea7d782019-03-19 14:58:42 -07009154 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009155 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009157 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9158 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009159 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009160 }
Michelecea4cf22018-12-21 15:00:11 -08009161
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
Michele0ea7d782019-03-19 14:58:42 -07009164 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
9168 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009169
Michele0ea7d782019-03-19 14:58:42 -07009170 @TelephonyManager.IsMultiSimSupportedResult
9171 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009172 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9173 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9174 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009175 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9176 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009177 }
9178 // Check if the hardware supports multisim functionality. If usage of multisim is not
9179 // supported by the modem, indicate that it is restricted.
9180 PhoneCapability staticCapability =
9181 mPhoneConfigurationManager.getStaticPhoneCapability();
9182 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009183 loge("isMultiSimSupportedInternal: no static configuration available");
9184 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009185 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009186 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009187 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9188 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009189 }
9190 // Check if support of multiple SIMs is restricted by carrier
9191 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009192 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009193 }
9194
Michele0ea7d782019-03-19 14:58:42 -07009195 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009196 }
9197
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009198 /**
9199 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009200 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9201 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9202 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009203 * @param numOfSims number of active sims we want to switch to
9204 */
9205 @Override
9206 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009207 if (numOfSims == 1) {
9208 enforceModifyPermission();
9209 } else {
9210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9211 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9212 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009213 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009214
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009215 try {
Michele30b57b22019-03-01 12:01:14 -08009216 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009217 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009218 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9219 return;
9220 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009221 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9222 } finally {
9223 Binder.restoreCallingIdentity(identity);
9224 }
9225 }
9226
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009227 @Override
9228 public boolean isApplicationOnUicc(int subId, int appType) {
9229 enforceReadPrivilegedPermission("isApplicationOnUicc");
9230 Phone phone = getPhone(subId);
9231 if (phone == null) {
9232 return false;
9233 }
9234 final long identity = Binder.clearCallingIdentity();
9235 try {
9236 UiccCard uiccCard = phone.getUiccCard();
9237 if (uiccCard == null) {
9238 return false;
9239 }
9240 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9241 if (uiccProfile == null) {
9242 return false;
9243 }
9244 if (TelephonyManager.APPTYPE_SIM <= appType
9245 && appType <= TelephonyManager.APPTYPE_ISIM) {
9246 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9247 }
9248 return false;
9249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
9252 }
9253
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009254 /**
chen xub4baa772019-04-03 10:23:41 -07009255 * Get whether making changes to modem configurations will trigger reboot.
9256 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009257 */
9258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009259 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9260 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009262 mApp, subId, callingPackage, callingFeatureId,
9263 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009264 return false;
9265 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009266 final long identity = Binder.clearCallingIdentity();
9267 try {
9268 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9269 } finally {
9270 Binder.restoreCallingIdentity(identity);
9271 }
9272 }
9273
Nathan Harold29f5f052019-02-15 13:41:57 -08009274 private void updateModemStateMetrics() {
9275 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9276 // TODO: check the state for each modem if the api is ready.
9277 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9278 }
9279
Pengquan Meng3889a572019-01-23 11:16:29 -08009280 @Override
9281 public int[] getSlotsMapping() {
9282 enforceReadPrivilegedPermission("getSlotsMapping");
9283
9284 final long identity = Binder.clearCallingIdentity();
9285 try {
9286 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9287 // All logical slots should have a mapping to a physical slot.
9288 int[] logicalSlotsMapping = new int[phoneCount];
9289 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9290 for (int i = 0; i < slotInfos.length; i++) {
9291 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9292 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9293 }
9294 }
9295 return logicalSlotsMapping;
9296 } finally {
9297 Binder.restoreCallingIdentity(identity);
9298 }
9299 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009300
9301 /**
9302 * Get the IRadio HAL Version
9303 */
9304 @Override
9305 public int getRadioHalVersion() {
9306 Phone phone = getDefaultPhone();
9307 if (phone == null) return -1;
9308 HalVersion hv = phone.getHalVersion();
9309 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9310 return hv.major * 100 + hv.minor;
9311 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009312
9313 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009314 * Get the current calling package name.
9315 * @return the current calling package name
9316 */
9317 @Override
9318 public String getCurrentPackageName() {
9319 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9320 }
9321
9322 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009323 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9324 * corresponding network requests on a subId.
9325 *
9326 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009327 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009328 * 2) APN is un-metered for this subscription, or
9329 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009330 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009331 *
9332 * @return whether data is allowed for a apn type.
9333 *
9334 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009335 */
9336 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009337 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009338 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9339 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009340
9341 // Now that all security checks passes, perform the operation as ourselves.
9342 final long identity = Binder.clearCallingIdentity();
9343 try {
9344 Phone phone = getPhone(subId);
9345 if (phone == null) return false;
9346
Jack Yu41407ee2019-05-13 16:54:09 -07009347 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009348 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
9353
9354 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009355 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009356 enforceReadPrivilegedPermission("isApnMetered");
9357
9358 // Now that all security checks passes, perform the operation as ourselves.
9359 final long identity = Binder.clearCallingIdentity();
9360 try {
9361 Phone phone = getPhone(subId);
9362 if (phone == null) return true; // By default return true.
9363
Jack Yu41407ee2019-05-13 16:54:09 -07009364 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009365 } finally {
9366 Binder.restoreCallingIdentity(identity);
9367 }
9368 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009369
9370 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009371 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9372 int subscriptionId, IBooleanConsumer resultCallback) {
9373 enforceModifyPermission();
9374 long token = Binder.clearCallingIdentity();
9375 try {
9376 Phone phone = getPhone(subscriptionId);
9377 if (phone == null) {
9378 try {
9379 if (resultCallback != null) {
9380 resultCallback.accept(false);
9381 }
9382 } catch (RemoteException e) {
9383 // ignore
9384 }
9385 return;
9386 }
9387 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9388 Pair.create(specifiers, (x) -> {
9389 try {
9390 if (resultCallback != null) {
9391 resultCallback.accept(x);
9392 }
9393 } catch (RemoteException e) {
9394 // ignore
9395 }
9396 });
9397 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9398 } finally {
9399 Binder.restoreCallingIdentity(token);
9400 }
9401 }
9402
9403 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009404 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9405 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009406 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009407 mApp, subId, "getSystemSelectionChannels");
9408 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9409 final long identity = Binder.clearCallingIdentity();
9410 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009411 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9412 if (result instanceof IllegalStateException) {
9413 throw (IllegalStateException) result;
9414 }
9415 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009416 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9417 return specifiers;
9418 } finally {
9419 Binder.restoreCallingIdentity(identity);
9420 }
9421 }
9422
9423 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009424 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009425 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009426 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9427 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9428 if (iccRecords == null) {
9429 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9430 return false;
9431 }
9432 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9433 }
9434
9435 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009436 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9437 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009438 if (callingPackage == null) {
9439 callingPackage = getCurrentPackageName();
9440 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009441 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9442 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009443 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9444 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009445 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9446 }
9447 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9448 Intent intent = new Intent();
9449 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9450 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9451 // Bring up choose default SMS subscription dialog right now
9452 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9453 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9454 mApp.startActivity(intent);
9455 }
chen xud5ca2d52019-05-28 15:20:57 -07009456
9457 @Override
9458 public String getMmsUAProfUrl(int subId) {
9459 //TODO investigate if this API should require proper permission check in R b/133791609
9460 final long identity = Binder.clearCallingIdentity();
9461 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009462 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9463 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9464 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9465 return carrierUAProfUrl;
9466 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009467 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9468 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009469 } finally {
9470 Binder.restoreCallingIdentity(identity);
9471 }
9472 }
9473
9474 @Override
9475 public String getMmsUserAgent(int subId) {
9476 //TODO investigate if this API should require proper permission check in R b/133791609
9477 final long identity = Binder.clearCallingIdentity();
9478 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009479 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9480 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9481 if (!TextUtils.isEmpty(carrierUserAgent)) {
9482 return carrierUserAgent;
9483 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009484 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9485 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009486 } finally {
9487 Binder.restoreCallingIdentity(identity);
9488 }
9489 }
Jack Yub07d4972019-05-28 16:12:25 -07009490
9491 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009492 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9493 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009494
Jack Yub07d4972019-05-28 16:12:25 -07009495 final long identity = Binder.clearCallingIdentity();
9496 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009497 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009498 if (phone == null) return false;
9499
Hall Liua62f5da2020-09-25 10:42:19 -07009500 switch (policy) {
9501 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9502 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9503 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9504 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9505 default:
9506 throw new IllegalArgumentException(policy + " is not a valid policy");
9507 }
Jack Yub07d4972019-05-28 16:12:25 -07009508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
9512
9513 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009514 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009515 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009516 enforceModifyPermission();
9517
changbettyd5c246e2019-12-24 15:40:37 +08009518 final long identity = Binder.clearCallingIdentity();
9519 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009520 Phone phone = getPhone(subscriptionId);
9521 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009522
Hall Liua62f5da2020-09-25 10:42:19 -07009523 switch (policy) {
9524 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9525 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9526 break;
9527 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9528 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9529 break;
9530 default:
9531 throw new IllegalArgumentException(policy + " is not a valid policy");
9532 }
changbettyd5c246e2019-12-24 15:40:37 +08009533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009538 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009539 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009540 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9541 * otherwise.
9542 */
9543 @Override
9544 public void setCepEnabled(boolean isCepEnabled) {
9545 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9546
9547 final long identity = Binder.clearCallingIdentity();
9548 try {
9549 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9550 for (Phone phone : PhoneFactory.getPhones()) {
9551 Phone defaultPhone = phone.getImsPhone();
9552 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9553 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9554 ImsPhoneCallTracker imsPhoneCallTracker =
9555 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9556 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9557 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9558 + imsPhone.getMsisdn());
9559 }
9560 }
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 }
allenwtsu46dcc572020-01-08 18:24:03 +08009565
9566 /**
9567 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9568 *
9569 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9570 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9571 * before being read.
9572 */
9573 @Override
9574 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9575 isCompressed) {
9576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9577 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009578 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9579 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9580 }
9581 if (!isImsAvailableOnDevice()) {
9582 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9583 "IMS not available on device.");
9584 }
9585
9586 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009587 try {
Hui Wang761a6682020-10-31 05:12:53 +00009588 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9589 } finally {
9590 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009591 }
9592 }
zoey chene02881a2019-12-30 16:11:23 +08009593
9594 @Override
9595 public boolean isIccLockEnabled(int subId) {
9596 enforceReadPrivilegedPermission("isIccLockEnabled");
9597
9598 // Now that all security checks passes, perform the operation as ourselves.
9599 final long identity = Binder.clearCallingIdentity();
9600 try {
9601 Phone phone = getPhone(subId);
9602 if (phone != null && phone.getIccCard() != null) {
9603 return phone.getIccCard().getIccLockEnabled();
9604 } else {
9605 return false;
9606 }
9607 } finally {
9608 Binder.restoreCallingIdentity(identity);
9609 }
9610 }
9611
9612 /**
9613 * Set the ICC pin lock enabled or disabled.
9614 *
9615 * @return an integer representing the status of IccLock enabled or disabled in the following
9616 * three cases:
9617 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9618 * successfully.
9619 * - Positive number and zero for remaining password attempts.
9620 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9621 *
9622 */
9623 @Override
9624 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9625 enforceModifyPermission();
9626
9627 Phone phone = getPhone(subId);
9628 if (phone == null) {
9629 return 0;
9630 }
9631 // Now that all security checks passes, perform the operation as ourselves.
9632 final long identity = Binder.clearCallingIdentity();
9633 try {
9634 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9635 new Pair<Boolean, String>(enabled, password), phone, null);
9636 return attemptsRemaining;
9637
9638 } catch (Exception e) {
9639 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 return 0;
9644 }
9645
9646 /**
9647 * Change the ICC password used in ICC pin lock.
9648 *
9649 * @return an integer representing the status of IccLock changed in the following three cases:
9650 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9651 * - Positive number and zero for remaining password attempts.
9652 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9653 *
9654 */
9655 @Override
9656 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9657 enforceModifyPermission();
9658
9659 Phone phone = getPhone(subId);
9660 if (phone == null) {
9661 return 0;
9662 }
9663 // Now that all security checks passes, perform the operation as ourselves.
9664 final long identity = Binder.clearCallingIdentity();
9665 try {
9666 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9667 new Pair<String, String>(oldPassword, newPassword), phone, null);
9668 return attemptsRemaining;
9669
9670 } catch (Exception e) {
9671 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9672 } finally {
9673 Binder.restoreCallingIdentity(identity);
9674 }
9675 return 0;
9676 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009677
9678 /**
9679 * Request for receiving user activity notification
9680 */
9681 @Override
9682 public void requestUserActivityNotification() {
9683 if (!mNotifyUserActivity.get()
9684 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9685 mNotifyUserActivity.set(true);
9686 }
9687 }
9688
9689 /**
9690 * Called when userActivity is signalled in the power manager.
9691 * This is safe to call from any thread, with any window manager locks held or not.
9692 */
9693 @Override
9694 public void userActivity() {
9695 // ***************************************
9696 // * Inherited from PhoneWindowManager *
9697 // ***************************************
9698 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9699 // WITH ITS LOCKS HELD.
9700 //
9701 // This code must be VERY careful about the locks
9702 // it acquires.
9703 // In fact, the current code acquires way too many,
9704 // and probably has lurking deadlocks.
9705
9706 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9707 throw new SecurityException("Only the OS may call notifyUserActivity()");
9708 }
9709
9710 if (mNotifyUserActivity.getAndSet(false)) {
9711 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9712 USER_ACTIVITY_NOTIFICATION_DELAY);
9713 }
9714 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009715
9716 @Override
9717 public boolean canConnectTo5GInDsdsMode() {
9718 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9719 }
Jack Yud10cdd42020-09-28 20:28:01 -07009720
9721 @Override
9722 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9723 String callingFeatureId) {
9724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9725 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9726 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9727 }
9728
9729 Phone phone = getPhone(subId);
9730 if (phone == null) {
9731 throw new RuntimeException("phone is not available");
9732 }
9733 // Now that all security checks passes, perform the operation as ourselves.
9734 final long identity = Binder.clearCallingIdentity();
9735 try {
9736 return phone.getEquivalentHomePlmns();
9737 } finally {
9738 Binder.restoreCallingIdentity(identity);
9739 }
9740 }
Daniel Bright59e67312020-11-13 11:49:37 -08009741
9742 @Override
9743 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009744 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9745 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009746 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009747 if (radioInterfaceCapabilities == null) {
9748 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009749 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009750 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009751 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009752
Hui Wang641e81c2020-10-12 12:14:23 -07009753 @Override
9754 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9755 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009756 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9757 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9758 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9759 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9760 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009761 if (DBG) {
9762 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9763 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9764 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9765 }
9766
9767 if (!SubscriptionManager.isValidSubscriptionId(subId)
9768 || appType < TelephonyManager.APPTYPE_UNKNOWN
9769 || appType > TelephonyManager.APPTYPE_ISIM
9770 || nafUrl == null || securityProtocol == null || callback == null) {
9771 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9772 if (callback != null) {
9773 try {
9774 callback.onAuthenticationFailure(
9775 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9776 } catch (RemoteException exception) {
9777 log("Fail to notify onAuthenticationFailure due to " + exception);
9778 }
9779 return;
9780 }
9781 }
9782
9783 final long token = Binder.clearCallingIdentity();
9784 try {
9785 getGbaManager(subId).bootstrapAuthenticationRequest(
9786 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9787 forceBootStrapping, callback));
9788 } finally {
9789 Binder.restoreCallingIdentity(token);
9790 }
9791 }
9792
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009793 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009794 * Attempts to set the radio power state for all phones for thermal reason.
9795 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009796 * requested radio power state will actually be set. See {@link
9797 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9798 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009799 * @param enable {@code true} if trying to turn radio on.
9800 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9801 * false}.
9802 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009803 private boolean setRadioPowerForThermal(boolean enable) {
9804 boolean isPhoneAvailable = false;
9805 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9806 Phone phone = PhoneFactory.getPhone(i);
9807 if (phone != null) {
9808 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9809 isPhoneAvailable = true;
9810 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009811 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009812
9813 // return true if successfully informed the phone object about the thermal radio power
9814 // request.
9815 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009816 }
9817
9818 private int handleDataThrottlingRequest(int subId,
9819 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009820 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9821 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9822 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9823 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9824 throw new IllegalArgumentException("modem does not support data throttling");
9825 }
9826
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009827 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9828 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009829 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009830 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9831 }
9832
9833 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9834
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009835 if (isDataThrottlingSupported) {
9836 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009837 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009838 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9839 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9840 } else if (thermalMitigationResult
9841 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009842 log("Modem likely does not support data throttling on secondary carrier. Data " +
9843 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9844 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009845 }
9846 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009847 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009848
9849 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009850 }
9851
Jack Nudelman644b91a2021-03-12 14:09:48 -08009852 private static List<String> getThermalMitigationAllowlist(Context context) {
9853 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9854 for (String pckg : context.getResources()
9855 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9856 sThermalMitigationAllowlistedPackages.add(pckg);
9857 }
9858 }
9859
9860 return sThermalMitigationAllowlistedPackages;
9861 }
9862
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009863 private boolean isAnyPhoneInEmergencyState() {
9864 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9865 if (tm.isInEmergencyCall()) {
9866 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9867 return true;
9868 }
9869 for (Phone phone : PhoneFactory.getPhones()) {
9870 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9871 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9872 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9873 + phone.isInEcm());
9874 return true;
9875 }
9876 }
9877
9878 return false;
9879 }
9880
Jack Nudelman644b91a2021-03-12 14:09:48 -08009881 /**
9882 * Used by shell commands to add an authorized package name for thermal mitigation.
9883 * @param packageName name of package to be allowlisted
9884 * @param context
9885 */
9886 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9887 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9888 sThermalMitigationAllowlistedPackages.add(packageName);
9889 }
9890
9891 /**
9892 * Used by shell commands to remove an authorized package name for thermal mitigation.
9893 * @param packageName name of package to remove from allowlist
9894 * @param context
9895 */
9896 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9897 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9898 sThermalMitigationAllowlistedPackages.remove(packageName);
9899 }
9900
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009901 /**
9902 * Thermal mitigation request to control functionalities at modem.
9903 *
9904 * @param subId the id of the subscription.
9905 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009906 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009907 *
9908 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9909 */
9910 @Override
9911 @ThermalMitigationResult
9912 public int sendThermalMitigationRequest(
9913 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009914 ThermalMitigationRequest thermalMitigationRequest,
9915 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009916 enforceModifyPermission();
9917
Jack Nudelman644b91a2021-03-12 14:09:48 -08009918 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9919 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9920 .contains(callingPackage)) {
9921 throw new SecurityException("Calling package must be configured in the device config. "
9922 + "calling package: " + callingPackage);
9923 }
9924
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9926 final long identity = Binder.clearCallingIdentity();
9927
9928 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9929 try {
9930 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9931 switch (thermalMitigationAction) {
9932 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9933 thermalMitigationResult =
9934 handleDataThrottlingRequest(subId,
9935 thermalMitigationRequest.getDataThrottlingRequest());
9936 break;
9937 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9938 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9939 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9940 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9941 }
9942
9943 // Ensure that radio is on. If not able to power on due to phone being
9944 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009945 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009946 thermalMitigationResult =
9947 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9948 break;
9949 }
9950
9951 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9952 false);
9953 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9954 break;
9955 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9956 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9957 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9958 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9959 }
9960
9961 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9962 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009963 Phone phone = getPhone(subId);
9964 if (phone == null) {
9965 thermalMitigationResult =
9966 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9967 break;
9968 }
9969
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009970 TelephonyConnectionService service =
9971 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -07009972 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009973 Log.e(LOG_TAG, "An emergency call is pending");
9974 thermalMitigationResult =
9975 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9976 break;
9977 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009978 thermalMitigationResult =
9979 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9980 break;
9981 }
9982 } else {
9983 thermalMitigationResult =
9984 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9985 break;
9986 }
9987
9988 // Turn radio off. If not able to power off due to phone being unavailable,
9989 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009990 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009991 thermalMitigationResult =
9992 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9993 break;
9994 }
9995 thermalMitigationResult =
9996 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9997 break;
9998 default:
9999 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10000 + "not exist. Requested action: " + thermalMitigationAction);
10001 }
10002 } catch (IllegalArgumentException e) {
10003 throw e;
10004 } catch (Exception e) {
10005 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10006 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10007 } finally {
10008 Binder.restoreCallingIdentity(identity);
10009 }
10010
10011 if (DBG) {
10012 log("thermalMitigationRequest returning with thermalMitigationResult: "
10013 + thermalMitigationResult);
10014 }
10015
10016 return thermalMitigationResult;
10017 }
Hui Wang641e81c2020-10-12 12:14:23 -070010018
10019 /**
10020 * Set the GbaService Package Name that Telephony will bind to.
10021 *
10022 * @param subId The sim that the GbaService is associated with.
10023 * @param packageName The name of the package to be replaced with.
10024 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10025 */
10026 @Override
10027 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10028 enforceModifyPermission();
10029
10030 final long identity = Binder.clearCallingIdentity();
10031 try {
10032 return getGbaManager(subId).overrideServicePackage(packageName);
10033 } finally {
10034 Binder.restoreCallingIdentity(identity);
10035 }
10036 }
10037
10038 /**
10039 * Return the package name of the currently bound GbaService.
10040 *
10041 * @param subId The sim that the GbaService is associated with.
10042 * @return the package name of the GbaService configuration, null if GBA is not supported.
10043 */
10044 @Override
10045 public String getBoundGbaService(int subId) {
10046 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10047
10048 final long identity = Binder.clearCallingIdentity();
10049 try {
10050 return getGbaManager(subId).getServicePackage();
10051 } finally {
10052 Binder.restoreCallingIdentity(identity);
10053 }
10054 }
10055
10056 /**
10057 * Set the release time for telephony to unbind GbaService.
10058 *
10059 * @param subId The sim that the GbaService is associated with.
10060 * @param interval The release time to unbind GbaService by millisecond.
10061 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10062 */
10063 @Override
10064 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10065 enforceModifyPermission();
10066
10067 final long identity = Binder.clearCallingIdentity();
10068 try {
10069 return getGbaManager(subId).overrideReleaseTime(interval);
10070 } finally {
10071 Binder.restoreCallingIdentity(identity);
10072 }
10073 }
10074
10075 /**
10076 * Return the release time for telephony to unbind GbaService.
10077 *
10078 * @param subId The sim that the GbaService is associated with.
10079 * @return The release time to unbind GbaService by millisecond.
10080 */
10081 @Override
10082 public int getGbaReleaseTime(int subId) {
10083 enforceReadPrivilegedPermission("getGbaReleaseTime");
10084
10085 final long identity = Binder.clearCallingIdentity();
10086 try {
10087 return getGbaManager(subId).getReleaseTime();
10088 } finally {
10089 Binder.restoreCallingIdentity(identity);
10090 }
10091 }
10092
10093 private GbaManager getGbaManager(int subId) {
10094 GbaManager instance = GbaManager.getInstance(subId);
10095 if (instance == null) {
10096 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10097 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10098 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10099 }
10100 return instance;
10101 }
Hui Wang761a6682020-10-31 05:12:53 +000010102
10103 /**
10104 * indicate whether the device and the carrier can support
10105 * RCS VoLTE single registration.
10106 */
10107 @Override
10108 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010109 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10110 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10111 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10112 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010113
10114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10115 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10116 }
10117
10118 final long identity = Binder.clearCallingIdentity();
10119 try {
10120 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10121 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010122 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10123 if (isCapable != null) {
10124 return isCapable;
10125 }
Hui Wang761a6682020-10-31 05:12:53 +000010126 }
Hui Wang67af90e2021-06-04 16:57:15 -070010127 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10128 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010129 } finally {
10130 Binder.restoreCallingIdentity(identity);
10131 }
10132 }
10133
10134 /**
10135 * Register RCS provisioning callback.
10136 */
10137 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010138 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010139 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010140 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010141 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010142 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10143 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010144
10145 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10146 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10147 }
10148 if (!isImsAvailableOnDevice()) {
10149 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10150 "IMS not available on device.");
10151 }
10152
10153 final long identity = Binder.clearCallingIdentity();
10154 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010155 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010156 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010157 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10158 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010159 }
Hui Wang761a6682020-10-31 05:12:53 +000010160 } finally {
10161 Binder.restoreCallingIdentity(identity);
10162 }
10163 }
10164
10165 /**
10166 * Unregister RCS provisioning callback.
10167 */
10168 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010169 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010170 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010171 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010172 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010173 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10174 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010175
10176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10177 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10178 }
10179 if (!isImsAvailableOnDevice()) {
10180 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10181 "IMS not available on device.");
10182 }
10183
10184 final long identity = Binder.clearCallingIdentity();
10185 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010186 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010187 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010188 } finally {
10189 Binder.restoreCallingIdentity(identity);
10190 }
10191 }
10192
10193 /**
10194 * trigger RCS reconfiguration.
10195 */
10196 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010197 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10198 "triggerRcsReconfiguration",
10199 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010200
10201 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10202 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10203 }
10204 if (!isImsAvailableOnDevice()) {
10205 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10206 "IMS not available on device.");
10207 }
10208
10209 final long identity = Binder.clearCallingIdentity();
10210 try {
10211 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
10216
10217 /**
10218 * Provide the client configuration parameters of the RCS application.
10219 */
10220 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010221 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10222 "setRcsClientConfiguration",
10223 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010224
10225 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10226 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10227 }
10228 if (!isImsAvailableOnDevice()) {
10229 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10230 "IMS not available on device.");
10231 }
10232
10233 final long identity = Binder.clearCallingIdentity();
10234
10235 try {
10236 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10237 if (configBinder == null) {
10238 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010239 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10240 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010241 } else {
10242 configBinder.setRcsClientConfiguration(rcc);
10243 }
10244 } catch (RemoteException e) {
10245 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010246 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10247 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010248 } finally {
10249 Binder.restoreCallingIdentity(identity);
10250 }
10251 }
10252
10253 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010254 * Enables or disables the test mode for RCS VoLTE single registration.
10255 */
10256 @Override
10257 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10258 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10259 "setRcsSingleRegistrationTestModeEnabled");
10260
10261 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10262 }
10263
10264 /**
10265 * Gets the test mode for RCS VoLTE single registration.
10266 */
10267 @Override
10268 public boolean getRcsSingleRegistrationTestModeEnabled() {
10269 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10270 "getRcsSingleRegistrationTestModeEnabled");
10271
10272 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10273 }
10274
10275 /**
Hui Wang761a6682020-10-31 05:12:53 +000010276 * Overrides the config of RCS VoLTE single registration enabled for the device.
10277 */
10278 @Override
10279 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10280 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10281 "setDeviceSingleRegistrationEnabledOverride");
10282 enforceModifyPermission();
10283
10284 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10285 : Boolean.parseBoolean(enabledStr);
10286 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010287 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010288 }
10289
10290 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010291 * Sends a device to device communication message. Only usable via shell.
10292 * @param message message to send.
10293 * @param value message value.
10294 */
10295 @Override
10296 public void sendDeviceToDeviceMessage(int message, int value) {
10297 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010298 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010299 enforceModifyPermission();
10300
10301 final long identity = Binder.clearCallingIdentity();
10302 try {
10303 TelephonyConnectionService service =
10304 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10305 if (service == null) {
10306 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10307 return;
10308 }
10309 service.sendTestDeviceToDeviceMessage(message, value);
10310 } finally {
10311 Binder.restoreCallingIdentity(identity);
10312 }
10313 }
10314
Tyler Gunnbabbda02021-02-10 11:05:02 -080010315 /**
10316 * Sets the specified device to device transport active.
10317 * @param transport The transport to set active.
10318 */
10319 @Override
10320 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10321 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10322 "setActiveDeviceToDeviceTransport");
10323 enforceModifyPermission();
10324
10325 final long identity = Binder.clearCallingIdentity();
10326 try {
10327 TelephonyConnectionService service =
10328 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10329 if (service == null) {
10330 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10331 return;
10332 }
10333 service.setActiveDeviceToDeviceTransport(transport);
10334 } finally {
10335 Binder.restoreCallingIdentity(identity);
10336 }
10337 }
Tyler Gunn92479152021-01-20 16:30:10 -080010338
Tyler Gunnd4575212021-05-03 14:46:49 -070010339 @Override
10340 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10341 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10342 "setDeviceToDeviceForceEnabled");
10343
10344 final long identity = Binder.clearCallingIdentity();
10345 try {
10346 Arrays.stream(PhoneFactory.getPhones()).forEach(
10347 p -> {
10348 Phone thePhone = p.getImsPhone();
10349 if (thePhone != null && thePhone instanceof ImsPhone) {
10350 ImsPhone imsPhone = (ImsPhone) thePhone;
10351 CallTracker tracker = imsPhone.getCallTracker();
10352 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10353 ImsPhoneCallTracker imsPhoneCallTracker =
10354 (ImsPhoneCallTracker) tracker;
10355 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10356 }
10357 }
10358 }
10359 );
10360 } finally {
10361 Binder.restoreCallingIdentity(identity);
10362 }
10363 }
10364
Tyler Gunn92479152021-01-20 16:30:10 -080010365 /**
Hui Wang761a6682020-10-31 05:12:53 +000010366 * Gets the config of RCS VoLTE single registration enabled for the device.
10367 */
10368 @Override
10369 public boolean getDeviceSingleRegistrationEnabled() {
10370 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10371 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10372 }
10373
10374 /**
10375 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10376 */
10377 @Override
10378 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10380 "setCarrierSingleRegistrationEnabledOverride");
10381 enforceModifyPermission();
10382
10383 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10384 : Boolean.parseBoolean(enabledStr);
10385 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10386 subId, enabled);
10387 }
10388
10389 /**
10390 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10391 */
10392 @Override
10393 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10394 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10395 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10396 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010397
10398 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010399 * Overrides the ims feature validation result
10400 */
10401 @Override
10402 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10403 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10404 "setImsFeatureValidationOverride");
10405
10406 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10407 : Boolean.parseBoolean(enabledStr);
10408 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10409 subId, enabled);
10410 }
10411
10412 /**
10413 * Gets the ims feature validation override value
10414 */
10415 @Override
10416 public boolean getImsFeatureValidationOverride(int subId) {
10417 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10418 "getImsFeatureValidationOverride");
10419 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10420 }
10421
10422 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010423 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10424 * their mobile plan.
10425 */
10426 @Override
10427 public String getMobileProvisioningUrl() {
10428 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10429 final long identity = Binder.clearCallingIdentity();
10430 try {
10431 return getDefaultPhone().getMobileProvisioningUrl();
10432 } finally {
10433 Binder.restoreCallingIdentity(identity);
10434 }
10435 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010436
James.cf Linbcdf8b32021-01-14 16:44:13 +080010437 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010438 * Get the EAB contact from the EAB database.
10439 */
10440 @Override
10441 public String getContactFromEab(String contact) {
10442 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10443 enforceModifyPermission();
10444 final long identity = Binder.clearCallingIdentity();
10445 try {
10446 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10447 } finally {
10448 Binder.restoreCallingIdentity(identity);
10449 }
10450 }
10451
10452 /**
Calvin Pana1434322021-07-01 19:27:01 +080010453 * Get the EAB capability from the EAB database.
10454 */
10455 @Override
10456 public String getCapabilityFromEab(String contact) {
10457 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10458 enforceModifyPermission();
10459 final long identity = Binder.clearCallingIdentity();
10460 try {
10461 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10462 } finally {
10463 Binder.restoreCallingIdentity(identity);
10464 }
10465 }
10466
10467 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010468 * Remove the EAB contacts from the EAB database.
10469 */
10470 @Override
10471 public int removeContactFromEab(int subId, String contacts) {
10472 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10473 enforceModifyPermission();
10474 final long identity = Binder.clearCallingIdentity();
10475 try {
10476 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10477 } finally {
10478 Binder.restoreCallingIdentity(identity);
10479 }
10480 }
10481
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010482 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010483 public boolean getDeviceUceEnabled() {
10484 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10485 final long identity = Binder.clearCallingIdentity();
10486 try {
10487 return mApp.getDeviceUceEnabled();
10488 } finally {
10489 Binder.restoreCallingIdentity(identity);
10490 }
10491 }
10492
10493 @Override
10494 public void setDeviceUceEnabled(boolean isEnabled) {
10495 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10496 final long identity = Binder.clearCallingIdentity();
10497 try {
10498 mApp.setDeviceUceEnabled(isEnabled);
10499 } finally {
10500 Binder.restoreCallingIdentity(identity);
10501 }
10502 }
10503
Brad Ebinger14d467f2021-02-12 06:18:28 +000010504 /**
10505 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10506 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10507 */
10508 // Used for SHELL command only right now.
10509 @Override
10510 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10511 List<String> featureTags) {
10512 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10513 "addUceRegistrationOverrideShell");
10514 final long identity = Binder.clearCallingIdentity();
10515 try {
10516 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10517 new ArraySet<>(featureTags));
10518 } catch (ImsException e) {
10519 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10520 } finally {
10521 Binder.restoreCallingIdentity(identity);
10522 }
10523 }
10524
10525 /**
10526 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10527 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10528 */
10529 // Used for SHELL command only right now.
10530 @Override
10531 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10532 List<String> featureTags) {
10533 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10534 "removeUceRegistrationOverrideShell");
10535 final long identity = Binder.clearCallingIdentity();
10536 try {
10537 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10538 new ArraySet<>(featureTags));
10539 } catch (ImsException e) {
10540 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10541 } finally {
10542 Binder.restoreCallingIdentity(identity);
10543 }
10544 }
10545
10546 /**
10547 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10548 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10549 */
10550 // Used for SHELL command only right now.
10551 @Override
10552 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10554 "clearUceRegistrationOverrideShell");
10555 final long identity = Binder.clearCallingIdentity();
10556 try {
10557 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10558 } catch (ImsException e) {
10559 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10560 } finally {
10561 Binder.restoreCallingIdentity(identity);
10562 }
10563 }
10564
10565 /**
10566 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10567 */
10568 // Used for SHELL command only right now.
10569 @Override
10570 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10571 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10572 "getLatestRcsContactUceCapabilityShell");
10573 final long identity = Binder.clearCallingIdentity();
10574 try {
10575 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10576 } catch (ImsException e) {
10577 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10578 } finally {
10579 Binder.restoreCallingIdentity(identity);
10580 }
10581 }
10582
10583 /**
10584 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10585 * device does not have an active PUBLISH.
10586 */
10587 // Used for SHELL command only right now.
10588 @Override
10589 public String getLastUcePidfXmlShell(int subId) {
10590 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10591 final long identity = Binder.clearCallingIdentity();
10592 try {
10593 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10594 } catch (ImsException e) {
10595 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10596 } finally {
10597 Binder.restoreCallingIdentity(identity);
10598 }
10599 }
10600
James.cf Line8713a42021-04-29 16:04:26 +080010601 /**
10602 * Remove UCE requests cannot be sent to the network status.
10603 */
10604 // Used for SHELL command only right now.
10605 @Override
10606 public boolean removeUceRequestDisallowedStatus(int subId) {
10607 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10608 final long identity = Binder.clearCallingIdentity();
10609 try {
10610 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10611 } catch (ImsException e) {
10612 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10613 } finally {
10614 Binder.restoreCallingIdentity(identity);
10615 }
10616 }
10617
James.cf Lin0fc71b02021-05-25 01:37:38 +080010618 /**
10619 * Remove UCE requests cannot be sent to the network status.
10620 */
10621 // Used for SHELL command only.
10622 @Override
10623 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10624 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10625 final long identity = Binder.clearCallingIdentity();
10626 try {
10627 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10628 } catch (ImsException e) {
10629 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10630 } finally {
10631 Binder.restoreCallingIdentity(identity);
10632 }
10633 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010634
James.cf Lin4b784aa2021-01-31 03:25:15 +080010635 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010636 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10637 String callingPackage) {
10638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10639 mApp, subId, "setSignalStrengthUpdateRequest");
10640
10641 final int callingUid = Binder.getCallingUid();
10642 // Verify that tha callingPackage belongs to the calling UID
10643 mApp.getSystemService(AppOpsManager.class)
10644 .checkPackage(callingUid, callingPackage);
10645
10646 validateSignalStrengthUpdateRequest(request, callingUid);
10647
10648 final long identity = Binder.clearCallingIdentity();
10649 try {
10650 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10651 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10652
10653 if (result instanceof IllegalStateException) {
10654 throw (IllegalStateException) result;
10655 }
10656 } finally {
10657 Binder.restoreCallingIdentity(identity);
10658 }
10659 }
10660
10661 @Override
10662 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10663 String callingPackage) {
10664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10665 mApp, subId, "clearSignalStrengthUpdateRequest");
10666
10667 final int callingUid = Binder.getCallingUid();
10668 // Verify that tha callingPackage belongs to the calling UID
10669 mApp.getSystemService(AppOpsManager.class)
10670 .checkPackage(callingUid, callingPackage);
10671
10672 final long identity = Binder.clearCallingIdentity();
10673 try {
10674 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10675 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10676
10677 if (result instanceof IllegalStateException) {
10678 throw (IllegalStateException) result;
10679 }
10680 } finally {
10681 Binder.restoreCallingIdentity(identity);
10682 }
10683 }
10684
10685 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10686 int callingUid) {
10687 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10688 // phone/system process do not have further restriction on request
10689 return;
10690 }
10691
10692 // Applications has restrictions on how to use the request:
10693 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10694 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10695 // This is not system caller which has been checked above
10696 throw new IllegalArgumentException(
10697 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10698 }
10699
10700 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10701 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10702 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10703 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10704 || info.isEnabled()) {
10705 throw new IllegalArgumentException(
10706 "Only system can set hide fields in SignalThresholdInfo");
10707 }
10708
10709 // Thresholds length for each RAN need in range. This has been validated in
10710 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10711 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10712 final int[] thresholds = info.getThresholds();
10713 Objects.requireNonNull(thresholds);
10714 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10715 || thresholds.length
10716 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10717 throw new IllegalArgumentException(
10718 "thresholds length is out of range: " + thresholds.length);
10719 }
10720 }
10721 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010722
10723 /**
10724 * Gets the current phone capability.
10725 *
10726 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10727 * @return the PhoneCapability which describes the data connection capability of modem.
10728 * It's used to evaluate possible phone config change, for example from single
10729 * SIM device to multi-SIM device.
10730 */
10731 @Override
10732 public PhoneCapability getPhoneCapability() {
10733 enforceReadPrivilegedPermission("getPhoneCapability");
10734 final long identity = Binder.clearCallingIdentity();
10735 try {
10736 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10737 } finally {
10738 Binder.restoreCallingIdentity(identity);
10739 }
10740 }
Michele Berionne5e411512020-11-13 02:36:59 +000010741
10742 /**
10743 * Prepare TelephonyManager for an unattended reboot. The reboot is
10744 * required to be done shortly after the API is invoked.
10745 */
10746 @Override
10747 @TelephonyManager.PrepareUnattendedRebootResult
10748 public int prepareForUnattendedReboot() {
10749 enforceRebootPermission();
10750
10751 final long identity = Binder.clearCallingIdentity();
10752 try {
10753 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10754 } finally {
10755 Binder.restoreCallingIdentity(identity);
10756 }
10757 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010758
10759 /**
10760 * Request to get the current slicing configuration including URSP rules and
10761 * NSSAIs (configured, allowed and rejected).
10762 *
10763 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10764 */
10765 @Override
10766 public void getSlicingConfig(ResultReceiver callback) {
10767 enforceReadPrivilegedPermission("getSlicingConfig");
10768
10769 final long identity = Binder.clearCallingIdentity();
10770 try {
10771 Phone phone = getDefaultPhone();
10772 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10773 } finally {
10774 Binder.restoreCallingIdentity(identity);
10775 }
10776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010777}