blob: 2e65669614e21f8de4ccbf3733c89c655779c852 [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
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006830 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6831 card.getCarrierPrivilegeStatus(pkgInfo),
6832 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006833 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006834 privilegedPackages.add(pkgInfo.packageName);
6835 }
6836 }
6837 }
6838 }
6839 return privilegedPackages;
6840 }
6841
chen xuf7e9fe82019-05-09 19:31:02 -07006842 @Override
6843 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006844 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6845
6846 final long identity = Binder.clearCallingIdentity();
6847
chen xuf7e9fe82019-05-09 19:31:02 -07006848 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006849 try {
6850 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6851 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6852 }
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006855 }
6856 return privilegedPackages;
6857 }
6858
Wink Savilleb564aae2014-10-23 10:18:09 -07006859 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006860 final Phone phone = getPhone(subId);
6861 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006862 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006863 return null;
6864 }
6865 String iccId = card.getIccId();
6866 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006867 return null;
6868 }
6869 return iccId;
6870 }
6871
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006872 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006873 public void setCallComposerStatus(int subId, int status) {
6874 enforceModifyPermission();
6875
6876 final long identity = Binder.clearCallingIdentity();
6877 try {
6878 Phone phone = getPhone(subId);
6879 if (phone != null) {
6880 Phone defaultPhone = phone.getImsPhone();
6881 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6882 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6883 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006884 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6885 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006886 }
6887 }
Shuo Qian284ae752020-12-22 19:10:14 -08006888 } catch (ImsException e) {
6889 throw new ServiceSpecificException(e.getCode());
6890 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006891 Binder.restoreCallingIdentity(identity);
6892 }
6893 }
6894
6895 @Override
6896 public int getCallComposerStatus(int subId) {
6897 enforceReadPrivilegedPermission("getCallComposerStatus");
6898
6899 final long identity = Binder.clearCallingIdentity();
6900 try {
6901 Phone phone = getPhone(subId);
6902 if (phone != null) {
6903 Phone defaultPhone = phone.getImsPhone();
6904 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6905 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6906 return imsPhone.getCallComposerStatus();
6907 }
6908 }
6909 } finally {
6910 Binder.restoreCallingIdentity(identity);
6911 }
6912 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6913 }
6914
6915 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006916 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6917 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006918 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006919 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 final long identity = Binder.clearCallingIdentity();
6922 try {
6923 final String iccId = getIccId(subId);
6924 final Phone phone = getPhone(subId);
6925 if (phone == null) {
6926 return false;
6927 }
6928 final String subscriberId = phone.getSubscriberId();
6929
6930 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006931 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006932 + subscriberId + " to " + number);
6933 }
6934
6935 if (TextUtils.isEmpty(iccId)) {
6936 return false;
6937 }
6938
6939 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6940
6941 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6942 if (alphaTag == null) {
6943 editor.remove(alphaTagPrefKey);
6944 } else {
6945 editor.putString(alphaTagPrefKey, alphaTag);
6946 }
6947
6948 // Record both the line number and IMSI for this ICCID, since we need to
6949 // track all merged IMSIs based on line number
6950 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6951 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6952 if (number == null) {
6953 editor.remove(numberPrefKey);
6954 editor.remove(subscriberPrefKey);
6955 } else {
6956 editor.putString(numberPrefKey, number);
6957 editor.putString(subscriberPrefKey, subscriberId);
6958 }
6959
6960 editor.commit();
6961 return true;
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006964 }
Derek Tan7226c842014-07-02 17:42:23 -07006965 }
6966
6967 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006968 public String getLine1NumberForDisplay(int subId, String callingPackage,
6969 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006970 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006972 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006973 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006974 return null;
6975 }
Derek Tan97ebb422014-09-05 16:55:38 -07006976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 String iccId = getIccId(subId);
6980 if (iccId != null) {
6981 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6982 if (DBG_MERGE) {
6983 log("getLine1NumberForDisplay returning "
6984 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6985 }
6986 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6989 return null;
6990 } finally {
6991 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006992 }
Derek Tan7226c842014-07-02 17:42:23 -07006993 }
6994
6995 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006996 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6997 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006999 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007000 return null;
7001 }
Derek Tan97ebb422014-09-05 16:55:38 -07007002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 final long identity = Binder.clearCallingIdentity();
7004 try {
7005 String iccId = getIccId(subId);
7006 if (iccId != null) {
7007 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7008 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7009 }
7010 return null;
7011 } finally {
7012 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007013 }
Derek Tan7226c842014-07-02 17:42:23 -07007014 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007015
7016 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007017 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7018 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007019 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7020 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007022 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007023 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007024 return null;
7025 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007026
Jordan Liub49b04b2019-05-06 14:45:15 -07007027 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7028 // the process, where TelephonyManager was instantiated.
7029 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007030 final long identity = Binder.clearCallingIdentity();
7031 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007032 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 final TelephonyManager tele = TelephonyManager.from(context);
7034 final SubscriptionManager sub = SubscriptionManager.from(context);
7035
7036 // Figure out what subscribers are currently active
7037 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038
Jordan Liub49b04b2019-05-06 14:45:15 -07007039 // Only consider subs which match the current subId
7040 // This logic can be simplified. See b/131189269 for progress.
7041 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007042 activeSubscriberIds.add(tele.getSubscriberId(subId));
7043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044
7045 // First pass, find a number override for an active subscriber
7046 String mergeNumber = null;
7047 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7048 for (String key : prefs.keySet()) {
7049 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7050 final String subscriberId = (String) prefs.get(key);
7051 if (activeSubscriberIds.contains(subscriberId)) {
7052 final String iccId = key.substring(
7053 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7054 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7055 mergeNumber = (String) prefs.get(numberKey);
7056 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007057 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 + " for active subscriber " + subscriberId);
7059 }
7060 if (!TextUtils.isEmpty(mergeNumber)) {
7061 break;
7062 }
7063 }
7064 }
7065 }
7066
7067 // Shortcut when no active merged subscribers
7068 if (TextUtils.isEmpty(mergeNumber)) {
7069 return null;
7070 }
7071
7072 // Second pass, find all subscribers under that line override
7073 final ArraySet<String> result = new ArraySet<>();
7074 for (String key : prefs.keySet()) {
7075 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7076 final String number = (String) prefs.get(key);
7077 if (mergeNumber.equals(number)) {
7078 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7079 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7080 final String subscriberId = (String) prefs.get(subscriberKey);
7081 if (!TextUtils.isEmpty(subscriberId)) {
7082 result.add(subscriberId);
7083 }
7084 }
7085 }
7086 }
7087
7088 final String[] resultArray = result.toArray(new String[result.size()]);
7089 Arrays.sort(resultArray);
7090 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007091 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7093 }
7094 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007095 } finally {
7096 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007097 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007098 }
7099
7100 @Override
zoey chen38003472019-12-13 17:16:31 +08007101 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7102 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007103
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 final TelephonyManager telephonyManager = mApp.getSystemService(
7107 TelephonyManager.class);
7108 String subscriberId = telephonyManager.getSubscriberId(subId);
7109 if (subscriberId == null) {
7110 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007111 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007112 + subId);
7113 }
7114 return null;
7115 }
7116
7117 final SubscriptionInfo info = SubscriptionController.getInstance()
7118 .getSubscriptionInfo(subId);
7119 final ParcelUuid groupUuid = info.getGroupUuid();
7120 // If it doesn't belong to any group, return just subscriberId of itself.
7121 if (groupUuid == null) {
7122 return new String[]{subscriberId};
7123 }
7124
7125 // Get all subscriberIds from the group.
7126 final List<String> mergedSubscriberIds = new ArrayList<>();
7127 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007128 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007129 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007130 for (SubscriptionInfo subInfo : groupInfos) {
7131 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7132 if (subscriberId != null) {
7133 mergedSubscriberIds.add(subscriberId);
7134 }
7135 }
7136
7137 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7138 } finally {
7139 Binder.restoreCallingIdentity(identity);
7140
7141 }
7142 }
7143
7144 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007145 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007146 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007147 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 final Phone phone = getPhone(subId);
7152 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
7155 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007156 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007157
7158 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007159 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007160 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7161 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007162 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7163 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164
7165 final long identity = Binder.clearCallingIdentity();
7166 try {
7167 final Phone phone = getPhone(subId);
7168 if (phone == null) {
7169 return false;
7170 }
7171 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7172 cdmaNonRoamingList);
7173 } finally {
7174 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007175 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007176 }
7177
7178 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007179 @Deprecated
7180 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7181 enforceModifyPermission();
7182
7183 int returnValue = 0;
7184 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007185 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007186 if(result.exception == null) {
7187 if (result.result != null) {
7188 byte[] responseData = (byte[])(result.result);
7189 if(responseData.length > oemResp.length) {
7190 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7191 responseData.length + "bytes. Buffer Size is " +
7192 oemResp.length + "bytes.");
7193 }
7194 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7195 returnValue = responseData.length;
7196 }
7197 } else {
7198 CommandException ex = (CommandException) result.exception;
7199 returnValue = ex.getCommandError().ordinal();
7200 if(returnValue > 0) returnValue *= -1;
7201 }
7202 } catch (RuntimeException e) {
7203 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7204 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7205 if(returnValue > 0) returnValue *= -1;
7206 }
7207
7208 return returnValue;
7209 }
7210
7211 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007212 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007213 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007214 try {
7215 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007216 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007217 mApp, phone.getSubId(), "getRadioAccessFamily");
7218 } catch (SecurityException e) {
7219 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7220 throw e;
7221 }
chen xub97461a2018-10-26 14:17:57 -07007222 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007223 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007224 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007226 final long identity = Binder.clearCallingIdentity();
7227 try {
chen xub97461a2018-10-26 14:17:57 -07007228 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007229 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007230 mApp, phone.getSubId(), "getRadioAccessFamily");
7231 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232 } finally {
7233 Binder.restoreCallingIdentity(identity);
7234 }
chen xub97461a2018-10-26 14:17:57 -07007235 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007236 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007237
7238 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007239 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007240 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007241 try {
7242 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7243 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007244 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007245 }
7246 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007247 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007248 }
7249 RoleManager rm = mApp.getSystemService(RoleManager.class);
7250 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7251 if (!dialerRoleHolders.contains(callingPackage)) {
7252 throw new SecurityException("App must be the dialer role holder to"
7253 + " upload a call composer pic");
7254 }
7255
7256 Executors.newSingleThreadExecutor().execute(() -> {
7257 ByteArrayOutputStream output = new ByteArrayOutputStream(
7258 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7259 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7260 boolean readUntilEnd = false;
7261 int totalBytesRead = 0;
7262 byte[] buffer = new byte[16 * 1024];
7263 while (true) {
7264 int numRead;
7265 try {
7266 numRead = input.read(buffer);
7267 } catch (IOException e) {
7268 try {
7269 fd.checkError();
7270 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7271 null);
7272 } catch (IOException e1) {
7273 // This means that the other side closed explicitly with an error. If this
7274 // happens, log and ignore.
7275 loge("Remote end of call composer picture pipe closed: " + e1);
7276 }
7277 break;
7278 }
7279 if (numRead == -1) {
7280 readUntilEnd = true;
7281 break;
7282 }
7283 totalBytesRead += numRead;
7284 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7285 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7286 try {
7287 input.close();
7288 } catch (IOException e) {
7289 // ignore
7290 }
7291 break;
7292 }
7293 output.write(buffer, 0, numRead);
7294 }
7295 // Generally, the remote end will close the file descriptors. The only case where we
7296 // close is above, where the picture size is too big.
7297
7298 try {
7299 fd.checkError();
7300 } catch (IOException e) {
7301 loge("Remote end for call composer closed with an error: " + e);
7302 return;
7303 }
7304
Hall Liuaa4211e2021-01-20 15:43:39 -08007305 if (!readUntilEnd) {
7306 loge("Did not finish reading entire image; aborting");
7307 return;
7308 }
Hall Liu82694d52020-12-11 18:22:04 -08007309
Hall Liuaa4211e2021-01-20 15:43:39 -08007310 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7311 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7312 new CallComposerPictureTransfer.Factory() {},
7313 imageData,
7314 (result) -> {
7315 if (result.first != null) {
7316 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7317 Bundle outputResult = new Bundle();
7318 outputResult.putParcelable(
7319 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7320 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7321 outputResult);
7322 } else {
7323 callback.send(result.second, null);
7324 }
7325 }
7326 );
Hall Liu82694d52020-12-11 18:22:04 -08007327 });
7328 }
7329
7330 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007331 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007332 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007333 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334
7335 final long identity = Binder.clearCallingIdentity();
7336 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007337 ImsManager.getInstance(defaultPhone.getContext(),
7338 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339 } finally {
7340 Binder.restoreCallingIdentity(identity);
7341 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007342 }
7343
7344 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007345 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007346 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7348 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007349 return false;
7350 }
Svet Ganovb320e182015-04-16 12:30:10 -07007351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352 final long identity = Binder.clearCallingIdentity();
7353 try {
7354 // Check the user preference and the system-level IMS setting. Even if the user has
7355 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7356 // In the long run, we may instead need to check if there exists a connection service
7357 // which can support video calling.
7358 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007359 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 return imsManager.isVtEnabledByPlatform()
7361 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7362 && imsManager.isVtEnabledByUser();
7363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007366 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007367
Andrew Leea1239f22015-03-02 17:44:07 -08007368 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007369 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7370 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007372 mApp, subId, callingPackage, callingFeatureId,
7373 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 return false;
7375 }
7376
7377 final long identity = Binder.clearCallingIdentity();
7378 try {
7379 CarrierConfigManager configManager =
7380 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007381 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7383 } finally {
7384 Binder.restoreCallingIdentity(identity);
7385 }
Andrew Leea1239f22015-03-02 17:44:07 -08007386 }
7387
7388 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007389 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007391 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 return false;
7393 }
7394
7395 final long identity = Binder.clearCallingIdentity();
7396 try {
7397 CarrierConfigManager configManager =
7398 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007399 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7401 } finally {
7402 Binder.restoreCallingIdentity(identity);
7403 }
Andrew Leea1239f22015-03-02 17:44:07 -08007404 }
7405
Andrew Lee9431b832015-03-09 18:46:45 -07007406 @Override
7407 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007408 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007409 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007410 }
7411
7412 @Override
7413 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414 final long identity = Binder.clearCallingIdentity();
7415 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007416 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 } finally {
7418 Binder.restoreCallingIdentity(identity);
7419 }
Andrew Lee9431b832015-03-09 18:46:45 -07007420 }
7421
Hall Liuf6668912018-10-31 17:05:23 -07007422 /**
7423 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7424 * support for the feature and device firmware support.
7425 *
7426 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7427 */
7428 @Override
7429 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007431 final Phone phone = getPhone(subscriptionId);
7432 if (phone == null) {
7433 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7434 return false;
7435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007437 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7439 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007440 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 return isCarrierSupported && isDeviceSupported;
7442 } finally {
7443 Binder.restoreCallingIdentity(identity);
7444 }
Hall Liu98187582018-01-22 19:15:32 -08007445 }
7446
Hall Liuf6668912018-10-31 17:05:23 -07007447 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007448 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7449 * RTT setting, will return true if the device and carrier both support RTT.
7450 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007451 */
7452 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 final long identity = Binder.clearCallingIdentity();
7454 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007455 boolean isRttSupported = isRttSupported(subscriptionId);
7456 boolean isUserRttSettingOn = Settings.Secure.getInt(
7457 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7458 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7459 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7460 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 } finally {
7462 Binder.restoreCallingIdentity(identity);
7463 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007464 }
7465
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007466 @Deprecated
7467 @Override
7468 public String getDeviceId(String callingPackage) {
7469 return getDeviceIdWithFeature(callingPackage, null);
7470 }
7471
Sanket Padawe7310cc72015-01-14 09:53:20 -08007472 /**
7473 * Returns the unique device ID of phone, for example, the IMEI for
7474 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7475 *
7476 * <p>Requires Permission:
7477 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7478 */
7479 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007480 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007481 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007482 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007483 return null;
7484 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007485 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007486 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007487 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007488 return null;
7489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490
7491 final long identity = Binder.clearCallingIdentity();
7492 try {
7493 return phone.getDeviceId();
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007497 }
7498
Ping Sunc67b7c22016-03-02 19:16:45 +08007499 /**
7500 * {@hide}
7501 * Returns the IMS Registration Status on a particular subid
7502 *
7503 * @param subId
7504 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007505 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007506 Phone phone = getPhone(subId);
7507 if (phone != null) {
7508 return phone.isImsRegistered();
7509 } else {
7510 return false;
7511 }
7512 }
7513
Santos Cordon7a1885b2015-02-03 11:15:19 -08007514 @Override
7515 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 final long identity = Binder.clearCallingIdentity();
7517 try {
7518 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7519 } finally {
7520 Binder.restoreCallingIdentity(identity);
7521 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007522 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007523
Tyler Gunnf70ed162019-04-03 15:28:53 -07007524 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007525 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007528 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007529 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7530 }
7531 final long identity = Binder.clearCallingIdentity();
7532 try {
7533 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
7537 }
7538
7539 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007540 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007541 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007542 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007543 mApp,
7544 subscriptionId,
7545 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007546 final long identity = Binder.clearCallingIdentity();
7547 try {
7548 Phone phone = getPhone(subscriptionId);
7549 if (phone == null) {
7550 return null;
7551 }
7552 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
7556 }
7557
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007558 /**
7559 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007560 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007561 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 final long identity = Binder.clearCallingIdentity();
7563 try {
7564 Phone phone = getPhone(subId);
7565 if (phone != null) {
7566 return phone.isWifiCallingEnabled();
7567 } else {
7568 return false;
7569 }
7570 } finally {
7571 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007572 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007573 }
7574
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007575 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007576 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007577 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007578 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 final long identity = Binder.clearCallingIdentity();
7580 try {
7581 Phone phone = getPhone(subId);
7582 if (phone != null) {
7583 return phone.isVideoEnabled();
7584 } else {
7585 return false;
7586 }
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007589 }
7590 }
7591
7592 /**
7593 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7594 * defined in {@link ImsRegistrationImplBase}.
7595 */
7596 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 final long identity = Binder.clearCallingIdentity();
7598 try {
7599 Phone phone = getPhone(subId);
7600 if (phone != null) {
7601 return phone.getImsRegistrationTech();
7602 } else {
7603 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7604 }
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007607 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007608 }
7609
Stuart Scott8eef64f2015-04-08 15:13:54 -07007610 @Override
7611 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007612 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007613 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7614 return;
7615 }
Kai Shif70f46f2021-03-03 13:59:46 -08007616 Phone defaultPhone = getDefaultPhone();
7617 if (defaultPhone != null) {
7618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7619 mApp, getDefaultPhone().getSubId(), "factoryReset");
7620 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007621 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007622
Svet Ganovcc087f82015-05-12 20:35:54 -07007623 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007624 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7625 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007626 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007627 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007628 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007629 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007630 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007631 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007632 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007633 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007634 // There has been issues when Sms raw table somehow stores orphan
7635 // fragments. They lead to garbled message when new fragments come
7636 // in and combined with those stale ones. In case this happens again,
7637 // user can reset all network settings which will clean up this table.
7638 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007639 // Clean up IMS settings as well here.
7640 int slotId = getSlotIndex(subId);
7641 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7642 ImsManager.getInstance(mApp, slotId).factoryReset();
7643 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007644
Kai Shif70f46f2021-03-03 13:59:46 -08007645 if (defaultPhone == null) {
7646 return;
7647 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007648 // Erase modem config if erase modem on network setting is enabled.
7649 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7650 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7651 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007652 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007653 }
Kai Shif70f46f2021-03-03 13:59:46 -08007654
7655 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007656 } finally {
7657 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007658 }
7659 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007660
SongFerngWangfd89b102021-05-27 22:44:54 +08007661 @VisibleForTesting
7662 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7663 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7664 return;
7665 }
7666 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7667 RILConstants.PREFERRED_NETWORK_MODE);
7668 SubscriptionManager.setSubscriptionProperty(subId,
7669 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7670 "user=" + defaultNetworkType);
7671 phone.loadAllowedNetworksFromSubscriptionDatabase();
7672 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7673 defaultNetworkType, null);
7674 }
7675
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007676 private void cleanUpSmsRawTable(Context context) {
7677 ContentResolver resolver = context.getContentResolver();
7678 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7679 resolver.delete(uri, null, null);
7680 }
7681
Narayan Kamath1c496c22015-04-16 14:40:19 +01007682 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007683 public String getSimLocaleForSubscriber(int subId) {
7684 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7685 final Phone phone = getPhone(subId);
7686 if (phone == null) {
7687 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007688 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 final long identity = Binder.clearCallingIdentity();
7691 try {
chen xu5d3637b2019-01-21 23:31:38 -08007692 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007693 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007694 if (info == null) {
7695 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7696 return null;
7697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 // Try and fetch the locale from the carrier properties or from the SIM language
7699 // preferences (EF-PL and EF-LI)...
7700 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007702 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7703 if (localeFromDefaultSim != null) {
7704 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7705 if (DBG) log("Using locale from subId: " + subId + " locale: "
7706 + localeFromDefaultSim);
7707 return localeFromDefaultSim.toLanguageTag();
7708 } else {
7709 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 }
7711 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713 // The SIM language preferences only store a language (e.g. fr = French), not an
7714 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7715 // the SIM and carrier preferences does not include a country we add the country
7716 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007717 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007719 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007720 return mccLocale.toLanguageTag();
7721 }
7722
7723 if (DBG) log("No locale found - returning null");
7724 return null;
7725 } finally {
7726 Binder.restoreCallingIdentity(identity);
7727 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007728 }
7729
7730 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007731 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007732 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007733 }
7734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 /**
7736 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7737 */
7738 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007739 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007740 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007741 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007742
Chenjie Yu1ba97252018-01-11 18:16:20 -08007743 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007744 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007745
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007746 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007747 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7748 * representing the state of the modem.
7749 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007750 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7751 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007752 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007753 */
7754 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007755 public void requestModemActivityInfo(ResultReceiver result) {
7756 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007757 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758
7759 final long identity = Binder.clearCallingIdentity();
7760 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007761 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007762 } finally {
7763 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007764 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007765 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007766
Siddharth Rayb8114062018-06-17 15:02:38 -07007767 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7768 // less than total activity duration.
7769 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7770 if (info == null) {
7771 return false;
7772 }
7773 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007774 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7775 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7776
Siddharth Rayb8114062018-06-17 15:02:38 -07007777 return (info.isValid()
7778 && (info.getSleepTimeMillis() <= activityDurationMs)
7779 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007780 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007781 && (totalTxTimeMs <= activityDurationMs));
7782 }
7783
Jack Yu85bd38a2015-11-09 11:34:32 -08007784 /**
7785 * {@hide}
7786 * Returns the service state information on specified subscription.
7787 */
7788 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007789 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7790 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007791 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007792 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007793 return null;
7794 }
7795
Hall Liuf19c44f2018-11-27 14:38:17 -08007796 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7797 LocationAccessPolicy.checkLocationPermission(mApp,
7798 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7799 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007800 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007801 .setCallingPid(Binder.getCallingPid())
7802 .setCallingUid(Binder.getCallingUid())
7803 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007804 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007805 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007806 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7807 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007808 .build());
7809
7810 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7811 LocationAccessPolicy.checkLocationPermission(mApp,
7812 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7813 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007814 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007815 .setCallingPid(Binder.getCallingPid())
7816 .setCallingUid(Binder.getCallingUid())
7817 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007818 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007819 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007820 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7821 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007822 .build());
7823 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7824 boolean hasFinePermission =
7825 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7826 boolean hasCoarsePermission =
7827 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7828
Jack Yu479f40e2020-10-27 21:29:25 -07007829 final Phone phone = getPhone(subId);
7830 if (phone == null) {
7831 return null;
7832 }
7833
Jordan Liu0f2bc442020-11-18 16:47:37 -08007834 final long identity = Binder.clearCallingIdentity();
7835
Jack Yu479f40e2020-10-27 21:29:25 -07007836 boolean isCallingPackageDataService = phone.getDataServicePackages()
7837 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007839 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7840 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7841 Rlog.d(LOG_TAG,
7842 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7843 return null;
7844 }
7845
Hall Liuf19c44f2018-11-27 14:38:17 -08007846 ServiceState ss = phone.getServiceState();
7847
7848 // Scrub out the location info in ServiceState depending on what level of access
7849 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007850 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007851 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7852 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 } finally {
7854 Binder.restoreCallingIdentity(identity);
7855 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007856 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007857
7858 /**
7859 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7860 *
7861 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7862 * voicemail ringtone.
7863 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7864 * PhoneAccount.
7865 */
7866 @Override
7867 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 final long identity = Binder.clearCallingIdentity();
7869 try {
7870 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7871 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007872 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7876 } finally {
7877 Binder.restoreCallingIdentity(identity);
7878 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007879 }
7880
7881 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007882 * Sets the per-account voicemail ringtone.
7883 *
7884 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7885 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7886 *
7887 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7888 * voicemail ringtone.
7889 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7890 * PhoneAccount.
7891 */
7892 @Override
7893 public void setVoicemailRingtoneUri(String callingPackage,
7894 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007895 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007896 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007897 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7898 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7900 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7901 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007902 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903
7904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7907 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007908 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909 }
7910 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7911 } finally {
7912 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007913 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007914 }
7915
7916 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007917 * Returns whether vibration is set for voicemail notification in Phone settings.
7918 *
7919 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7920 * voicemail vibration setting.
7921 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7922 */
7923 @Override
7924 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 final long identity = Binder.clearCallingIdentity();
7926 try {
7927 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7928 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007929 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7933 } finally {
7934 Binder.restoreCallingIdentity(identity);
7935 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007936 }
7937
Youhan Wange64578a2016-05-02 15:32:42 -07007938 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007939 * Sets the per-account voicemail vibration.
7940 *
7941 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7942 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7943 *
7944 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7945 * voicemail vibration setting.
7946 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7947 * specific PhoneAccount.
7948 */
7949 @Override
7950 public void setVoicemailVibrationEnabled(String callingPackage,
7951 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007952 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007953 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007954 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7955 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7957 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7958 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007959 }
7960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 final long identity = Binder.clearCallingIdentity();
7962 try {
7963 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7964 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007965 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007966 }
7967 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7968 } finally {
7969 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007970 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007971 }
7972
7973 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007974 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7975 *
7976 * @throws SecurityException if the caller does not have the required permission
7977 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007978 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007979 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007980 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007981 }
7982
7983 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007984 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7985 * permission.
7986 *
7987 * @throws SecurityException if the caller does not have the required permission
7988 */
7989 private void enforceSendSmsPermission() {
7990 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7991 }
7992
7993 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007994 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007995 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007996 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007997 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007998 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007999 final long identity = Binder.clearCallingIdentity();
8000 try {
8001 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008002 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 if (componentName == null) {
8004 throw new SecurityException(
8005 "Caller not current active visual voicemail package[null]");
8006 }
8007 String vvmPackage = componentName.getPackageName();
8008 if (!callingPackage.equals(vvmPackage)) {
8009 throw new SecurityException("Caller not current active visual voicemail package["
8010 + vvmPackage + "]");
8011 }
8012 } finally {
8013 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008014 }
8015 }
8016
8017 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008018 * Return the application ID for the app type.
8019 *
8020 * @param subId the subscription ID that this request applies to.
8021 * @param appType the uicc app type.
8022 * @return Application ID for specificied app type, or null if no uicc.
8023 */
8024 @Override
8025 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008026 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008027 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028
8029 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008030 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008031 if (phone == null) {
8032 return null;
8033 }
8034 String aid = null;
8035 try {
8036 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8037 .getApplicationByType(appType).getAid();
8038 } catch (Exception e) {
8039 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8040 }
8041 return aid;
8042 } finally {
8043 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008044 }
Youhan Wange64578a2016-05-02 15:32:42 -07008045 }
8046
Youhan Wang4001d252016-05-11 10:29:41 -07008047 /**
8048 * Return the Electronic Serial Number.
8049 *
8050 * @param subId the subscription ID that this request applies to.
8051 * @return ESN or null if error.
8052 */
8053 @Override
8054 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008055 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008056 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008057
8058 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008059 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 if (phone == null) {
8061 return null;
8062 }
8063 String esn = null;
8064 try {
8065 esn = phone.getEsn();
8066 } catch (Exception e) {
8067 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8068 }
8069 return esn;
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008072 }
Youhan Wang4001d252016-05-11 10:29:41 -07008073 }
8074
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008075 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008076 * Return the Preferred Roaming List Version.
8077 *
8078 * @param subId the subscription ID that this request applies to.
8079 * @return PRLVersion or null if error.
8080 */
8081 @Override
8082 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008083 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008084 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085
8086 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008087 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088 if (phone == null) {
8089 return null;
8090 }
8091 String cdmaPrlVersion = null;
8092 try {
8093 cdmaPrlVersion = phone.getCdmaPrlVersion();
8094 } catch (Exception e) {
8095 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8096 }
8097 return cdmaPrlVersion;
8098 } finally {
8099 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008100 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008101 }
8102
8103 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008104 * Get snapshot of Telephony histograms
8105 * @return List of Telephony histograms
8106 * @hide
8107 */
8108 @Override
8109 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8111 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112
8113 final long identity = Binder.clearCallingIdentity();
8114 try {
8115 return RIL.getTelephonyRILTimingHistograms();
8116 } finally {
8117 Binder.restoreCallingIdentity(identity);
8118 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008119 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008120
8121 /**
8122 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008123 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8124 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008125 * Require system privileges. In the future we may add this to carrier APIs.
8126 *
Michele Berionne482f8202018-11-27 18:57:59 -08008127 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008128 */
8129 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008130 @TelephonyManager.SetCarrierRestrictionResult
8131 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008132 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008133 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008134
Michele Berionne482f8202018-11-27 18:57:59 -08008135 if (carrierRestrictionRules == null) {
8136 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008137 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 final long identity = Binder.clearCallingIdentity();
8140 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008141 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008142 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008143 } finally {
8144 Binder.restoreCallingIdentity(identity);
8145 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008146 }
8147
8148 /**
8149 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008150 * Get the allowed carrier list and the excluded carrier list, including the priority between
8151 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008152 * Require system privileges. In the future we may add this to carrier APIs.
8153 *
Michele Berionne482f8202018-11-27 18:57:59 -08008154 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008155 */
8156 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008157 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008158 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008159 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008160
8161 final long identity = Binder.clearCallingIdentity();
8162 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008163 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8164 if (response instanceof CarrierRestrictionRules) {
8165 return (CarrierRestrictionRules) response;
8166 }
8167 // Response is an Exception of some kind,
8168 // which is signalled to the user as a NULL retval
8169 return null;
8170 } catch (Exception e) {
8171 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8172 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 } finally {
8174 Binder.restoreCallingIdentity(identity);
8175 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008176 }
8177
fionaxu59545b42016-05-25 15:53:37 -07008178 /**
fionaxu59545b42016-05-25 15:53:37 -07008179 * Action set from carrier signalling broadcast receivers to enable/disable radio
8180 * @param subId the subscription ID that this action applies to.
8181 * @param enabled control enable or disable radio.
8182 * {@hide}
8183 */
8184 @Override
8185 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8186 enforceModifyPermission();
8187 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008188
8189 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008190 if (phone == null) {
8191 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8192 return;
8193 }
8194 try {
8195 phone.carrierActionSetRadioEnabled(enabled);
8196 } catch (Exception e) {
8197 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008198 } finally {
8199 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008200 }
8201 }
8202
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008203 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008204 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8205 * network status based on which carrier apps could apply actions accordingly,
8206 * enable/disable default url handler for example.
8207 *
8208 * @param subId the subscription ID that this action applies to.
8209 * @param report control start/stop reporting the default network status.
8210 * {@hide}
8211 */
8212 @Override
8213 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8214 enforceModifyPermission();
8215 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216
8217 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008218 if (phone == null) {
8219 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8220 return;
8221 }
8222 try {
8223 phone.carrierActionReportDefaultNetworkStatus(report);
8224 } catch (Exception e) {
8225 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 } finally {
8227 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008228 }
8229 }
8230
8231 /**
fionaxud9622282017-07-17 17:51:30 -07008232 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8233 * @param subId the subscription ID that this action applies to.
8234 * {@hide}
8235 */
8236 @Override
8237 public void carrierActionResetAll(int subId) {
8238 enforceModifyPermission();
8239 final Phone phone = getPhone(subId);
8240 if (phone == null) {
8241 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8242 return;
8243 }
8244 try {
8245 phone.carrierActionResetAll();
8246 } catch (Exception e) {
8247 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8248 }
8249 }
8250
8251 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008252 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8253 * bug report is being generated.
8254 */
8255 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008256 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008257 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8258 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008259 writer.println("Permission Denial: can't dump Phone from pid="
8260 + Binder.getCallingPid()
8261 + ", uid=" + Binder.getCallingUid()
8262 + "without permission "
8263 + android.Manifest.permission.DUMP);
8264 return;
8265 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008266 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008267 }
Jack Yueb89b242016-06-22 13:27:47 -07008268
Brad Ebingerdac2f002018-04-03 15:17:52 -07008269 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008270 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8271 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8272 @NonNull String[] args) {
8273 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8274 this, in.getFileDescriptor(), out.getFileDescriptor(),
8275 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008276 }
8277
Jack Yueb89b242016-06-22 13:27:47 -07008278 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008279 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008280 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008281 * @param reason the reason the data enable change is taking place
8282 * @param enabled True if enabling the data, otherwise disabling.
8283 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008284 */
8285 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008286 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008287 boolean enabled) {
8288 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8289 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8290 try {
8291 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008292 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008293 } catch (SecurityException se) {
8294 enforceModifyPermission();
8295 }
8296 } else {
8297 enforceModifyPermission();
8298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299
8300 final long identity = Binder.clearCallingIdentity();
8301 try {
8302 Phone phone = getPhone(subId);
8303 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008304 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8305 phone.carrierActionSetMeteredApnsEnabled(enabled);
8306 } else {
8307 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 }
8310 } finally {
8311 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008312 }
8313 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008314
8315 /**
8316 * Get Client request stats
8317 * @return List of Client Request Stats
8318 * @hide
8319 */
8320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008321 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8322 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008324 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008325 return null;
8326 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008327 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 final long identity = Binder.clearCallingIdentity();
8330 try {
8331 if (phone != null) {
8332 return phone.getClientRequestStats();
8333 }
8334
8335 return null;
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008339 }
8340
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008341 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008342 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008343 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008344 }
Jack Yueb4124c2017-02-16 15:32:43 -08008345
8346 /**
Grace Chen70990072017-03-24 17:21:30 -07008347 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008348 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008349 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008350 * @param state State of SIM (power down, power up, pass through)
8351 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8352 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8353 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008354 *
8355 **/
8356 @Override
Grace Chen70990072017-03-24 17:21:30 -07008357 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008358 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008359 Phone phone = PhoneFactory.getPhone(slotIndex);
8360
vagdeviaf9a5b92018-08-15 16:01:53 -07008361 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363 final long identity = Binder.clearCallingIdentity();
8364 try {
8365 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008366 phone.setSimPowerState(state, null, workSource);
8367 }
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
8371 }
8372
8373 /**
8374 * Set SIM card power state.
8375 *
8376 * @param slotIndex SIM slot id.
8377 * @param state State of SIM (power down, power up, pass through)
8378 * @param callback callback to trigger after success or failure
8379 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8380 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8381 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8382 *
8383 **/
8384 @Override
8385 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8386 IIntegerConsumer callback) {
8387 enforceModifyPermission();
8388 Phone phone = PhoneFactory.getPhone(slotIndex);
8389
8390 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8391
8392 final long identity = Binder.clearCallingIdentity();
8393 try {
8394 if (phone != null) {
8395 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8396 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008397 }
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008400 }
8401 }
Shuo Qiandd210312017-04-12 22:11:33 +00008402
Tyler Gunn65d45c22017-06-05 11:22:26 -07008403 private boolean isUssdApiAllowed(int subId) {
8404 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008405 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008406 if (configManager == null) {
8407 return false;
8408 }
8409 PersistableBundle pb = configManager.getConfigForSubId(subId);
8410 if (pb == null) {
8411 return false;
8412 }
8413 return pb.getBoolean(
8414 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8415 }
8416
Shuo Qiandd210312017-04-12 22:11:33 +00008417 /**
8418 * Check if phone is in emergency callback mode
8419 * @return true if phone is in emergency callback mode
8420 * @param subId sub id
8421 */
goneil9c5f4872017-12-05 14:07:56 -08008422 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008423 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008424 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008425 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008426
8427 final long identity = Binder.clearCallingIdentity();
8428 try {
8429 if (phone != null) {
8430 return phone.isInEcm();
8431 } else {
8432 return false;
8433 }
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008436 }
8437 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008438
8439 /**
8440 * Get the current signal strength information for the given subscription.
8441 * Because this information is not updated when the device is in a low power state
8442 * it should not be relied-upon to be current.
8443 * @param subId Subscription index
8444 * @return the most recent cached signal strength info from the modem
8445 */
8446 @Override
8447 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008448 final long identity = Binder.clearCallingIdentity();
8449 try {
8450 Phone p = getPhone(subId);
8451 if (p == null) {
8452 return null;
8453 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008454
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008455 return p.getSignalStrength();
8456 } finally {
8457 Binder.restoreCallingIdentity(identity);
8458 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008459 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008460
Pengquan Meng77b7f132018-08-22 14:49:57 -07008461 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008462 * Get the current modem radio state for the given slot.
8463 * @param slotIndex slot index.
8464 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008465 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008466 * @return the current radio power state from the modem
8467 */
8468 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008469 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008470 Phone phone = PhoneFactory.getPhone(slotIndex);
8471 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8473 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008474 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8475 }
8476
8477 final long identity = Binder.clearCallingIdentity();
8478 try {
8479 return phone.getRadioPowerState();
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
8482 }
8483 }
8484 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8485 }
8486
8487 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008488 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8489 *
8490 * <p>Requires one of the following permissions:
8491 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8492 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8493 * privileges.
8494 *
8495 * @param subId subscription id
8496 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8497 * {@code false}.
8498 */
8499 @Override
8500 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008501 try {
8502 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8503 null);
8504 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008505 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008506 mApp, subId, "isDataRoamingEnabled");
8507 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008508
Pengquan Menga1bb6272018-09-06 09:59:22 -07008509 boolean isEnabled = false;
8510 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008511 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008512 Phone phone = getPhone(subId);
8513 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008514 } finally {
8515 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008516 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008517 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008518 }
8519
8520
8521 /**
8522 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8523 *
8524 * <p> Requires permission:
8525 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8526 * privileges.
8527 *
8528 * @param subId subscription id
8529 * @param isEnabled {@code true} means enable, {@code false} means disable.
8530 */
8531 @Override
8532 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8534 mApp, subId, "setDataRoamingEnabled");
8535
Pengquan Menga1bb6272018-09-06 09:59:22 -07008536 final long identity = Binder.clearCallingIdentity();
8537 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008538 Phone phone = getPhone(subId);
8539 if (phone != null) {
8540 phone.setDataRoamingEnabled(isEnabled);
8541 }
8542 } finally {
8543 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008544 }
8545 }
8546
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008547 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008548 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008549 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008550 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008551 mApp, subId, "isManualNetworkSelectionAllowed");
8552
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008553 boolean isAllowed = true;
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008556 Phone phone = getPhone(subId);
8557 if (phone != null) {
8558 isAllowed = phone.isCspPlmnEnabled();
8559 }
8560 } finally {
8561 Binder.restoreCallingIdentity(identity);
8562 }
8563 return isAllowed;
8564 }
8565
8566 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008567 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008568 // Verify that tha callingPackage belongs to the calling UID
8569 mApp.getSystemService(AppOpsManager.class)
8570 .checkPackage(Binder.getCallingUid(), callingPackage);
8571
Jordan Liu1e142fc2019-04-22 15:10:43 -07008572 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008573 try {
8574 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008575 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008576 } catch (SecurityException e) {
8577 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8578 // has carrier privileges on an active UICC
8579 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8580 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008581 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008582 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008583 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008584
8585 final long identity = Binder.clearCallingIdentity();
8586 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008587 UiccController uiccController = UiccController.getInstance();
8588 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008589 if (hasReadPermission) {
8590 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008591 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008592
8593 // Remove private info if the caller doesn't have access
8594 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8595 for (UiccCardInfo cardInfo : cardInfos) {
8596 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8597 // is available
8598 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8599 if (card == null || card.getUiccProfile() == null) {
8600 // assume no access if the card or profile is unavailable
8601 filteredInfos.add(cardInfo.getUnprivileged());
8602 continue;
8603 }
8604 UiccProfile profile = card.getUiccProfile();
8605 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8606 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8607 filteredInfos.add(cardInfo);
8608 } else {
8609 filteredInfos.add(cardInfo.getUnprivileged());
8610 }
8611 }
8612 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008613 } finally {
8614 Binder.restoreCallingIdentity(identity);
8615 }
8616 }
8617
8618 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008619 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008620 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008622 final long identity = Binder.clearCallingIdentity();
8623 try {
8624 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8625 if (slots == null) {
8626 Rlog.i(LOG_TAG, "slots is null.");
8627 return null;
8628 }
8629
8630 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8631 for (int i = 0; i < slots.length; i++) {
8632 UiccSlot slot = slots[i];
8633 if (slot == null) {
8634 continue;
8635 }
8636
Jordan Liu7be7e652019-05-06 18:55:02 +00008637 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008638 UiccCard card = slot.getUiccCard();
8639 if (card != null) {
8640 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008641 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008642 cardId = slot.getEid();
8643 if (TextUtils.isEmpty(cardId)) {
8644 cardId = slot.getIccId();
8645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008646 }
8647
Jordan Liu857451f2019-05-09 16:35:35 -07008648 if (cardId != null) {
8649 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8650 // if cardId is an EID, it's all digits so this is fine
8651 cardId = IccUtils.stripTrailingFs(cardId);
8652 }
8653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008654 int cardState = 0;
8655 switch (slot.getCardState()) {
8656 case CARDSTATE_ABSENT:
8657 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8658 break;
8659 case CARDSTATE_PRESENT:
8660 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8661 break;
8662 case CARDSTATE_ERROR:
8663 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8664 break;
8665 case CARDSTATE_RESTRICTED:
8666 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8667 break;
8668 default:
8669 break;
8670
8671 }
8672
8673 infos[i] = new UiccSlotInfo(
8674 slot.isActive(),
8675 slot.isEuicc(),
8676 cardId,
8677 cardState,
8678 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008679 slot.isExtendedApduSupported(),
8680 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008681 }
8682 return infos;
8683 } finally {
8684 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008685 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008686 }
8687
8688 @Override
8689 public boolean switchSlots(int[] physicalSlots) {
8690 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008691
8692 final long identity = Binder.clearCallingIdentity();
8693 try {
8694 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8695 } finally {
8696 Binder.restoreCallingIdentity(identity);
8697 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008698 }
Jack Yu4c988042018-02-27 15:30:01 -08008699
8700 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008701 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008702 final long identity = Binder.clearCallingIdentity();
8703 try {
8704 return UiccController.getInstance().getCardIdForDefaultEuicc();
8705 } finally {
8706 Binder.restoreCallingIdentity(identity);
8707 }
8708 }
8709
Pengquan Meng85728fb2018-03-12 16:31:21 -07008710 /**
goneil47ffb6e2018-04-06 15:40:58 -07008711 * A test API to reload the UICC profile.
8712 *
8713 * <p>Requires that the calling app has permission
8714 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8715 * @hide
8716 */
8717 @Override
8718 public void refreshUiccProfile(int subId) {
8719 enforceModifyPermission();
8720
8721 final long identity = Binder.clearCallingIdentity();
8722 try {
8723 Phone phone = getPhone(subId);
8724 if (phone == null) {
8725 return;
8726 }
8727 UiccCard uiccCard = phone.getUiccCard();
8728 if (uiccCard == null) {
8729 return;
8730 }
8731 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8732 if (uiccProfile == null) {
8733 return;
8734 }
8735 uiccProfile.refresh();
8736 } finally {
8737 Binder.restoreCallingIdentity(identity);
8738 }
8739 }
8740
8741 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008742 * Returns false if the mobile data is disabled by default, otherwise return true.
8743 */
8744 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008745 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008746 }
8747
8748 /**
8749 * Returns true if the data roaming is enabled by default, i.e the system property
8750 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8751 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8752 */
8753 private boolean getDefaultDataRoamingEnabled(int subId) {
8754 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008755 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008756 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008757 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8758 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8759 return isDataRoamingEnabled;
8760 }
8761
8762 /**
8763 * Returns the default network type for the given {@code subId}, if the default network type is
8764 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8765 */
8766 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008767 List<Integer> list = TelephonyProperties.default_network();
8768 int phoneId = mSubscriptionController.getPhoneId(subId);
8769 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8770 return list.get(phoneId);
8771 }
8772 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008773 }
fionaxua13278b2018-03-21 00:08:13 -07008774
8775 @Override
8776 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008777 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008779
8780 final long identity = Binder.clearCallingIdentity();
8781 try {
8782 final Phone phone = getPhone(subId);
8783 if (phone == null) {
8784 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8785 return;
8786 }
chen xueaba88a2019-03-15 13:15:10 -07008787 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8788 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008789 if (carrierPrivilegeRules == null) {
8790 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8791 } else {
8792 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008794 } finally {
8795 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008796 }
fionaxua13278b2018-03-21 00:08:13 -07008797 }
8798
8799 @Override
8800 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008801 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008802
8803 final long identity = Binder.clearCallingIdentity();
8804 try {
8805 final Phone phone = getPhone(subId);
8806 if (phone == null) {
8807 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8808 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8809 }
8810 return phone.getCarrierIdListVersion();
8811 } finally {
8812 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008813 }
fionaxua13278b2018-03-21 00:08:13 -07008814 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008815
8816 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008817 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8818 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008819 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008820 mApp, subId, callingPackage, callingFeatureId,
8821 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008822 return -1;
8823 }
8824
8825 final long identity = Binder.clearCallingIdentity();
8826 try {
8827 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8828 } finally {
8829 Binder.restoreCallingIdentity(identity);
8830 }
8831 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008832
8833 @Override
8834 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008835 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008836 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008837 mApp, subId, "getCdmaRoamingMode");
8838
8839 final long identity = Binder.clearCallingIdentity();
8840 try {
8841 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8842 } finally {
8843 Binder.restoreCallingIdentity(identity);
8844 }
8845 }
8846
8847 @Override
8848 public boolean setCdmaRoamingMode(int subId, int mode) {
8849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8850 mApp, subId, "setCdmaRoamingMode");
8851
8852 final long identity = Binder.clearCallingIdentity();
8853 try {
8854 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8855 } finally {
8856 Binder.restoreCallingIdentity(identity);
8857 }
8858 }
8859
8860 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008861 public int getCdmaSubscriptionMode(int subId) {
8862 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008863 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008864 mApp, subId, "getCdmaSubscriptionMode");
8865
8866 final long identity = Binder.clearCallingIdentity();
8867 try {
8868 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8869 } finally {
8870 Binder.restoreCallingIdentity(identity);
8871 }
8872 }
8873
8874 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008875 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8877 mApp, subId, "setCdmaSubscriptionMode");
8878
8879 final long identity = Binder.clearCallingIdentity();
8880 try {
8881 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8882 } finally {
8883 Binder.restoreCallingIdentity(identity);
8884 }
8885 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008886
sqianc5eccab2018-10-19 18:46:41 -07008887 @Override
sqian8c685422019-02-22 15:55:18 -08008888 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008889 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008891 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8892 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008893 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8894 }
8895 final long identity = Binder.clearCallingIdentity();
8896 try {
sqian854d44b2018-12-12 16:48:18 -08008897 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8898 for (Phone phone: PhoneFactory.getPhones()) {
8899 if (phone.getEmergencyNumberTracker() != null
8900 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8901 emergencyNumberListInternal.put(
8902 phone.getSubId(),
8903 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8904 }
sqian11b7a0e2018-12-05 18:48:28 -08008905 }
sqian854d44b2018-12-12 16:48:18 -08008906 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008907 } finally {
8908 Binder.restoreCallingIdentity(identity);
8909 }
sqianc5eccab2018-10-19 18:46:41 -07008910 }
8911
8912 @Override
sqian8c685422019-02-22 15:55:18 -08008913 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008914 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008915 if (!exactMatch) {
8916 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008917 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008918 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008919 }
8920 final long identity = Binder.clearCallingIdentity();
8921 try {
sqian854d44b2018-12-12 16:48:18 -08008922 for (Phone phone: PhoneFactory.getPhones()) {
8923 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008924 && phone.getEmergencyNumberTracker()
8925 .isEmergencyNumber(number, exactMatch)) {
8926 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008927 }
sqian11b7a0e2018-12-05 18:48:28 -08008928 }
8929 return false;
8930 } finally {
8931 Binder.restoreCallingIdentity(identity);
8932 }
8933 }
8934
sqianf4ca7ed2019-01-15 18:32:07 -08008935 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008936 * Start emergency callback mode for GsmCdmaPhone for testing.
8937 */
8938 @Override
8939 public void startEmergencyCallbackMode() {
8940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8941 "startEmergencyCallbackMode");
8942 enforceModifyPermission();
8943 final long identity = Binder.clearCallingIdentity();
8944 try {
8945 for (Phone phone : PhoneFactory.getPhones()) {
8946 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8947 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8948 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8949 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8950 gsmCdmaPhone.obtainMessage(
8951 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8952 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8953 }
8954 }
8955 } finally {
8956 Binder.restoreCallingIdentity(identity);
8957 }
8958 }
8959
8960 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008961 * Update emergency number list for test mode.
8962 */
8963 @Override
8964 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8966 "updateEmergencyNumberListTestMode");
8967
8968 final long identity = Binder.clearCallingIdentity();
8969 try {
8970 for (Phone phone: PhoneFactory.getPhones()) {
8971 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8972 if (tracker != null) {
8973 tracker.executeEmergencyNumberTestModeCommand(action, num);
8974 }
8975 }
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
8978 }
8979 }
8980
8981 /**
8982 * Get the full emergency number list for test mode.
8983 */
8984 @Override
8985 public List<String> getEmergencyNumberListTestMode() {
8986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8987 "getEmergencyNumberListTestMode");
8988
8989 final long identity = Binder.clearCallingIdentity();
8990 try {
8991 Set<String> emergencyNumbers = new HashSet<>();
8992 for (Phone phone: PhoneFactory.getPhones()) {
8993 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8994 if (tracker != null) {
8995 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8996 emergencyNumbers.add(num.getNumber());
8997 }
8998 }
8999 }
9000 return new ArrayList<>(emergencyNumbers);
9001 } finally {
9002 Binder.restoreCallingIdentity(identity);
9003 }
9004 }
9005
chen xud6b45bd2018-10-30 22:27:10 -07009006 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009007 public int getEmergencyNumberDbVersion(int subId) {
9008 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9009
9010 final long identity = Binder.clearCallingIdentity();
9011 try {
9012 final Phone phone = getPhone(subId);
9013 if (phone == null) {
9014 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9015 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9016 }
9017 return phone.getEmergencyNumberDbVersion();
9018 } finally {
9019 Binder.restoreCallingIdentity(identity);
9020 }
9021 }
9022
9023 @Override
9024 public void notifyOtaEmergencyNumberDbInstalled() {
9025 enforceModifyPermission();
9026
9027 final long identity = Binder.clearCallingIdentity();
9028 try {
9029 for (Phone phone: PhoneFactory.getPhones()) {
9030 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9031 if (tracker != null) {
9032 tracker.updateOtaEmergencyNumberDatabase();
9033 }
9034 }
9035 } finally {
9036 Binder.restoreCallingIdentity(identity);
9037 }
9038 }
9039
9040 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009041 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009042 enforceActiveEmergencySessionPermission();
9043
9044 final long identity = Binder.clearCallingIdentity();
9045 try {
9046 for (Phone phone: PhoneFactory.getPhones()) {
9047 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9048 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009049 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9050 }
9051 }
9052 } finally {
9053 Binder.restoreCallingIdentity(identity);
9054 }
9055 }
9056
9057 @Override
9058 public void resetOtaEmergencyNumberDbFilePath() {
9059 enforceActiveEmergencySessionPermission();
9060
9061 final long identity = Binder.clearCallingIdentity();
9062 try {
9063 for (Phone phone: PhoneFactory.getPhones()) {
9064 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9065 if (tracker != null) {
9066 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009067 }
9068 }
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
9072 }
9073
9074 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009075 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9076 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9077 Phone phone = getPhone(subId);
9078 if (phone == null) {
9079 return null;
9080 }
9081 final long identity = Binder.clearCallingIdentity();
9082 try {
9083 UiccProfile profile = UiccController.getInstance()
9084 .getUiccProfileForPhone(phone.getPhoneId());
9085 if (profile != null) {
9086 return profile.getCertsFromCarrierPrivilegeAccessRules();
9087 }
9088 } finally {
9089 Binder.restoreCallingIdentity(identity);
9090 }
9091 return null;
9092 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009093
9094 /**
9095 * Enable or disable a modem stack.
9096 */
9097 @Override
9098 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9099 enforceModifyPermission();
9100
9101 final long identity = Binder.clearCallingIdentity();
9102 try {
9103 Phone phone = PhoneFactory.getPhone(slotIndex);
9104 if (phone == null) {
9105 return false;
9106 } else {
9107 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9108 }
9109 } finally {
9110 Binder.restoreCallingIdentity(identity);
9111 }
9112 }
Michelecea4cf22018-12-21 15:00:11 -08009113
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009114 /**
9115 * Whether a modem stack is enabled or not.
9116 */
9117 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009118 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9119 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009120 Phone phone = PhoneFactory.getPhone(slotIndex);
9121 if (phone == null) return false;
9122
9123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009124 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9125 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009126 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9127 }
9128
9129 final long identity = Binder.clearCallingIdentity();
9130 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009131 try {
9132 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9133 } catch (NoSuchElementException ex) {
9134 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9135 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009136 } finally {
9137 Binder.restoreCallingIdentity(identity);
9138 }
9139 }
9140
Michelecea4cf22018-12-21 15:00:11 -08009141 @Override
Michele0ea7d782019-03-19 14:58:42 -07009142 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009143 enforceModifyPermission();
9144
9145 final long identity = Binder.clearCallingIdentity();
9146 try {
9147 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009148 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009149 .commit();
9150 } finally {
9151 Binder.restoreCallingIdentity(identity);
9152 }
9153 }
9154
9155 @Override
Michele0ea7d782019-03-19 14:58:42 -07009156 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009157 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009159 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9160 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009161 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009162 }
Michelecea4cf22018-12-21 15:00:11 -08009163
9164 final long identity = Binder.clearCallingIdentity();
9165 try {
Michele0ea7d782019-03-19 14:58:42 -07009166 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009167 } finally {
9168 Binder.restoreCallingIdentity(identity);
9169 }
9170 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009171
Michele0ea7d782019-03-19 14:58:42 -07009172 @TelephonyManager.IsMultiSimSupportedResult
9173 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009174 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9175 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9176 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009177 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9178 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009179 }
9180 // Check if the hardware supports multisim functionality. If usage of multisim is not
9181 // supported by the modem, indicate that it is restricted.
9182 PhoneCapability staticCapability =
9183 mPhoneConfigurationManager.getStaticPhoneCapability();
9184 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009185 loge("isMultiSimSupportedInternal: no static configuration available");
9186 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009187 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009188 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009189 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9190 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009191 }
9192 // Check if support of multiple SIMs is restricted by carrier
9193 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009194 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009195 }
9196
Michele0ea7d782019-03-19 14:58:42 -07009197 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009198 }
9199
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009200 /**
9201 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009202 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9203 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9204 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009205 * @param numOfSims number of active sims we want to switch to
9206 */
9207 @Override
9208 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009209 if (numOfSims == 1) {
9210 enforceModifyPermission();
9211 } else {
9212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9213 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9214 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009215 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009216
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009217 try {
Michele30b57b22019-03-01 12:01:14 -08009218 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009219 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009220 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9221 return;
9222 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009223 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9224 } finally {
9225 Binder.restoreCallingIdentity(identity);
9226 }
9227 }
9228
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009229 @Override
9230 public boolean isApplicationOnUicc(int subId, int appType) {
9231 enforceReadPrivilegedPermission("isApplicationOnUicc");
9232 Phone phone = getPhone(subId);
9233 if (phone == null) {
9234 return false;
9235 }
9236 final long identity = Binder.clearCallingIdentity();
9237 try {
9238 UiccCard uiccCard = phone.getUiccCard();
9239 if (uiccCard == null) {
9240 return false;
9241 }
9242 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9243 if (uiccProfile == null) {
9244 return false;
9245 }
9246 if (TelephonyManager.APPTYPE_SIM <= appType
9247 && appType <= TelephonyManager.APPTYPE_ISIM) {
9248 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9249 }
9250 return false;
9251 } finally {
9252 Binder.restoreCallingIdentity(identity);
9253 }
9254 }
9255
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009256 /**
chen xub4baa772019-04-03 10:23:41 -07009257 * Get whether making changes to modem configurations will trigger reboot.
9258 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009259 */
9260 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009261 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9262 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009264 mApp, subId, callingPackage, callingFeatureId,
9265 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009266 return false;
9267 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009268 final long identity = Binder.clearCallingIdentity();
9269 try {
9270 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9271 } finally {
9272 Binder.restoreCallingIdentity(identity);
9273 }
9274 }
9275
Nathan Harold29f5f052019-02-15 13:41:57 -08009276 private void updateModemStateMetrics() {
9277 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9278 // TODO: check the state for each modem if the api is ready.
9279 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9280 }
9281
Pengquan Meng3889a572019-01-23 11:16:29 -08009282 @Override
9283 public int[] getSlotsMapping() {
9284 enforceReadPrivilegedPermission("getSlotsMapping");
9285
9286 final long identity = Binder.clearCallingIdentity();
9287 try {
9288 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9289 // All logical slots should have a mapping to a physical slot.
9290 int[] logicalSlotsMapping = new int[phoneCount];
9291 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9292 for (int i = 0; i < slotInfos.length; i++) {
9293 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9294 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9295 }
9296 }
9297 return logicalSlotsMapping;
9298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009302
9303 /**
9304 * Get the IRadio HAL Version
9305 */
9306 @Override
9307 public int getRadioHalVersion() {
9308 Phone phone = getDefaultPhone();
9309 if (phone == null) return -1;
9310 HalVersion hv = phone.getHalVersion();
9311 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9312 return hv.major * 100 + hv.minor;
9313 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009314
9315 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009316 * Get the current calling package name.
9317 * @return the current calling package name
9318 */
9319 @Override
9320 public String getCurrentPackageName() {
9321 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9322 }
9323
9324 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009325 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9326 * corresponding network requests on a subId.
9327 *
9328 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009329 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009330 * 2) APN is un-metered for this subscription, or
9331 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009332 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009333 *
9334 * @return whether data is allowed for a apn type.
9335 *
9336 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009337 */
9338 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009339 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009340 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9341 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009342
9343 // Now that all security checks passes, perform the operation as ourselves.
9344 final long identity = Binder.clearCallingIdentity();
9345 try {
9346 Phone phone = getPhone(subId);
9347 if (phone == null) return false;
9348
Jack Yu41407ee2019-05-13 16:54:09 -07009349 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009350 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9351 } finally {
9352 Binder.restoreCallingIdentity(identity);
9353 }
9354 }
9355
9356 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009357 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009358 enforceReadPrivilegedPermission("isApnMetered");
9359
9360 // Now that all security checks passes, perform the operation as ourselves.
9361 final long identity = Binder.clearCallingIdentity();
9362 try {
9363 Phone phone = getPhone(subId);
9364 if (phone == null) return true; // By default return true.
9365
Jack Yu41407ee2019-05-13 16:54:09 -07009366 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009367 } finally {
9368 Binder.restoreCallingIdentity(identity);
9369 }
9370 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009371
9372 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009373 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9374 int subscriptionId, IBooleanConsumer resultCallback) {
9375 enforceModifyPermission();
9376 long token = Binder.clearCallingIdentity();
9377 try {
9378 Phone phone = getPhone(subscriptionId);
9379 if (phone == null) {
9380 try {
9381 if (resultCallback != null) {
9382 resultCallback.accept(false);
9383 }
9384 } catch (RemoteException e) {
9385 // ignore
9386 }
9387 return;
9388 }
9389 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9390 Pair.create(specifiers, (x) -> {
9391 try {
9392 if (resultCallback != null) {
9393 resultCallback.accept(x);
9394 }
9395 } catch (RemoteException e) {
9396 // ignore
9397 }
9398 });
9399 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9400 } finally {
9401 Binder.restoreCallingIdentity(token);
9402 }
9403 }
9404
9405 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009406 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9407 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009408 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009409 mApp, subId, "getSystemSelectionChannels");
9410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9411 final long identity = Binder.clearCallingIdentity();
9412 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009413 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9414 if (result instanceof IllegalStateException) {
9415 throw (IllegalStateException) result;
9416 }
9417 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009418 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9419 return specifiers;
9420 } finally {
9421 Binder.restoreCallingIdentity(identity);
9422 }
9423 }
9424
9425 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009426 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009427 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009428 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9429 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9430 if (iccRecords == null) {
9431 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9432 return false;
9433 }
9434 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9435 }
9436
9437 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009438 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9439 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009440 if (callingPackage == null) {
9441 callingPackage = getCurrentPackageName();
9442 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009443 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9444 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009445 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9446 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009447 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9448 }
9449 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9450 Intent intent = new Intent();
9451 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9452 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9453 // Bring up choose default SMS subscription dialog right now
9454 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9455 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9456 mApp.startActivity(intent);
9457 }
chen xud5ca2d52019-05-28 15:20:57 -07009458
9459 @Override
9460 public String getMmsUAProfUrl(int subId) {
9461 //TODO investigate if this API should require proper permission check in R b/133791609
9462 final long identity = Binder.clearCallingIdentity();
9463 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009464 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9465 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9466 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9467 return carrierUAProfUrl;
9468 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009469 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9470 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009471 } finally {
9472 Binder.restoreCallingIdentity(identity);
9473 }
9474 }
9475
9476 @Override
9477 public String getMmsUserAgent(int subId) {
9478 //TODO investigate if this API should require proper permission check in R b/133791609
9479 final long identity = Binder.clearCallingIdentity();
9480 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009481 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9482 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9483 if (!TextUtils.isEmpty(carrierUserAgent)) {
9484 return carrierUserAgent;
9485 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009486 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9487 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009488 } finally {
9489 Binder.restoreCallingIdentity(identity);
9490 }
9491 }
Jack Yub07d4972019-05-28 16:12:25 -07009492
9493 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009494 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9495 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009496
Jack Yub07d4972019-05-28 16:12:25 -07009497 final long identity = Binder.clearCallingIdentity();
9498 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009499 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009500 if (phone == null) return false;
9501
Hall Liua62f5da2020-09-25 10:42:19 -07009502 switch (policy) {
9503 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9504 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9505 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9506 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9507 default:
9508 throw new IllegalArgumentException(policy + " is not a valid policy");
9509 }
Jack Yub07d4972019-05-28 16:12:25 -07009510 } finally {
9511 Binder.restoreCallingIdentity(identity);
9512 }
9513 }
9514
9515 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009516 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009517 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009518 enforceModifyPermission();
9519
changbettyd5c246e2019-12-24 15:40:37 +08009520 final long identity = Binder.clearCallingIdentity();
9521 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009522 Phone phone = getPhone(subscriptionId);
9523 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009524
Hall Liua62f5da2020-09-25 10:42:19 -07009525 switch (policy) {
9526 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9527 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9528 break;
9529 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9530 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9531 break;
9532 default:
9533 throw new IllegalArgumentException(policy + " is not a valid policy");
9534 }
changbettyd5c246e2019-12-24 15:40:37 +08009535 } finally {
9536 Binder.restoreCallingIdentity(identity);
9537 }
9538 }
9539
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009540 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009541 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009542 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9543 * otherwise.
9544 */
9545 @Override
9546 public void setCepEnabled(boolean isCepEnabled) {
9547 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9548
9549 final long identity = Binder.clearCallingIdentity();
9550 try {
9551 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9552 for (Phone phone : PhoneFactory.getPhones()) {
9553 Phone defaultPhone = phone.getImsPhone();
9554 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9555 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9556 ImsPhoneCallTracker imsPhoneCallTracker =
9557 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9558 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9559 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9560 + imsPhone.getMsisdn());
9561 }
9562 }
9563 } finally {
9564 Binder.restoreCallingIdentity(identity);
9565 }
9566 }
allenwtsu46dcc572020-01-08 18:24:03 +08009567
9568 /**
9569 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9570 *
9571 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9572 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9573 * before being read.
9574 */
9575 @Override
9576 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9577 isCompressed) {
9578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9579 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009580 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9581 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9582 }
9583 if (!isImsAvailableOnDevice()) {
9584 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9585 "IMS not available on device.");
9586 }
9587
9588 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009589 try {
Hui Wang761a6682020-10-31 05:12:53 +00009590 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9591 } finally {
9592 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009593 }
9594 }
zoey chene02881a2019-12-30 16:11:23 +08009595
9596 @Override
9597 public boolean isIccLockEnabled(int subId) {
9598 enforceReadPrivilegedPermission("isIccLockEnabled");
9599
9600 // Now that all security checks passes, perform the operation as ourselves.
9601 final long identity = Binder.clearCallingIdentity();
9602 try {
9603 Phone phone = getPhone(subId);
9604 if (phone != null && phone.getIccCard() != null) {
9605 return phone.getIccCard().getIccLockEnabled();
9606 } else {
9607 return false;
9608 }
9609 } finally {
9610 Binder.restoreCallingIdentity(identity);
9611 }
9612 }
9613
9614 /**
9615 * Set the ICC pin lock enabled or disabled.
9616 *
9617 * @return an integer representing the status of IccLock enabled or disabled in the following
9618 * three cases:
9619 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9620 * successfully.
9621 * - Positive number and zero for remaining password attempts.
9622 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9623 *
9624 */
9625 @Override
9626 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9627 enforceModifyPermission();
9628
9629 Phone phone = getPhone(subId);
9630 if (phone == null) {
9631 return 0;
9632 }
9633 // Now that all security checks passes, perform the operation as ourselves.
9634 final long identity = Binder.clearCallingIdentity();
9635 try {
9636 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9637 new Pair<Boolean, String>(enabled, password), phone, null);
9638 return attemptsRemaining;
9639
9640 } catch (Exception e) {
9641 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9642 } finally {
9643 Binder.restoreCallingIdentity(identity);
9644 }
9645 return 0;
9646 }
9647
9648 /**
9649 * Change the ICC password used in ICC pin lock.
9650 *
9651 * @return an integer representing the status of IccLock changed in the following three cases:
9652 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9653 * - Positive number and zero for remaining password attempts.
9654 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9655 *
9656 */
9657 @Override
9658 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9659 enforceModifyPermission();
9660
9661 Phone phone = getPhone(subId);
9662 if (phone == null) {
9663 return 0;
9664 }
9665 // Now that all security checks passes, perform the operation as ourselves.
9666 final long identity = Binder.clearCallingIdentity();
9667 try {
9668 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9669 new Pair<String, String>(oldPassword, newPassword), phone, null);
9670 return attemptsRemaining;
9671
9672 } catch (Exception e) {
9673 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9674 } finally {
9675 Binder.restoreCallingIdentity(identity);
9676 }
9677 return 0;
9678 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009679
9680 /**
9681 * Request for receiving user activity notification
9682 */
9683 @Override
9684 public void requestUserActivityNotification() {
9685 if (!mNotifyUserActivity.get()
9686 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9687 mNotifyUserActivity.set(true);
9688 }
9689 }
9690
9691 /**
9692 * Called when userActivity is signalled in the power manager.
9693 * This is safe to call from any thread, with any window manager locks held or not.
9694 */
9695 @Override
9696 public void userActivity() {
9697 // ***************************************
9698 // * Inherited from PhoneWindowManager *
9699 // ***************************************
9700 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9701 // WITH ITS LOCKS HELD.
9702 //
9703 // This code must be VERY careful about the locks
9704 // it acquires.
9705 // In fact, the current code acquires way too many,
9706 // and probably has lurking deadlocks.
9707
9708 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9709 throw new SecurityException("Only the OS may call notifyUserActivity()");
9710 }
9711
9712 if (mNotifyUserActivity.getAndSet(false)) {
9713 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9714 USER_ACTIVITY_NOTIFICATION_DELAY);
9715 }
9716 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009717
9718 @Override
9719 public boolean canConnectTo5GInDsdsMode() {
9720 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9721 }
Jack Yud10cdd42020-09-28 20:28:01 -07009722
9723 @Override
9724 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9725 String callingFeatureId) {
9726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9727 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9728 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9729 }
9730
9731 Phone phone = getPhone(subId);
9732 if (phone == null) {
9733 throw new RuntimeException("phone is not available");
9734 }
9735 // Now that all security checks passes, perform the operation as ourselves.
9736 final long identity = Binder.clearCallingIdentity();
9737 try {
9738 return phone.getEquivalentHomePlmns();
9739 } finally {
9740 Binder.restoreCallingIdentity(identity);
9741 }
9742 }
Daniel Bright59e67312020-11-13 11:49:37 -08009743
9744 @Override
9745 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009746 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9747 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009748 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009749 if (radioInterfaceCapabilities == null) {
9750 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009751 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009752 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009753 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009754
Hui Wang641e81c2020-10-12 12:14:23 -07009755 @Override
9756 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9757 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009758 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9759 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9760 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9761 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9762 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009763 if (DBG) {
9764 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9765 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9766 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9767 }
9768
9769 if (!SubscriptionManager.isValidSubscriptionId(subId)
9770 || appType < TelephonyManager.APPTYPE_UNKNOWN
9771 || appType > TelephonyManager.APPTYPE_ISIM
9772 || nafUrl == null || securityProtocol == null || callback == null) {
9773 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9774 if (callback != null) {
9775 try {
9776 callback.onAuthenticationFailure(
9777 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9778 } catch (RemoteException exception) {
9779 log("Fail to notify onAuthenticationFailure due to " + exception);
9780 }
9781 return;
9782 }
9783 }
9784
9785 final long token = Binder.clearCallingIdentity();
9786 try {
9787 getGbaManager(subId).bootstrapAuthenticationRequest(
9788 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9789 forceBootStrapping, callback));
9790 } finally {
9791 Binder.restoreCallingIdentity(token);
9792 }
9793 }
9794
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009795 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009796 * Attempts to set the radio power state for all phones for thermal reason.
9797 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009798 * requested radio power state will actually be set. See {@link
9799 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9800 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009801 * @param enable {@code true} if trying to turn radio on.
9802 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9803 * false}.
9804 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009805 private boolean setRadioPowerForThermal(boolean enable) {
9806 boolean isPhoneAvailable = false;
9807 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9808 Phone phone = PhoneFactory.getPhone(i);
9809 if (phone != null) {
9810 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9811 isPhoneAvailable = true;
9812 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009813 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009814
9815 // return true if successfully informed the phone object about the thermal radio power
9816 // request.
9817 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009818 }
9819
9820 private int handleDataThrottlingRequest(int subId,
9821 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009822 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9823 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9824 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9825 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9826 throw new IllegalArgumentException("modem does not support data throttling");
9827 }
9828
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009829 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9830 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009831 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009832 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9833 }
9834
9835 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9836
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009837 if (isDataThrottlingSupported) {
9838 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009839 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009840 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9841 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9842 } else if (thermalMitigationResult
9843 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009844 log("Modem likely does not support data throttling on secondary carrier. Data " +
9845 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9846 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009847 }
9848 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009849 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009850
9851 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009852 }
9853
Jack Nudelman644b91a2021-03-12 14:09:48 -08009854 private static List<String> getThermalMitigationAllowlist(Context context) {
9855 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9856 for (String pckg : context.getResources()
9857 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9858 sThermalMitigationAllowlistedPackages.add(pckg);
9859 }
9860 }
9861
9862 return sThermalMitigationAllowlistedPackages;
9863 }
9864
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009865 private boolean isAnyPhoneInEmergencyState() {
9866 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9867 if (tm.isInEmergencyCall()) {
9868 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9869 return true;
9870 }
9871 for (Phone phone : PhoneFactory.getPhones()) {
9872 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9873 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9874 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9875 + phone.isInEcm());
9876 return true;
9877 }
9878 }
9879
9880 return false;
9881 }
9882
Jack Nudelman644b91a2021-03-12 14:09:48 -08009883 /**
9884 * Used by shell commands to add an authorized package name for thermal mitigation.
9885 * @param packageName name of package to be allowlisted
9886 * @param context
9887 */
9888 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9889 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9890 sThermalMitigationAllowlistedPackages.add(packageName);
9891 }
9892
9893 /**
9894 * Used by shell commands to remove an authorized package name for thermal mitigation.
9895 * @param packageName name of package to remove from allowlist
9896 * @param context
9897 */
9898 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9899 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9900 sThermalMitigationAllowlistedPackages.remove(packageName);
9901 }
9902
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009903 /**
9904 * Thermal mitigation request to control functionalities at modem.
9905 *
9906 * @param subId the id of the subscription.
9907 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009908 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009909 *
9910 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9911 */
9912 @Override
9913 @ThermalMitigationResult
9914 public int sendThermalMitigationRequest(
9915 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009916 ThermalMitigationRequest thermalMitigationRequest,
9917 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009918 enforceModifyPermission();
9919
Jack Nudelman644b91a2021-03-12 14:09:48 -08009920 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9921 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9922 .contains(callingPackage)) {
9923 throw new SecurityException("Calling package must be configured in the device config. "
9924 + "calling package: " + callingPackage);
9925 }
9926
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009927 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9928 final long identity = Binder.clearCallingIdentity();
9929
9930 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9931 try {
9932 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9933 switch (thermalMitigationAction) {
9934 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9935 thermalMitigationResult =
9936 handleDataThrottlingRequest(subId,
9937 thermalMitigationRequest.getDataThrottlingRequest());
9938 break;
9939 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9940 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9941 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9942 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9943 }
9944
9945 // Ensure that radio is on. If not able to power on due to phone being
9946 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009947 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009948 thermalMitigationResult =
9949 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9950 break;
9951 }
9952
9953 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9954 false);
9955 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9956 break;
9957 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9958 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9959 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9960 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9961 }
9962
9963 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9964 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009965 Phone phone = getPhone(subId);
9966 if (phone == null) {
9967 thermalMitigationResult =
9968 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9969 break;
9970 }
9971
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009972 TelephonyConnectionService service =
9973 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -07009974 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009975 Log.e(LOG_TAG, "An emergency call is pending");
9976 thermalMitigationResult =
9977 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9978 break;
9979 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009980 thermalMitigationResult =
9981 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9982 break;
9983 }
9984 } else {
9985 thermalMitigationResult =
9986 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9987 break;
9988 }
9989
9990 // Turn radio off. If not able to power off due to phone being unavailable,
9991 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009992 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009993 thermalMitigationResult =
9994 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9995 break;
9996 }
9997 thermalMitigationResult =
9998 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9999 break;
10000 default:
10001 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10002 + "not exist. Requested action: " + thermalMitigationAction);
10003 }
10004 } catch (IllegalArgumentException e) {
10005 throw e;
10006 } catch (Exception e) {
10007 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10008 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10009 } finally {
10010 Binder.restoreCallingIdentity(identity);
10011 }
10012
10013 if (DBG) {
10014 log("thermalMitigationRequest returning with thermalMitigationResult: "
10015 + thermalMitigationResult);
10016 }
10017
10018 return thermalMitigationResult;
10019 }
Hui Wang641e81c2020-10-12 12:14:23 -070010020
10021 /**
10022 * Set the GbaService Package Name that Telephony will bind to.
10023 *
10024 * @param subId The sim that the GbaService is associated with.
10025 * @param packageName The name of the package to be replaced with.
10026 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10027 */
10028 @Override
10029 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10030 enforceModifyPermission();
10031
10032 final long identity = Binder.clearCallingIdentity();
10033 try {
10034 return getGbaManager(subId).overrideServicePackage(packageName);
10035 } finally {
10036 Binder.restoreCallingIdentity(identity);
10037 }
10038 }
10039
10040 /**
10041 * Return the package name of the currently bound GbaService.
10042 *
10043 * @param subId The sim that the GbaService is associated with.
10044 * @return the package name of the GbaService configuration, null if GBA is not supported.
10045 */
10046 @Override
10047 public String getBoundGbaService(int subId) {
10048 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10049
10050 final long identity = Binder.clearCallingIdentity();
10051 try {
10052 return getGbaManager(subId).getServicePackage();
10053 } finally {
10054 Binder.restoreCallingIdentity(identity);
10055 }
10056 }
10057
10058 /**
10059 * Set the release time for telephony to unbind GbaService.
10060 *
10061 * @param subId The sim that the GbaService is associated with.
10062 * @param interval The release time to unbind GbaService by millisecond.
10063 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10064 */
10065 @Override
10066 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10067 enforceModifyPermission();
10068
10069 final long identity = Binder.clearCallingIdentity();
10070 try {
10071 return getGbaManager(subId).overrideReleaseTime(interval);
10072 } finally {
10073 Binder.restoreCallingIdentity(identity);
10074 }
10075 }
10076
10077 /**
10078 * Return the release time for telephony to unbind GbaService.
10079 *
10080 * @param subId The sim that the GbaService is associated with.
10081 * @return The release time to unbind GbaService by millisecond.
10082 */
10083 @Override
10084 public int getGbaReleaseTime(int subId) {
10085 enforceReadPrivilegedPermission("getGbaReleaseTime");
10086
10087 final long identity = Binder.clearCallingIdentity();
10088 try {
10089 return getGbaManager(subId).getReleaseTime();
10090 } finally {
10091 Binder.restoreCallingIdentity(identity);
10092 }
10093 }
10094
10095 private GbaManager getGbaManager(int subId) {
10096 GbaManager instance = GbaManager.getInstance(subId);
10097 if (instance == null) {
10098 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10099 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10100 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10101 }
10102 return instance;
10103 }
Hui Wang761a6682020-10-31 05:12:53 +000010104
10105 /**
10106 * indicate whether the device and the carrier can support
10107 * RCS VoLTE single registration.
10108 */
10109 @Override
10110 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010111 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10112 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10113 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10114 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010115
10116 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10117 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10118 }
10119
10120 final long identity = Binder.clearCallingIdentity();
10121 try {
10122 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10123 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010124 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10125 if (isCapable != null) {
10126 return isCapable;
10127 }
Hui Wang761a6682020-10-31 05:12:53 +000010128 }
Hui Wang67af90e2021-06-04 16:57:15 -070010129 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10130 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010131 } finally {
10132 Binder.restoreCallingIdentity(identity);
10133 }
10134 }
10135
10136 /**
10137 * Register RCS provisioning callback.
10138 */
10139 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010140 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010141 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010142 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010143 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010144 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10145 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010146
10147 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10148 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10149 }
10150 if (!isImsAvailableOnDevice()) {
10151 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10152 "IMS not available on device.");
10153 }
10154
10155 final long identity = Binder.clearCallingIdentity();
10156 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010157 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010158 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010159 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10160 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010161 }
Hui Wang761a6682020-10-31 05:12:53 +000010162 } finally {
10163 Binder.restoreCallingIdentity(identity);
10164 }
10165 }
10166
10167 /**
10168 * Unregister RCS provisioning callback.
10169 */
10170 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010171 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010172 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010173 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010174 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010175 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10176 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010177
10178 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10179 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10180 }
10181 if (!isImsAvailableOnDevice()) {
10182 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10183 "IMS not available on device.");
10184 }
10185
10186 final long identity = Binder.clearCallingIdentity();
10187 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010188 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010189 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010190 } finally {
10191 Binder.restoreCallingIdentity(identity);
10192 }
10193 }
10194
10195 /**
10196 * trigger RCS reconfiguration.
10197 */
10198 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010199 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10200 "triggerRcsReconfiguration",
10201 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010202
10203 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10204 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10205 }
10206 if (!isImsAvailableOnDevice()) {
10207 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10208 "IMS not available on device.");
10209 }
10210
10211 final long identity = Binder.clearCallingIdentity();
10212 try {
10213 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10214 } finally {
10215 Binder.restoreCallingIdentity(identity);
10216 }
10217 }
10218
10219 /**
10220 * Provide the client configuration parameters of the RCS application.
10221 */
10222 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010223 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10224 "setRcsClientConfiguration",
10225 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010226
10227 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10228 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10229 }
10230 if (!isImsAvailableOnDevice()) {
10231 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10232 "IMS not available on device.");
10233 }
10234
10235 final long identity = Binder.clearCallingIdentity();
10236
10237 try {
10238 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10239 if (configBinder == null) {
10240 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010241 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10242 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010243 } else {
10244 configBinder.setRcsClientConfiguration(rcc);
10245 }
10246 } catch (RemoteException e) {
10247 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010248 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10249 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010250 } finally {
10251 Binder.restoreCallingIdentity(identity);
10252 }
10253 }
10254
10255 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010256 * Enables or disables the test mode for RCS VoLTE single registration.
10257 */
10258 @Override
10259 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10260 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10261 "setRcsSingleRegistrationTestModeEnabled");
10262
10263 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10264 }
10265
10266 /**
10267 * Gets the test mode for RCS VoLTE single registration.
10268 */
10269 @Override
10270 public boolean getRcsSingleRegistrationTestModeEnabled() {
10271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10272 "getRcsSingleRegistrationTestModeEnabled");
10273
10274 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10275 }
10276
10277 /**
Hui Wang761a6682020-10-31 05:12:53 +000010278 * Overrides the config of RCS VoLTE single registration enabled for the device.
10279 */
10280 @Override
10281 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10282 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10283 "setDeviceSingleRegistrationEnabledOverride");
10284 enforceModifyPermission();
10285
10286 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10287 : Boolean.parseBoolean(enabledStr);
10288 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010289 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010290 }
10291
10292 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010293 * Sends a device to device communication message. Only usable via shell.
10294 * @param message message to send.
10295 * @param value message value.
10296 */
10297 @Override
10298 public void sendDeviceToDeviceMessage(int message, int value) {
10299 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010300 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010301 enforceModifyPermission();
10302
10303 final long identity = Binder.clearCallingIdentity();
10304 try {
10305 TelephonyConnectionService service =
10306 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10307 if (service == null) {
10308 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10309 return;
10310 }
10311 service.sendTestDeviceToDeviceMessage(message, value);
10312 } finally {
10313 Binder.restoreCallingIdentity(identity);
10314 }
10315 }
10316
Tyler Gunnbabbda02021-02-10 11:05:02 -080010317 /**
10318 * Sets the specified device to device transport active.
10319 * @param transport The transport to set active.
10320 */
10321 @Override
10322 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10323 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10324 "setActiveDeviceToDeviceTransport");
10325 enforceModifyPermission();
10326
10327 final long identity = Binder.clearCallingIdentity();
10328 try {
10329 TelephonyConnectionService service =
10330 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10331 if (service == null) {
10332 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10333 return;
10334 }
10335 service.setActiveDeviceToDeviceTransport(transport);
10336 } finally {
10337 Binder.restoreCallingIdentity(identity);
10338 }
10339 }
Tyler Gunn92479152021-01-20 16:30:10 -080010340
Tyler Gunnd4575212021-05-03 14:46:49 -070010341 @Override
10342 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10343 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10344 "setDeviceToDeviceForceEnabled");
10345
10346 final long identity = Binder.clearCallingIdentity();
10347 try {
10348 Arrays.stream(PhoneFactory.getPhones()).forEach(
10349 p -> {
10350 Phone thePhone = p.getImsPhone();
10351 if (thePhone != null && thePhone instanceof ImsPhone) {
10352 ImsPhone imsPhone = (ImsPhone) thePhone;
10353 CallTracker tracker = imsPhone.getCallTracker();
10354 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10355 ImsPhoneCallTracker imsPhoneCallTracker =
10356 (ImsPhoneCallTracker) tracker;
10357 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10358 }
10359 }
10360 }
10361 );
10362 } finally {
10363 Binder.restoreCallingIdentity(identity);
10364 }
10365 }
10366
Tyler Gunn92479152021-01-20 16:30:10 -080010367 /**
Hui Wang761a6682020-10-31 05:12:53 +000010368 * Gets the config of RCS VoLTE single registration enabled for the device.
10369 */
10370 @Override
10371 public boolean getDeviceSingleRegistrationEnabled() {
10372 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10373 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10374 }
10375
10376 /**
10377 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10378 */
10379 @Override
10380 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10381 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10382 "setCarrierSingleRegistrationEnabledOverride");
10383 enforceModifyPermission();
10384
10385 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10386 : Boolean.parseBoolean(enabledStr);
10387 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10388 subId, enabled);
10389 }
10390
10391 /**
10392 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10393 */
10394 @Override
10395 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10396 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10397 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10398 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010399
10400 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010401 * Overrides the ims feature validation result
10402 */
10403 @Override
10404 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10405 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10406 "setImsFeatureValidationOverride");
10407
10408 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10409 : Boolean.parseBoolean(enabledStr);
10410 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10411 subId, enabled);
10412 }
10413
10414 /**
10415 * Gets the ims feature validation override value
10416 */
10417 @Override
10418 public boolean getImsFeatureValidationOverride(int subId) {
10419 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10420 "getImsFeatureValidationOverride");
10421 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10422 }
10423
10424 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010425 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10426 * their mobile plan.
10427 */
10428 @Override
10429 public String getMobileProvisioningUrl() {
10430 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10431 final long identity = Binder.clearCallingIdentity();
10432 try {
10433 return getDefaultPhone().getMobileProvisioningUrl();
10434 } finally {
10435 Binder.restoreCallingIdentity(identity);
10436 }
10437 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010438
James.cf Linbcdf8b32021-01-14 16:44:13 +080010439 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010440 * Get the EAB contact from the EAB database.
10441 */
10442 @Override
10443 public String getContactFromEab(String contact) {
10444 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10445 enforceModifyPermission();
10446 final long identity = Binder.clearCallingIdentity();
10447 try {
10448 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10449 } finally {
10450 Binder.restoreCallingIdentity(identity);
10451 }
10452 }
10453
10454 /**
Calvin Pana1434322021-07-01 19:27:01 +080010455 * Get the EAB capability from the EAB database.
10456 */
10457 @Override
10458 public String getCapabilityFromEab(String contact) {
10459 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10460 enforceModifyPermission();
10461 final long identity = Binder.clearCallingIdentity();
10462 try {
10463 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10464 } finally {
10465 Binder.restoreCallingIdentity(identity);
10466 }
10467 }
10468
10469 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010470 * Remove the EAB contacts from the EAB database.
10471 */
10472 @Override
10473 public int removeContactFromEab(int subId, String contacts) {
10474 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10475 enforceModifyPermission();
10476 final long identity = Binder.clearCallingIdentity();
10477 try {
10478 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10479 } finally {
10480 Binder.restoreCallingIdentity(identity);
10481 }
10482 }
10483
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010484 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010485 public boolean getDeviceUceEnabled() {
10486 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10487 final long identity = Binder.clearCallingIdentity();
10488 try {
10489 return mApp.getDeviceUceEnabled();
10490 } finally {
10491 Binder.restoreCallingIdentity(identity);
10492 }
10493 }
10494
10495 @Override
10496 public void setDeviceUceEnabled(boolean isEnabled) {
10497 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10498 final long identity = Binder.clearCallingIdentity();
10499 try {
10500 mApp.setDeviceUceEnabled(isEnabled);
10501 } finally {
10502 Binder.restoreCallingIdentity(identity);
10503 }
10504 }
10505
Brad Ebinger14d467f2021-02-12 06:18:28 +000010506 /**
10507 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10508 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10509 */
10510 // Used for SHELL command only right now.
10511 @Override
10512 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10513 List<String> featureTags) {
10514 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10515 "addUceRegistrationOverrideShell");
10516 final long identity = Binder.clearCallingIdentity();
10517 try {
10518 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10519 new ArraySet<>(featureTags));
10520 } catch (ImsException e) {
10521 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10522 } finally {
10523 Binder.restoreCallingIdentity(identity);
10524 }
10525 }
10526
10527 /**
10528 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10529 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10530 */
10531 // Used for SHELL command only right now.
10532 @Override
10533 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10534 List<String> featureTags) {
10535 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10536 "removeUceRegistrationOverrideShell");
10537 final long identity = Binder.clearCallingIdentity();
10538 try {
10539 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10540 new ArraySet<>(featureTags));
10541 } catch (ImsException e) {
10542 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10543 } finally {
10544 Binder.restoreCallingIdentity(identity);
10545 }
10546 }
10547
10548 /**
10549 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10550 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10551 */
10552 // Used for SHELL command only right now.
10553 @Override
10554 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10555 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10556 "clearUceRegistrationOverrideShell");
10557 final long identity = Binder.clearCallingIdentity();
10558 try {
10559 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10560 } catch (ImsException e) {
10561 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10562 } finally {
10563 Binder.restoreCallingIdentity(identity);
10564 }
10565 }
10566
10567 /**
10568 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10569 */
10570 // Used for SHELL command only right now.
10571 @Override
10572 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10573 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10574 "getLatestRcsContactUceCapabilityShell");
10575 final long identity = Binder.clearCallingIdentity();
10576 try {
10577 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10578 } catch (ImsException e) {
10579 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10580 } finally {
10581 Binder.restoreCallingIdentity(identity);
10582 }
10583 }
10584
10585 /**
10586 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10587 * device does not have an active PUBLISH.
10588 */
10589 // Used for SHELL command only right now.
10590 @Override
10591 public String getLastUcePidfXmlShell(int subId) {
10592 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10593 final long identity = Binder.clearCallingIdentity();
10594 try {
10595 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10596 } catch (ImsException e) {
10597 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10598 } finally {
10599 Binder.restoreCallingIdentity(identity);
10600 }
10601 }
10602
James.cf Line8713a42021-04-29 16:04:26 +080010603 /**
10604 * Remove UCE requests cannot be sent to the network status.
10605 */
10606 // Used for SHELL command only right now.
10607 @Override
10608 public boolean removeUceRequestDisallowedStatus(int subId) {
10609 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10610 final long identity = Binder.clearCallingIdentity();
10611 try {
10612 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10613 } catch (ImsException e) {
10614 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10615 } finally {
10616 Binder.restoreCallingIdentity(identity);
10617 }
10618 }
10619
James.cf Lin0fc71b02021-05-25 01:37:38 +080010620 /**
10621 * Remove UCE requests cannot be sent to the network status.
10622 */
10623 // Used for SHELL command only.
10624 @Override
10625 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10627 final long identity = Binder.clearCallingIdentity();
10628 try {
10629 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10630 } catch (ImsException e) {
10631 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10632 } finally {
10633 Binder.restoreCallingIdentity(identity);
10634 }
10635 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010636
James.cf Lin4b784aa2021-01-31 03:25:15 +080010637 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010638 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10639 String callingPackage) {
10640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10641 mApp, subId, "setSignalStrengthUpdateRequest");
10642
10643 final int callingUid = Binder.getCallingUid();
10644 // Verify that tha callingPackage belongs to the calling UID
10645 mApp.getSystemService(AppOpsManager.class)
10646 .checkPackage(callingUid, callingPackage);
10647
10648 validateSignalStrengthUpdateRequest(request, callingUid);
10649
10650 final long identity = Binder.clearCallingIdentity();
10651 try {
10652 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10653 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10654
10655 if (result instanceof IllegalStateException) {
10656 throw (IllegalStateException) result;
10657 }
10658 } finally {
10659 Binder.restoreCallingIdentity(identity);
10660 }
10661 }
10662
10663 @Override
10664 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10665 String callingPackage) {
10666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10667 mApp, subId, "clearSignalStrengthUpdateRequest");
10668
10669 final int callingUid = Binder.getCallingUid();
10670 // Verify that tha callingPackage belongs to the calling UID
10671 mApp.getSystemService(AppOpsManager.class)
10672 .checkPackage(callingUid, callingPackage);
10673
10674 final long identity = Binder.clearCallingIdentity();
10675 try {
10676 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10677 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10678
10679 if (result instanceof IllegalStateException) {
10680 throw (IllegalStateException) result;
10681 }
10682 } finally {
10683 Binder.restoreCallingIdentity(identity);
10684 }
10685 }
10686
10687 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10688 int callingUid) {
10689 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10690 // phone/system process do not have further restriction on request
10691 return;
10692 }
10693
10694 // Applications has restrictions on how to use the request:
10695 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10696 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10697 // This is not system caller which has been checked above
10698 throw new IllegalArgumentException(
10699 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10700 }
10701
10702 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10703 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10704 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10705 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10706 || info.isEnabled()) {
10707 throw new IllegalArgumentException(
10708 "Only system can set hide fields in SignalThresholdInfo");
10709 }
10710
10711 // Thresholds length for each RAN need in range. This has been validated in
10712 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10713 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10714 final int[] thresholds = info.getThresholds();
10715 Objects.requireNonNull(thresholds);
10716 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10717 || thresholds.length
10718 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10719 throw new IllegalArgumentException(
10720 "thresholds length is out of range: " + thresholds.length);
10721 }
10722 }
10723 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010724
10725 /**
10726 * Gets the current phone capability.
10727 *
10728 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10729 * @return the PhoneCapability which describes the data connection capability of modem.
10730 * It's used to evaluate possible phone config change, for example from single
10731 * SIM device to multi-SIM device.
10732 */
10733 @Override
10734 public PhoneCapability getPhoneCapability() {
10735 enforceReadPrivilegedPermission("getPhoneCapability");
10736 final long identity = Binder.clearCallingIdentity();
10737 try {
10738 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10739 } finally {
10740 Binder.restoreCallingIdentity(identity);
10741 }
10742 }
Michele Berionne5e411512020-11-13 02:36:59 +000010743
10744 /**
10745 * Prepare TelephonyManager for an unattended reboot. The reboot is
10746 * required to be done shortly after the API is invoked.
10747 */
10748 @Override
10749 @TelephonyManager.PrepareUnattendedRebootResult
10750 public int prepareForUnattendedReboot() {
10751 enforceRebootPermission();
10752
10753 final long identity = Binder.clearCallingIdentity();
10754 try {
10755 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10756 } finally {
10757 Binder.restoreCallingIdentity(identity);
10758 }
10759 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010760
10761 /**
10762 * Request to get the current slicing configuration including URSP rules and
10763 * NSSAIs (configured, allowed and rejected).
10764 *
10765 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10766 */
10767 @Override
10768 public void getSlicingConfig(ResultReceiver callback) {
10769 enforceReadPrivilegedPermission("getSlicingConfig");
10770
10771 final long identity = Binder.clearCallingIdentity();
10772 try {
10773 Phone phone = getDefaultPhone();
10774 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010779}