blob: b5c4e0137c4504a8c1473a04cd970b763ca80d08 [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;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700189import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800192import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000193import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800194import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700195import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800197import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800198import com.android.phone.callcomposer.CallComposerPictureManager;
199import com.android.phone.callcomposer.CallComposerPictureTransfer;
200import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700201import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800203import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700205import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800206import com.android.services.telephony.TelecomAccountRegistry;
207import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800208import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800209
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700211import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.IOException;
213import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700214import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800216import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800217import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800218import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800219import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100220import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700222import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800224import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800226import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800227import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229/**
230 * Implementation of the ITelephony interface.
231 */
Santos Cordon117fee72014-05-16 17:56:12 -0700232public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 private static final String LOG_TAG = "PhoneInterfaceManager";
234 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
235 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238 // Message codes used with mMainThreadHandler
239 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700240 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
241 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242 private static final int CMD_OPEN_CHANNEL = 9;
243 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
244 private static final int CMD_CLOSE_CHANNEL = 11;
245 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800246 private static final int CMD_NV_READ_ITEM = 13;
247 private static final int EVENT_NV_READ_ITEM_DONE = 14;
248 private static final int CMD_NV_WRITE_ITEM = 15;
249 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
250 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
251 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700252 private static final int CMD_RESET_MODEM_CONFIG = 19;
253 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800254 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
255 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800256 private static final int CMD_SEND_ENVELOPE = 25;
257 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000258 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
259 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700260 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
261 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
262 private static final int CMD_EXCHANGE_SIM_IO = 31;
263 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800264 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
265 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700266 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
267 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700268 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
269 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700270 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
271 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
272 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
273 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700274 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
275 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
276 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
277 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700278 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800279 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
280 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000281 private static final int CMD_SWITCH_SLOTS = 50;
282 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700283 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
284 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
285 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
286 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
287 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
288 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
289 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
290 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700291 private static final int CMD_GET_ALL_CELL_INFO = 60;
292 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
293 private static final int CMD_GET_CELL_LOCATION = 62;
294 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700295 private static final int CMD_MODEM_REBOOT = 64;
296 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700297 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
298 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800299 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
300 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700301 private static final int CMD_GET_MODEM_STATUS = 70;
302 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700303 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
304 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700305 private static final int CMD_ERASE_MODEM_CONFIG = 74;
306 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800307 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
308 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
309 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
310 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800311 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
312 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800314 private static final int CMD_GET_CALL_FORWARDING = 83;
315 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
316 private static final int CMD_SET_CALL_FORWARDING = 85;
317 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
318 private static final int CMD_GET_CALL_WAITING = 87;
319 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
320 private static final int CMD_SET_CALL_WAITING = 89;
321 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700322 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
323 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
324 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
325 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700326 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
327 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800328 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
329 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800330 private static final int CMD_SET_DATA_THROTTLING = 99;
331 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800332 private static final int CMD_SET_SIM_POWER = 101;
333 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800334 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
335 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
336 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
337 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800338 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
339 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000340 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800341 private static final int CMD_GET_SLICING_CONFIG = 110;
342 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800343 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700344 private static final int CMD_ENABLE_VONR = 113;
345 private static final int EVENT_ENABLE_VONR_DONE = 114;
346 private static final int CMD_IS_VONR_ENABLED = 115;
347 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800349 // Parameters of select command.
350 private static final int SELECT_COMMAND = 0xA4;
351 private static final int SELECT_P1 = 0x04;
352 private static final int SELECT_P2 = 0;
353 private static final int SELECT_P3 = 0x10;
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 /** The singleton instance. */
356 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800357 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800361 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700362 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700364 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800365 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800366 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700368 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800369 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Peter Wangdafb9ac2020-01-15 14:13:38 -0800371 /** User Activity */
372 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
374
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700375 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
376
Derek Tan97ebb422014-09-05 16:55:38 -0700377 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
378 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800379 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800380 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700381
Michelecea4cf22018-12-21 15:00:11 -0800382 // String to store multi SIM allowed
383 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
384
Derek Tan740e1672017-06-27 14:56:27 -0700385 // The AID of ISD-R.
386 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
387
yinxub1bed742017-04-17 11:45:04 -0700388 private NetworkScanRequestTracker mNetworkScanRequestTracker;
389
David Kelly5e06a7f2018-03-12 14:10:59 +0000390 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
391 private static final int MANUFACTURER_CODE_LENGTH = 8;
392
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800393 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800394 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800395
Derek Tan89e89d42014-07-08 17:00:10 -0700396 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700397 * Experiment flag to enable erase modem config on reset network, default value is false
398 */
399 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
400 "reset_network_erase_modem_config_enabled";
401
Rambo Wang0f050d82021-02-12 11:43:36 -0800402 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
403
Naina Nallurid63128d2019-09-17 14:10:30 -0700404 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 * A request object to use for transmitting data to an ICC.
406 */
407 private static final class IccAPDUArgument {
408 public int channel, cla, command, p1, p2, p3;
409 public String data;
410
411 public IccAPDUArgument(int channel, int cla, int command,
412 int p1, int p2, int p3, String data) {
413 this.channel = channel;
414 this.cla = cla;
415 this.command = command;
416 this.p1 = p1;
417 this.p2 = p2;
418 this.p3 = p3;
419 this.data = data;
420 }
421 }
422
423 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700424 * A request object to use for transmitting data to an ICC.
425 */
426 private static final class ManualNetworkSelectionArgument {
427 public OperatorInfo operatorInfo;
428 public boolean persistSelection;
429
430 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
431 this.operatorInfo = operatorInfo;
432 this.persistSelection = persistSelection;
433 }
434 }
435
436 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
438 * request after sending. The main thread will notify the request when it is complete.
439 */
440 private static final class MainThreadRequest {
441 /** The argument to use for the request */
442 public Object argument;
443 /** The result of the request that is run on the main thread */
444 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800445 // The subscriber id that this request applies to. Defaults to
446 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
447 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448
Nathan Harold92bed182018-10-12 18:16:49 -0700449 // In cases where subId is unavailable, the caller needs to specify the phone.
450 public Phone phone;
451
vagdeviaf9a5b92018-08-15 16:01:53 -0700452 public WorkSource workSource;
453
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 public MainThreadRequest(Object argument) {
455 this.argument = argument;
456 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800457
Nathan Harold92bed182018-10-12 18:16:49 -0700458 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
459 this.argument = argument;
460 if (phone != null) {
461 this.phone = phone;
462 }
463 this.workSource = workSource;
464 }
465
vagdeviaf9a5b92018-08-15 16:01:53 -0700466 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800467 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800468 if (subId != null) {
469 this.subId = subId;
470 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700471 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 }
474
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800475 private static final class IncomingThirdPartyCallArgs {
476 public final ComponentName component;
477 public final String callId;
478 public final String callerDisplayName;
479
480 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
481 String callerDisplayName) {
482 this.component = component;
483 this.callId = callId;
484 this.callerDisplayName = callerDisplayName;
485 }
486 }
487
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 /**
489 * A handler that processes messages on the main thread in the phone process. Since many
490 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
491 * inbound binder threads to the main thread in the phone process. The Binder thread
492 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
493 * on, which will be notified when the operation completes and will contain the result of the
494 * request.
495 *
496 * <p>If a MainThreadRequest object is provided in the msg.obj field,
497 * note that request.result must be set to something non-null for the calling thread to
498 * unblock.
499 */
500 private final class MainThreadHandler extends Handler {
501 @Override
502 public void handleMessage(Message msg) {
503 MainThreadRequest request;
504 Message onCompleted;
505 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800508 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509
510 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 case CMD_HANDLE_USSD_REQUEST: {
512 request = (MainThreadRequest) msg.obj;
513 final Phone phone = getPhoneFromRequest(request);
514 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
515 String ussdRequest = ussdObject.first;
516 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700517
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 if (!isUssdApiAllowed(request.subId)) {
519 // Carrier does not support use of this API, return failure.
520 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
521 UssdResponse response = new UssdResponse(ussdRequest, null);
522 Bundle returnData = new Bundle();
523 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
524 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700525
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 request.result = true;
527 notifyRequester(request);
528 return;
529 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700530
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 try {
532 request.result = phone != null
533 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
534 } catch (CallStateException cse) {
535 request.result = false;
536 }
537 // Wake up the requesting thread
538 notifyRequester(request);
539 break;
pkanwar32d516d2016-10-14 19:37:38 -0700540 }
541
Yorke Lee716f67e2015-06-17 15:39:16 -0700542 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 final Phone phone = getPhoneFromRequest(request);
545 request.result = phone != null ?
546 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
547 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("iccTransmitApduLogicalChannel: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
563 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 iccArgument.channel, iccArgument.cla, iccArgument.command,
566 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 break;
570
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 ar = (AsyncResult) msg.obj;
573 request = (MainThreadRequest) ar.userObj;
574 if (ar.exception == null && ar.result != null) {
575 request.result = ar.result;
576 } else {
577 request.result = new IccIoResult(0x6F, 0, (byte[])null);
578 if (ar.result == null) {
579 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800580 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800582 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
584 loge("iccTransmitApduLogicalChannel: Unknown exception");
585 }
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
591 request = (MainThreadRequest) msg.obj;
592 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 if (uiccCard == null) {
595 loge("iccTransmitApduBasicChannel: No UICC");
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 } else {
599 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
600 request);
601 uiccCard.iccTransmitApduBasicChannel(
602 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
603 iccArgument.p3, iccArgument.data, onCompleted);
604 }
605 break;
606
607 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
610 if (ar.exception == null && ar.result != null) {
611 request.result = ar.result;
612 } else {
613 request.result = new IccIoResult(0x6F, 0, (byte[])null);
614 if (ar.result == null) {
615 loge("iccTransmitApduBasicChannel: Empty response");
616 } else if (ar.exception instanceof CommandException) {
617 loge("iccTransmitApduBasicChannel: CommandException: " +
618 ar.exception);
619 } else {
620 loge("iccTransmitApduBasicChannel: Unknown exception");
621 }
622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 break;
625
626 case CMD_EXCHANGE_SIM_IO:
627 request = (MainThreadRequest) msg.obj;
628 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 if (uiccCard == null) {
631 loge("iccExchangeSimIO: No UICC");
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
636 request);
637 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
638 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
639 iccArgument.data, onCompleted);
640 }
641 break;
642
643 case EVENT_EXCHANGE_SIM_IO_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
648 } else {
649 request.result = new IccIoResult(0x6f, 0, (byte[])null);
650 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 break;
653
Derek Tan4d5e5c12014-02-04 11:54:58 -0800654 case CMD_SEND_ENVELOPE:
655 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800656 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 if (uiccCard == null) {
658 loge("sendEnvelopeWithStatus: No UICC");
659 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 } else {
662 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
663 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
664 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800665 break;
666
667 case EVENT_SEND_ENVELOPE_DONE:
668 ar = (AsyncResult) msg.obj;
669 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700670 if (ar.exception == null && ar.result != null) {
671 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800672 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700673 request.result = new IccIoResult(0x6F, 0, (byte[])null);
674 if (ar.result == null) {
675 loge("sendEnvelopeWithStatus: Empty response");
676 } else if (ar.exception instanceof CommandException) {
677 loge("sendEnvelopeWithStatus: CommandException: " +
678 ar.exception);
679 } else {
680 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
681 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 break;
685
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 case CMD_OPEN_CHANNEL:
687 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800688 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800689 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 if (uiccCard == null) {
691 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800692 request.result = new IccOpenLogicalChannelResponse(-1,
693 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800697 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
698 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 break;
701
702 case EVENT_OPEN_CHANNEL_DONE:
703 ar = (AsyncResult) msg.obj;
704 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 int[] result = (int[]) ar.result;
708 int channelId = result[0];
709 byte[] selectResponse = null;
710 if (result.length > 1) {
711 selectResponse = new byte[result.length - 1];
712 for (int i = 1; i < result.length; ++i) {
713 selectResponse[i - 1] = (byte) result[i];
714 }
715 }
716 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700717 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 if (ar.result == null) {
720 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 if (ar.exception != null) {
723 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
724 }
725
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700726 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700727 if (ar.exception instanceof CommandException) {
728 CommandException.Error error =
729 ((CommandException) (ar.exception)).getCommandError();
730 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700731 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700732 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700733 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 }
735 }
736 openChannelResp = new IccOpenLogicalChannelResponse(
737 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700739 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 break;
742
743 case CMD_CLOSE_CHANNEL:
744 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800745 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 if (uiccCard == null) {
747 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900748 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 } else {
751 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
752 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
753 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 break;
755
756 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800757 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
758 break;
759
760 case CMD_NV_READ_ITEM:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
764 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800765 break;
766
767 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 ar = (AsyncResult) msg.obj;
769 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800770 if (ar.exception == null && ar.result != null) {
771 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800773 request.result = "";
774 if (ar.result == null) {
775 loge("nvReadItem: Empty response");
776 } else if (ar.exception instanceof CommandException) {
777 loge("nvReadItem: CommandException: " +
778 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800780 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 }
782 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700783 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
Jake Hambye994d462014-02-03 13:10:13 -0800786 case CMD_NV_WRITE_ITEM:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
789 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800790 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700791 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800792 break;
793
794 case EVENT_NV_WRITE_ITEM_DONE:
795 handleNullReturnEvent(msg, "nvWriteItem");
796 break;
797
798 case CMD_NV_WRITE_CDMA_PRL:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800801 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800802 break;
803
804 case EVENT_NV_WRITE_CDMA_PRL_DONE:
805 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
806 break;
807
chen xu6dac5ab2018-10-26 17:39:23 -0700808 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800809 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700810 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800811 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
chen xu6dac5ab2018-10-26 17:39:23 -0700814 case EVENT_RESET_MODEM_CONFIG_DONE:
815 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800816 break;
817
Sooraj Sasindran37444802020-08-11 10:40:43 -0700818 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
821 request);
822 Phone phone = getPhoneFromRequest(request);
823 if (phone != null) {
824 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
825 } else {
826 loge("isNRDualConnectivityEnabled: No phone object");
827 request.result = false;
828 notifyRequester(request);
829 }
830 break;
831 }
832
833 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null && ar.result != null) {
837 request.result = ar.result;
838 } else {
839 // request.result must be set to something non-null
840 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700841 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700842 request.result = ar.result;
843 } else {
844 request.result = false;
845 }
846 if (ar.result == null) {
847 loge("isNRDualConnectivityEnabled: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("isNRDualConnectivityEnabled: CommandException: "
850 + ar.exception);
851 } else {
852 loge("isNRDualConnectivityEnabled: Unknown exception");
853 }
854 }
855 notifyRequester(request);
856 break;
857
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700858 case CMD_IS_VONR_ENABLED: {
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
861 request);
862 Phone phone = getPhoneFromRequest(request);
863 if (phone != null) {
864 phone.isVoNrEnabled(onCompleted, request.workSource);
865 } else {
866 loge("isVoNrEnabled: No phone object");
867 request.result = false;
868 notifyRequester(request);
869 }
870 break;
871 }
872
873 case EVENT_IS_VONR_ENABLED_DONE:
874 ar = (AsyncResult) msg.obj;
875 request = (MainThreadRequest) ar.userObj;
876 if (ar.exception == null && ar.result != null) {
877 request.result = ar.result;
878 } else {
879 // request.result must be set to something non-null
880 // for the calling thread to unblock
881 if (ar.result != null) {
882 request.result = ar.result;
883 } else {
884 request.result = false;
885 }
886 if (ar.result == null) {
887 loge("isVoNrEnabled: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("isVoNrEnabled: CommandException: "
890 + ar.exception);
891 } else {
892 loge("isVoNrEnabled: Unknown exception");
893 }
894 }
895 notifyRequester(request);
896 break;
897
Sooraj Sasindran37444802020-08-11 10:40:43 -0700898 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
901 Phone phone = getPhoneFromRequest(request);
902 if (phone != null) {
903 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
904 request.workSource);
905 } else {
906 loge("enableNrDualConnectivity: No phone object");
907 request.result =
908 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
909 notifyRequester(request);
910 }
911 break;
912 }
913
914 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
917 if (ar.exception == null) {
918 request.result =
919 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
920 } else {
921 request.result =
922 TelephonyManager
923 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
924 if (ar.exception instanceof CommandException) {
925 CommandException.Error error =
926 ((CommandException) (ar.exception)).getCommandError();
927 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
928 request.result =
929 TelephonyManager
930 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000931 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
932 request.result =
933 TelephonyManager
934 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700935 }
936 loge("enableNrDualConnectivity" + ": CommandException: "
937 + ar.exception);
938 } else {
939 loge("enableNrDualConnectivity" + ": Unknown exception");
940 }
941 }
942 notifyRequester(request);
943 break;
944 }
945
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700946 case CMD_ENABLE_VONR: {
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
949 Phone phone = getPhoneFromRequest(request);
950 if (phone != null) {
951 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
952 request.workSource);
953 } else {
954 loge("setVoNrEnabled: No phone object");
955 request.result =
956 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
957 notifyRequester(request);
958 }
959 break;
960 }
961
962 case EVENT_ENABLE_VONR_DONE: {
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null) {
966 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
967 } else {
968 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
969 if (ar.exception instanceof CommandException) {
970 CommandException.Error error =
971 ((CommandException) (ar.exception)).getCommandError();
972 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
973 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
974 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
975 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
976 } else {
977 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
978 }
979 loge("setVoNrEnabled" + ": CommandException: "
980 + ar.exception);
981 } else {
982 loge("setVoNrEnabled" + ": Unknown exception");
983 }
984 }
985 notifyRequester(request);
986 break;
987 }
988
SongFerngWang3ef3e072020-12-21 16:41:52 +0800989 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800990 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800991 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
992 request);
993 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800994 break;
995
SongFerngWang3ef3e072020-12-21 16:41:52 +0800996 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception == null && ar.result != null) {
1000 request.result = ar.result; // Integer
1001 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301002 // request.result must be set to something non-null
1003 // for the calling thread to unblock
1004 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001005 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001006 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001007 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 loge("getAllowedNetworkTypesBitmask: CommandException: "
1009 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001010 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 }
1013 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001014 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001015 break;
1016
SongFerngWang3ef3e072020-12-21 16:41:52 +08001017 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001019 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1020 request);
1021 Pair<Integer, Long> reasonWithNetworkTypes =
1022 (Pair<Integer, Long>) request.argument;
1023 getPhoneFromRequest(request).setAllowedNetworkTypes(
1024 reasonWithNetworkTypes.first,
1025 reasonWithNetworkTypes.second,
1026 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001027 break;
1028
SongFerngWang3ef3e072020-12-21 16:41:52 +08001029 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1030 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 break;
1032
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001033 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1034 request = (MainThreadRequest)msg.obj;
1035 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001036 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001037 break;
1038
1039 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1040 ar = (AsyncResult)msg.obj;
1041 request = (MainThreadRequest)ar.userObj;
1042 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001043 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001044 break;
1045
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001046 case CMD_SET_VOICEMAIL_NUMBER:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1049 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001050 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1051 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001052 break;
1053
1054 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1055 handleNullReturnEvent(msg, "setVoicemailNumber");
1056 break;
1057
Stuart Scott54788802015-03-30 13:18:01 -07001058 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1059 request = (MainThreadRequest) msg.obj;
1060 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1061 request);
1062 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1063 break;
1064
1065 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1066 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1067 break;
1068
Shishir Agrawal302c8692015-06-19 13:49:39 -07001069 case CMD_PERFORM_NETWORK_SCAN:
1070 request = (MainThreadRequest) msg.obj;
1071 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1072 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1073 break;
1074
Hall Liu27d24262020-09-18 19:04:59 -07001075 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001078 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1079 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1080 request.argument;
1081 int callForwardingReason = args.first;
1082 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001083 break;
Hall Liu27d24262020-09-18 19:04:59 -07001084 }
1085 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001088 TelephonyManager.CallForwardingInfoCallback callback =
1089 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1090 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001091 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001092 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1094 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1095 // Service Class is a bit mask per 3gpp 27.007. Search for
1096 // any service for voice call.
1097 if ((callForwardInfo.serviceClass
1098 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001099 callForwardingInfo = new CallForwardingInfo(
1100 callForwardInfo.status
1101 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001102 callForwardInfo.reason,
1103 callForwardInfo.number,
1104 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001105 break;
1106 }
1107 }
1108 // Didn't find a call forward info for voice call.
1109 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001110 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1111 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001112 }
Hall Liu27d24262020-09-18 19:04:59 -07001113 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001114 } else {
1115 if (ar.result == null) {
1116 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1117 }
1118 if (ar.exception != null) {
1119 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1120 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001121 int errorCode = TelephonyManager
1122 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001123 if (ar.exception instanceof CommandException) {
1124 CommandException.Error error =
1125 ((CommandException) (ar.exception)).getCommandError();
1126 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001127 errorCode = TelephonyManager
1128 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001129 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001130 errorCode = TelephonyManager
1131 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001132 }
1133 }
Hall Liu27d24262020-09-18 19:04:59 -07001134 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136 break;
Hall Liu27d24262020-09-18 19:04:59 -07001137 }
Shuo Qian4a594052020-01-23 11:59:30 -08001138
Hall Liu27d24262020-09-18 19:04:59 -07001139 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001140 request = (MainThreadRequest) msg.obj;
1141 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001142 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001143 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001144 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1145 request.argument).first;
1146 request.phone.setCallForwardingOption(
1147 callForwardingInfoToSet.isEnabled()
1148 ? CommandsInterface.CF_ACTION_ENABLE
1149 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001150 callForwardingInfoToSet.getReason(),
1151 callForwardingInfoToSet.getNumber(),
1152 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1153 break;
Hall Liu27d24262020-09-18 19:04:59 -07001154 }
Shuo Qian4a594052020-01-23 11:59:30 -08001155
Hall Liu27d24262020-09-18 19:04:59 -07001156 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001157 ar = (AsyncResult) msg.obj;
1158 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001159 Consumer<Integer> callback =
1160 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1161 request.argument).second;
1162 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001163 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001164 int errorCode = TelephonyManager.CallForwardingInfoCallback
1165 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001166 if (ar.exception instanceof CommandException) {
1167 CommandException.Error error =
1168 ((CommandException) (ar.exception)).getCommandError();
1169 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001170 errorCode = TelephonyManager.CallForwardingInfoCallback
1171 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001172 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001173 errorCode = TelephonyManager.CallForwardingInfoCallback
1174 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001175 }
1176 }
1177 callback.accept(errorCode);
1178 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001179 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001180 }
Shuo Qian4a594052020-01-23 11:59:30 -08001181 break;
Hall Liu27d24262020-09-18 19:04:59 -07001182 }
Shuo Qian4a594052020-01-23 11:59:30 -08001183
Hall Liu27d24262020-09-18 19:04:59 -07001184 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1187 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1188 break;
Hall Liu27d24262020-09-18 19:04:59 -07001189 }
Shuo Qian4a594052020-01-23 11:59:30 -08001190
Hall Liu27d24262020-09-18 19:04:59 -07001191 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001192 ar = (AsyncResult) msg.obj;
1193 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001194 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001195 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1196 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001197 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 // Service Class is a bit mask per 3gpp 27.007.
1199 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001200 if (callForwardResults.length > 1
1201 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001202 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001203 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001204 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1205 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001207 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 }
1209 } else {
1210 if (ar.result == null) {
1211 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1212 }
1213 if (ar.exception != null) {
1214 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1215 }
1216 if (ar.exception instanceof CommandException) {
1217 CommandException.Error error =
1218 ((CommandException) (ar.exception)).getCommandError();
1219 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1220 callForwardingStatus =
1221 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1222 }
1223 }
1224 }
Hall Liu27d24262020-09-18 19:04:59 -07001225 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001226 break;
Hall Liu27d24262020-09-18 19:04:59 -07001227 }
Shuo Qian4a594052020-01-23 11:59:30 -08001228
Hall Liu27d24262020-09-18 19:04:59 -07001229 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001230 request = (MainThreadRequest) msg.obj;
1231 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001232 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1233 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001234 break;
Hall Liu27d24262020-09-18 19:04:59 -07001235 }
Shuo Qian4a594052020-01-23 11:59:30 -08001236
Hall Liu27d24262020-09-18 19:04:59 -07001237 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001240 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1241 Consumer<Integer> callback =
1242 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1243 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001244 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001245 if (ar.exception instanceof CommandException) {
1246 CommandException.Error error =
1247 ((CommandException) (ar.exception)).getCommandError();
1248 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1249 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1250 } else {
1251 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1252 }
1253 } else {
1254 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1255 }
1256 } else {
1257 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1258 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260 break;
Hall Liu27d24262020-09-18 19:04:59 -07001261 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001262 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1263 ar = (AsyncResult) msg.obj;
1264 request = (MainThreadRequest) ar.userObj;
1265 CellNetworkScanResult cellScanResult;
1266 if (ar.exception == null && ar.result != null) {
1267 cellScanResult = new CellNetworkScanResult(
1268 CellNetworkScanResult.STATUS_SUCCESS,
1269 (List<OperatorInfo>) ar.result);
1270 } else {
1271 if (ar.result == null) {
1272 loge("getCellNetworkScanResults: Empty response");
1273 }
1274 if (ar.exception != null) {
1275 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1276 }
1277 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1278 if (ar.exception instanceof CommandException) {
1279 CommandException.Error error =
1280 ((CommandException) (ar.exception)).getCommandError();
1281 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1282 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1283 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1284 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1285 }
1286 }
1287 cellScanResult = new CellNetworkScanResult(errorCode, null);
1288 }
1289 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001290 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001291 break;
1292
1293 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1294 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001295 ManualNetworkSelectionArgument selArg =
1296 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001297 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1298 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001299 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1300 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001301 break;
1302
1303 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
1306 if (ar.exception == null) {
1307 request.result = true;
1308 } else {
1309 request.result = false;
1310 loge("setNetworkSelectionModeManual " + ar.exception);
1311 }
1312 notifyRequester(request);
1313 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001314 break;
1315
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001316 case CMD_GET_MODEM_ACTIVITY_INFO:
1317 request = (MainThreadRequest) msg.obj;
1318 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001319 if (defaultPhone != null) {
1320 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001321 } else {
1322 ResultReceiver result = (ResultReceiver) request.argument;
1323 Bundle bundle = new Bundle();
1324 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001325 new ModemActivityInfo(0, 0, 0,
1326 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001327 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001328 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001329 break;
1330
Hall Liud0f208c2020-10-14 16:54:44 -07001331 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001334 ResultReceiver result = (ResultReceiver) request.argument;
1335
Hall Liud0f208c2020-10-14 16:54:44 -07001336 ModemActivityInfo ret = null;
1337 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001338 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001339 // Update the last modem activity info and the result of the request.
1340 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1341 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001342 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001343 int[] txTimeMs = info.getTransmitTimeMillis();
1344 int[] lastModemTxTimeMs = mLastModemActivityInfo
1345 .getTransmitTimeMillis();
1346 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1347 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1348 }
Hall Liu49656c02020-10-09 19:00:11 -07001349 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001350 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1351 + mLastModemActivityInfo.getSleepTimeMillis());
1352 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1353 + mLastModemActivityInfo.getIdleTimeMillis());
1354 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1355 mLastModemActivityInfo.setReceiveTimeMillis(
1356 info.getReceiveTimeMillis()
1357 + mLastModemActivityInfo.getReceiveTimeMillis());
1358 }
Hall Liu49656c02020-10-09 19:00:11 -07001359 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001360 mLastModemActivityInfo.getSleepTimeMillis(),
1361 mLastModemActivityInfo.getIdleTimeMillis(),
1362 mLastModemActivityInfo.getTransmitTimeMillis(),
1363 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001364 } else {
1365 if (ar.result == null) {
1366 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001367 error = TelephonyManager.ModemActivityInfoException
1368 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001369 } else if (ar.exception instanceof CommandException) {
1370 loge("queryModemActivityInfo: CommandException: " +
1371 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001372 error = TelephonyManager.ModemActivityInfoException
1373 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001374 } else {
1375 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001376 error = TelephonyManager.ModemActivityInfoException
1377 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001378 }
1379 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001380 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001381 if (ret != null) {
1382 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1383 } else {
1384 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1385 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001386 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001387 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001389 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390
Meng Wang1a7c35a2016-05-05 20:56:15 -07001391 case CMD_SET_ALLOWED_CARRIERS:
1392 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001393 CarrierRestrictionRules argument =
1394 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001395 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001396 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001397 break;
1398
1399 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null && ar.result != null) {
1403 request.result = ar.result;
1404 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001405 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1406 if (ar.exception instanceof CommandException) {
1407 loge("setAllowedCarriers: CommandException: " + ar.exception);
1408 CommandException.Error error =
1409 ((CommandException) (ar.exception)).getCommandError();
1410 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1411 request.result =
1412 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1413 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001414 } else {
1415 loge("setAllowedCarriers: Unknown exception");
1416 }
1417 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001418 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001419 break;
1420
1421 case CMD_GET_ALLOWED_CARRIERS:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001424 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001425 break;
1426
1427 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1428 ar = (AsyncResult) msg.obj;
1429 request = (MainThreadRequest) ar.userObj;
1430 if (ar.exception == null && ar.result != null) {
1431 request.result = ar.result;
1432 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001433 request.result = new IllegalStateException(
1434 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001435 if (ar.result == null) {
1436 loge("getAllowedCarriers: Empty response");
1437 } else if (ar.exception instanceof CommandException) {
1438 loge("getAllowedCarriers: CommandException: " +
1439 ar.exception);
1440 } else {
1441 loge("getAllowedCarriers: Unknown exception");
1442 }
1443 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001444 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001445 break;
1446
Nathan Haroldb3014052017-01-25 15:57:32 -08001447 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null && ar.result != null) {
1451 request.result = ar.result;
1452 } else {
1453 request.result = new IllegalArgumentException(
1454 "Failed to retrieve Forbidden Plmns");
1455 if (ar.result == null) {
1456 loge("getForbiddenPlmns: Empty response");
1457 } else {
1458 loge("getForbiddenPlmns: Unknown exception");
1459 }
1460 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001461 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001462 break;
1463
1464 case CMD_GET_FORBIDDEN_PLMNS:
1465 request = (MainThreadRequest) msg.obj;
1466 uiccCard = getUiccCardFromRequest(request);
1467 if (uiccCard == null) {
1468 loge("getForbiddenPlmns() UiccCard is null");
1469 request.result = new IllegalArgumentException(
1470 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001471 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001472 break;
1473 }
1474 Integer appType = (Integer) request.argument;
1475 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1476 if (uiccApp == null) {
1477 loge("getForbiddenPlmns() no app with specified type -- "
1478 + appType);
1479 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001481 break;
1482 } else {
1483 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1484 + " specified type -- " + appType);
1485 }
1486 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1487 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1488 onCompleted);
1489 break;
1490
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001491 case CMD_SWITCH_SLOTS:
1492 request = (MainThreadRequest) msg.obj;
1493 int[] physicalSlots = (int[]) request.argument;
1494 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1495 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1496 break;
1497
1498 case EVENT_SWITCH_SLOTS_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 notifyRequester(request);
1503 break;
1504 case CMD_GET_NETWORK_SELECTION_MODE:
1505 request = (MainThreadRequest) msg.obj;
1506 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1507 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1508 break;
1509
1510 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 if (ar.exception != null) {
1514 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1515 } else {
1516 int mode = ((int[]) ar.result)[0];
1517 if (mode == 0) {
1518 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1519 } else {
1520 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1521 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
1524 break;
1525 case CMD_GET_CDMA_ROAMING_MODE:
1526 request = (MainThreadRequest) msg.obj;
1527 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1528 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1529 break;
1530 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception != null) {
1534 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1535 } else {
1536 request.result = ((int[]) ar.result)[0];
1537 }
1538 notifyRequester(request);
1539 break;
1540 case CMD_SET_CDMA_ROAMING_MODE:
1541 request = (MainThreadRequest) msg.obj;
1542 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1543 int mode = (int) request.argument;
1544 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1545 break;
1546 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1547 ar = (AsyncResult) msg.obj;
1548 request = (MainThreadRequest) ar.userObj;
1549 request.result = ar.exception == null;
1550 notifyRequester(request);
1551 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001552 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1553 request = (MainThreadRequest) msg.obj;
1554 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1555 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1556 break;
1557 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 if (ar.exception != null) {
1561 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1562 } else {
1563 request.result = ((int[]) ar.result)[0];
1564 }
1565 notifyRequester(request);
1566 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001567 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1568 request = (MainThreadRequest) msg.obj;
1569 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1570 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001571 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1572 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001573 break;
1574 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1575 ar = (AsyncResult) msg.obj;
1576 request = (MainThreadRequest) ar.userObj;
1577 request.result = ar.exception == null;
1578 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001579 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001580 case CMD_GET_ALL_CELL_INFO:
1581 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001582 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001583 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001584 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001585 case EVENT_GET_ALL_CELL_INFO_DONE:
1586 ar = (AsyncResult) msg.obj;
1587 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001588 // If a timeout occurs, the response will be null
1589 request.result = (ar.exception == null && ar.result != null)
1590 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001591 synchronized (request) {
1592 request.notifyAll();
1593 }
1594 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001595 case CMD_REQUEST_CELL_INFO_UPDATE:
1596 request = (MainThreadRequest) msg.obj;
1597 request.phone.requestCellInfoUpdate(request.workSource,
1598 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1599 break;
1600 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1604 try {
1605 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001606 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001607 cb.onError(
1608 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1609 ar.exception.getClass().getName(),
1610 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001611 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001613 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001614 } else {
1615 // use the result as returned
1616 cb.onCellInfo((List<CellInfo>) ar.result);
1617 }
1618 } catch (RemoteException re) {
1619 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1620 }
1621 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001622 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001623 request = (MainThreadRequest) msg.obj;
1624 WorkSource ws = (WorkSource) request.argument;
1625 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001626 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001627 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001628 }
1629 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception == null) {
1633 request.result = ar.result;
1634 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001635 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001636 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001637 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001638 }
1639
1640 synchronized (request) {
1641 request.notifyAll();
1642 }
1643 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001644 }
chen xu6dac5ab2018-10-26 17:39:23 -07001645 case CMD_MODEM_REBOOT:
1646 request = (MainThreadRequest) msg.obj;
1647 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001648 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001649 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001650 case EVENT_CMD_MODEM_REBOOT_DONE:
1651 handleNullReturnEvent(msg, "rebootModem");
1652 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001653 case CMD_REQUEST_ENABLE_MODEM:
1654 request = (MainThreadRequest) msg.obj;
1655 boolean enable = (boolean) request.argument;
1656 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001657 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001658 PhoneConfigurationManager.getInstance()
1659 .enablePhone(request.phone, enable, onCompleted);
1660 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001661 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001665 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001666 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001667 if ((boolean) request.result) {
1668 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1669 updateModemStateMetrics();
1670 } else {
1671 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1672 + ar.exception);
1673 }
1674 notifyRequester(request);
1675 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001676 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001677 case CMD_GET_MODEM_STATUS:
1678 request = (MainThreadRequest) msg.obj;
1679 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1680 PhoneConfigurationManager.getInstance()
1681 .getPhoneStatusFromModem(request.phone, onCompleted);
1682 break;
1683 case EVENT_GET_MODEM_STATUS_DONE:
1684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 int id = request.phone.getPhoneId();
1687 if (ar.exception == null && ar.result != null) {
1688 request.result = ar.result;
1689 //update the cache as modem status has changed
1690 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1691 (boolean) request.result);
1692 } else {
1693 // Return true if modem status cannot be retrieved. For most cases,
1694 // modem status is on. And for older version modems, GET_MODEM_STATUS
1695 // and disable modem are not supported. Modem is always on.
1696 // TODO: this should be fixed in R to support a third
1697 // status UNKNOWN b/131631629
1698 request.result = true;
1699 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1700 + ar.exception);
1701 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001702 notifyRequester(request);
1703 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001704 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1707 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1708 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1709 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1710 break;
1711 }
1712 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1716 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1717 args.second.accept(ar.exception == null);
1718 notifyRequester(request);
1719 break;
1720 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001721 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1724 Phone phone = getPhoneFromRequest(request);
1725 if (phone != null) {
1726 phone.getSystemSelectionChannels(onCompleted);
1727 } else {
1728 loge("getSystemSelectionChannels: No phone object");
1729 request.result = new ArrayList<RadioAccessSpecifier>();
1730 notifyRequester(request);
1731 }
1732 break;
1733 }
1734 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 if (ar.exception == null && ar.result != null) {
1738 request.result = ar.result;
1739 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001740 request.result = new IllegalStateException(
1741 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001742 if (ar.result == null) {
1743 loge("getSystemSelectionChannels: Empty response");
1744 } else {
1745 loge("getSystemSelectionChannels: Unknown exception");
1746 }
1747 }
1748 notifyRequester(request);
1749 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001750 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
1753 if (ar.exception == null && ar.result != null) {
1754 request.result = ar.result;
1755 } else {
1756 request.result = -1;
1757 loge("Failed to set Forbidden Plmns");
1758 if (ar.result == null) {
1759 loge("setForbidenPlmns: Empty response");
1760 } else if (ar.exception != null) {
1761 loge("setForbiddenPlmns: Exception: " + ar.exception);
1762 request.result = -1;
1763 } else {
1764 loge("setForbiddenPlmns: Unknown exception");
1765 }
1766 }
1767 notifyRequester(request);
1768 break;
1769 case CMD_SET_FORBIDDEN_PLMNS:
1770 request = (MainThreadRequest) msg.obj;
1771 uiccCard = getUiccCardFromRequest(request);
1772 if (uiccCard == null) {
1773 loge("setForbiddenPlmns: UiccCard is null");
1774 request.result = -1;
1775 notifyRequester(request);
1776 break;
1777 }
1778 Pair<Integer, List<String>> setFplmnsArgs =
1779 (Pair<Integer, List<String>>) request.argument;
1780 appType = setFplmnsArgs.first;
1781 List<String> fplmns = setFplmnsArgs.second;
1782 uiccApp = uiccCard.getApplicationByType(appType);
1783 if (uiccApp == null) {
1784 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1785 request.result = -1;
1786 loge("Failed to get UICC App");
1787 notifyRequester(request);
1788 } else {
1789 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1790 ((SIMRecords) uiccApp.getIccRecords())
1791 .setForbiddenPlmns(onCompleted, fplmns);
1792 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001793 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001794 case CMD_ERASE_MODEM_CONFIG:
1795 request = (MainThreadRequest) msg.obj;
1796 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1797 defaultPhone.eraseModemConfig(onCompleted);
1798 break;
1799 case EVENT_ERASE_MODEM_CONFIG_DONE:
1800 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001801 break;
zoey chene02881a2019-12-30 16:11:23 +08001802
Kai Shif70f46f2021-03-03 13:59:46 -08001803 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1804 request = (MainThreadRequest) msg.obj;
1805 request.result = defaultPhone.eraseDataInSharedPreferences();
1806 notifyRequester(request);
1807 break;
1808
zoey chene02881a2019-12-30 16:11:23 +08001809 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1810 request = (MainThreadRequest) msg.obj;
1811 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1812 Pair<String, String> changed = (Pair<String, String>) request.argument;
1813 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1814 changed.first, changed.second, onCompleted);
1815 break;
1816 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1817 ar = (AsyncResult) msg.obj;
1818 request = (MainThreadRequest) ar.userObj;
1819 if (ar.exception == null) {
1820 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001821 // If the operation is successful, update the PIN storage
1822 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1823 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001824 UiccController.getInstance().getPinStorage()
1825 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001826 } else {
1827 request.result = msg.arg1;
1828 }
1829 notifyRequester(request);
1830 break;
1831
Michele Berionne5e411512020-11-13 02:36:59 +00001832 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001833 request = (MainThreadRequest) msg.obj;
1834 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1835 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1836 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1837 enabled.first, enabled.second, onCompleted);
1838 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001839 }
zoey chene02881a2019-12-30 16:11:23 +08001840 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1841 ar = (AsyncResult) msg.obj;
1842 request = (MainThreadRequest) ar.userObj;
1843 if (ar.exception == null) {
1844 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001845 // If the operation is successful, update the PIN storage
1846 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1847 int phoneId = getPhoneFromRequest(request).getPhoneId();
1848 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001849 UiccController.getInstance().getPinStorage()
1850 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001851 } else {
1852 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1853 }
zoey chene02881a2019-12-30 16:11:23 +08001854 } else {
1855 request.result = msg.arg1;
1856 }
Michele Berionne5e411512020-11-13 02:36:59 +00001857
1858
zoey chene02881a2019-12-30 16:11:23 +08001859 notifyRequester(request);
1860 break;
1861
Peter Wangdafb9ac2020-01-15 14:13:38 -08001862 case MSG_NOTIFY_USER_ACTIVITY:
1863 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001864 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001865 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1866 getDefaultPhone().getContext().sendBroadcastAsUser(
1867 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1868 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001869
1870 case CMD_SET_DATA_THROTTLING: {
1871 request = (MainThreadRequest) msg.obj;
1872 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1873 DataThrottlingRequest dataThrottlingRequest =
1874 (DataThrottlingRequest) request.argument;
1875 Phone phone = getPhoneFromRequest(request);
1876 if (phone != null) {
1877 phone.setDataThrottling(onCompleted,
1878 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1879 dataThrottlingRequest.getCompletionDurationMillis());
1880 } else {
1881 loge("setDataThrottling: No phone object");
1882 request.result =
1883 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1884 notifyRequester(request);
1885 }
1886
1887 break;
1888 }
1889 case EVENT_SET_DATA_THROTTLING_DONE:
1890 ar = (AsyncResult) msg.obj;
1891 request = (MainThreadRequest) ar.userObj;
1892
1893 if (ar.exception == null) {
1894 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1895 } else if (ar.exception instanceof CommandException) {
1896 loge("setDataThrottling: CommandException: " + ar.exception);
1897 CommandException.Error error =
1898 ((CommandException) (ar.exception)).getCommandError();
1899
1900 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1901 request.result = TelephonyManager
1902 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1903 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1904 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001905 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1906 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001907 } else {
1908 request.result =
1909 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1910 }
1911 } else {
1912 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1913 }
1914 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1915 notifyRequester(request);
1916 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001917
1918 case CMD_SET_SIM_POWER: {
1919 request = (MainThreadRequest) msg.obj;
1920 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1921 request = (MainThreadRequest) msg.obj;
1922 int stateToSet =
1923 ((Pair<Integer, IIntegerConsumer>)
1924 request.argument).first;
1925 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1926 break;
1927 }
1928 case EVENT_SET_SIM_POWER_DONE: {
1929 ar = (AsyncResult) msg.obj;
1930 request = (MainThreadRequest) ar.userObj;
1931 IIntegerConsumer callback =
1932 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1933 if (ar.exception != null) {
1934 loge("setSimPower exception: " + ar.exception);
1935 int errorCode = TelephonyManager.CallForwardingInfoCallback
1936 .RESULT_ERROR_UNKNOWN;
1937 if (ar.exception instanceof CommandException) {
1938 CommandException.Error error =
1939 ((CommandException) (ar.exception)).getCommandError();
1940 if (error == CommandException.Error.SIM_ERR) {
1941 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1942 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1943 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1944 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1945 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1946 } else {
1947 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1948 }
1949 }
1950 try {
1951 callback.accept(errorCode);
1952 } catch (RemoteException e) {
1953 // Ignore if the remote process is no longer available to call back.
1954 Log.w(LOG_TAG, "setSimPower: callback not available.");
1955 }
1956 } else {
1957 try {
1958 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1959 } catch (RemoteException e) {
1960 // Ignore if the remote process is no longer available to call back.
1961 Log.w(LOG_TAG, "setSimPower: callback not available.");
1962 }
1963 }
1964 break;
1965 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001966 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1967 request = (MainThreadRequest) msg.obj;
1968
1969 final Phone phone = getPhoneFromRequest(request);
1970 if (phone == null || phone.getServiceStateTracker() == null) {
1971 request.result = new IllegalStateException("Phone or SST is null");
1972 notifyRequester(request);
1973 break;
1974 }
1975
1976 Pair<Integer, SignalStrengthUpdateRequest> pair =
1977 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1978 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1979 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001980 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001981 request.subId, pair.first /*callingUid*/,
1982 pair.second /*request*/, onCompleted);
1983 break;
1984 }
1985 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1986 ar = (AsyncResult) msg.obj;
1987 request = (MainThreadRequest) ar.userObj;
1988 // request.result will be the exception of ar if present, true otherwise.
1989 // Be cautious not to leave result null which will wait() forever
1990 request.result = ar.exception != null ? ar.exception : true;
1991 notifyRequester(request);
1992 break;
1993 }
1994 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1995 request = (MainThreadRequest) msg.obj;
1996
1997 Phone phone = getPhoneFromRequest(request);
1998 if (phone == null || phone.getServiceStateTracker() == null) {
1999 request.result = new IllegalStateException("Phone or SST is null");
2000 notifyRequester(request);
2001 break;
2002 }
2003
2004 Pair<Integer, SignalStrengthUpdateRequest> pair =
2005 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2006 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2007 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002008 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002009 request.subId, pair.first /*callingUid*/,
2010 pair.second /*request*/, onCompleted);
2011 break;
2012 }
2013 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2014 ar = (AsyncResult) msg.obj;
2015 request = (MainThreadRequest) ar.userObj;
2016 request.result = ar.exception != null ? ar.exception : true;
2017 notifyRequester(request);
2018 break;
2019 }
Jordan Liu109698e2020-11-24 14:50:34 -08002020
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002021 case CMD_GET_SLICING_CONFIG: {
2022 request = (MainThreadRequest) msg.obj;
2023 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2024 request.phone.getSlicingConfig(onCompleted);
2025 break;
2026 }
2027 case EVENT_GET_SLICING_CONFIG_DONE: {
2028 ar = (AsyncResult) msg.obj;
2029 request = (MainThreadRequest) ar.userObj;
2030 ResultReceiver result = (ResultReceiver) request.argument;
2031
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002032 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002033 Bundle bundle = new Bundle();
2034 int resultCode = 0;
2035 if (ar.exception != null) {
2036 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2037 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002038 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002039 } else if (ar.result == null) {
2040 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002041 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002042 } else {
2043 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002044 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2045 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002046 }
2047
2048 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002049 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002050 }
2051 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2052 result.send(resultCode, bundle);
2053 notifyRequester(request);
2054 break;
2055 }
2056
Michele Berionne5e411512020-11-13 02:36:59 +00002057 case CMD_PREPARE_UNATTENDED_REBOOT:
2058 request = (MainThreadRequest) msg.obj;
2059 request.result =
2060 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2061 notifyRequester(request);
2062 break;
2063
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 default:
2065 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2066 break;
2067 }
2068 }
Jake Hambye994d462014-02-03 13:10:13 -08002069
Pengquan Menga1bb6272018-09-06 09:59:22 -07002070 private void notifyRequester(MainThreadRequest request) {
2071 synchronized (request) {
2072 request.notifyAll();
2073 }
2074 }
2075
Jake Hambye994d462014-02-03 13:10:13 -08002076 private void handleNullReturnEvent(Message msg, String command) {
2077 AsyncResult ar = (AsyncResult) msg.obj;
2078 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2079 if (ar.exception == null) {
2080 request.result = true;
2081 } else {
2082 request.result = false;
2083 if (ar.exception instanceof CommandException) {
2084 loge(command + ": CommandException: " + ar.exception);
2085 } else {
2086 loge(command + ": Unknown exception");
2087 }
2088 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002089 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 }
2092
2093 /**
2094 * Posts the specified command to be executed on the main thread,
2095 * waits for the request to complete, and returns the result.
2096 * @see #sendRequestAsync
2097 */
2098 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002099 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2100 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002101 }
2102
2103 /**
2104 * Posts the specified command to be executed on the main thread,
2105 * waits for the request to complete, and returns the result.
2106 * @see #sendRequestAsync
2107 */
2108 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2109 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002110 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002111 }
2112
2113 /**
2114 * Posts the specified command to be executed on the main thread,
2115 * waits for the request to complete, and returns the result.
2116 * @see #sendRequestAsync
2117 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002118 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002119 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2120 }
2121
2122 /**
2123 * Posts the specified command to be executed on the main thread,
2124 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2125 * if not timeout or null otherwise.
2126 * @see #sendRequestAsync
2127 */
2128 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2129 long timeoutInMs) {
2130 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002131 }
2132
2133 /**
2134 * Posts the specified command to be executed on the main thread,
2135 * waits for the request to complete, and returns the result.
2136 * @see #sendRequestAsync
2137 */
Nathan Harold92bed182018-10-12 18:16:49 -07002138 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002139 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002140 }
2141
2142 /**
2143 * Posts the specified command to be executed on the main thread,
2144 * waits for the request to complete, and returns the result.
2145 * @see #sendRequestAsync
2146 */
2147 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002148 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2149 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002150 }
2151
2152 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002153 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2154 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2155 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002156 * @see #sendRequestAsync
2157 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002158 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2159 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2161 throw new RuntimeException("This method will deadlock if called from the main thread.");
2162 }
2163
Nathan Harold92bed182018-10-12 18:16:49 -07002164 MainThreadRequest request = null;
2165 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2166 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2167 } else if (phone != null) {
2168 request = new MainThreadRequest(argument, phone, workSource);
2169 } else {
2170 request = new MainThreadRequest(argument, subId, workSource);
2171 }
2172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 Message msg = mMainThreadHandler.obtainMessage(command, request);
2174 msg.sendToTarget();
2175
Rambo Wang0f050d82021-02-12 11:43:36 -08002176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002178 if (timeoutInMs >= 0) {
2179 // Wait for at least timeoutInMs before returning null request result
2180 long now = SystemClock.elapsedRealtime();
2181 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002182 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002183 try {
2184 request.wait(deadline - now);
2185 } catch (InterruptedException e) {
2186 // Do nothing, go back and check if request is completed or timeout
2187 } finally {
2188 now = SystemClock.elapsedRealtime();
2189 }
2190 }
2191 } else {
2192 // Wait for the request to complete
2193 while (request.result == null) {
2194 try {
2195 request.wait();
2196 } catch (InterruptedException e) {
2197 // Do nothing, go back and wait until the request is complete
2198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200 }
2201 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002202 if (request.result == null) {
2203 Log.wtf(LOG_TAG,
2204 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2205 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 return request.result;
2207 }
2208
2209 /**
2210 * Asynchronous ("fire and forget") version of sendRequest():
2211 * Posts the specified command to be executed on the main thread, and
2212 * returns immediately.
2213 * @see #sendRequest
2214 */
2215 private void sendRequestAsync(int command) {
2216 mMainThreadHandler.sendEmptyMessage(command);
2217 }
2218
2219 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002220 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002221 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002222 */
2223 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002224 sendRequestAsync(command, argument, null, null);
2225 }
2226
2227 /**
2228 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2229 * @see {@link #sendRequest(int,Object)}
2230 */
2231 private void sendRequestAsync(
2232 int command, Object argument, Phone phone, WorkSource workSource) {
2233 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002234 Message msg = mMainThreadHandler.obtainMessage(command, request);
2235 msg.sendToTarget();
2236 }
2237
2238 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 * Initialize the singleton PhoneInterfaceManager instance.
2240 * This is only done once, at startup, from PhoneApp.onCreate().
2241 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002242 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 synchronized (PhoneInterfaceManager.class) {
2244 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002245 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 } else {
2247 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2248 }
2249 return sInstance;
2250 }
2251 }
2252
2253 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002254 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002257 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002258 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002260 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002262 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002263 mTelephonySharedPreferences =
2264 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002265 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002266 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002267 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002268 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002269
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 publish();
2271 }
2272
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002273 private Phone getDefaultPhone() {
2274 Phone thePhone = getPhone(getDefaultSubscription());
2275 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2276 }
2277
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 private void publish() {
2279 if (DBG) log("publish: " + this);
2280
Peter Wangc035ce42020-01-08 21:00:22 -08002281 TelephonyFrameworkInitializer
2282 .getTelephonyServiceManager()
2283 .getTelephonyServiceRegisterer()
2284 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286
Stuart Scott584921c2015-01-15 17:10:34 -08002287 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002288 if (request.phone != null) {
2289 return request.phone;
2290 } else {
2291 return getPhoneFromSubId(request.subId);
2292 }
2293 }
2294
2295 private Phone getPhoneFromSubId(int subId) {
2296 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2297 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002298 }
2299
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002300 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2301 Phone phone = getPhoneFromRequest(request);
2302 return phone == null ? null :
2303 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2304 }
2305
Wink Saville36469e72014-06-11 15:17:00 -07002306 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002307 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002308 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310
Kai Shif70f46f2021-03-03 13:59:46 -08002311 private void sendEraseModemConfig(@NonNull Phone phone) {
2312 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2313 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2314 }
2315
2316 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2317 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2318 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002319 }
2320
Peter Wang44b186e2020-01-13 23:33:09 -08002321 private boolean isImsAvailableOnDevice() {
2322 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2323 if (pm == null) {
2324 // For some reason package manger is not available.. This will fail internally anyway,
2325 // so do not throw error and allow.
2326 return true;
2327 }
2328 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2329 }
2330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002332 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002333 }
2334
Wink Savilleb564aae2014-10-23 10:18:09 -07002335 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 if (DBG) log("dial: " + number);
2337 // No permission check needed here: This is just a wrapper around the
2338 // ACTION_DIAL intent, which is available to any app since it puts up
2339 // the UI before it does anything.
2340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 String url = createTelUrl(number);
2344 if (url == null) {
2345 return;
2346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348 // PENDING: should we just silently fail if phone is offhook or ringing?
2349 PhoneConstants.State state = mCM.getState(subId);
2350 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2351 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2352 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2353 mApp.startActivity(intent);
2354 }
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 }
2358 }
2359
2360 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002361 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002362 }
2363
Wink Savilleb564aae2014-10-23 10:18:09 -07002364 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 if (DBG) log("call: " + number);
2366
2367 // This is just a wrapper around the ACTION_CALL intent, but we still
2368 // need to do a permission check since we're calling startActivity()
2369 // from the context of the phone app.
2370 enforceCallPermission();
2371
Jordan Liu1617b712019-07-10 15:06:26 -07002372 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 != AppOpsManager.MODE_ALLOWED) {
2374 return;
2375 }
2376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 String url = createTelUrl(number);
2380 if (url == null) {
2381 return;
2382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002384 boolean isValid = false;
2385 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2386 if (slist != null) {
2387 for (SubscriptionInfo subInfoRecord : slist) {
2388 if (subInfoRecord.getSubscriptionId() == subId) {
2389 isValid = true;
2390 break;
2391 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002392 }
Wink Saville08874612014-08-31 19:19:58 -07002393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002394 if (!isValid) {
2395 return;
2396 }
Wink Saville08874612014-08-31 19:19:58 -07002397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2399 intent.putExtra(SUBSCRIPTION_KEY, subId);
2400 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2401 mApp.startActivity(intent);
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
2404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
2406
Wink Savilleb564aae2014-10-23 10:18:09 -07002407 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002408 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002409 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2410 }
2411
Wink Savilleb564aae2014-10-23 10:18:09 -07002412 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002413 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002414 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2415 }
2416
Wink Savilleb564aae2014-10-23 10:18:09 -07002417 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419
2420 final long identity = Binder.clearCallingIdentity();
2421 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002422 Phone phone = getPhone(subId);
2423 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424 checkSimPin.start();
2425 return checkSimPin.unlockSim(null, pin);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002433
2434 final long identity = Binder.clearCallingIdentity();
2435 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002436 Phone phone = getPhone(subId);
2437 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438 checkSimPuk.start();
2439 return checkSimPuk.unlockSim(puk, pin);
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
2442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444
2445 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002446 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 * a synchronous one.
2448 */
2449 private static class UnlockSim extends Thread {
2450
2451 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002452 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453
2454 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002455 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2456 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457
2458 // For replies from SimCard interface
2459 private Handler mHandler;
2460
2461 // For async handler to identify request type
2462 private static final int SUPPLY_PIN_COMPLETE = 100;
2463
Michele Berionne5e411512020-11-13 02:36:59 +00002464 UnlockSim(int phoneId, IccCard simCard) {
2465 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 mSimCard = simCard;
2467 }
2468
2469 @Override
2470 public void run() {
2471 Looper.prepare();
2472 synchronized (UnlockSim.this) {
2473 mHandler = new Handler() {
2474 @Override
2475 public void handleMessage(Message msg) {
2476 AsyncResult ar = (AsyncResult) msg.obj;
2477 switch (msg.what) {
2478 case SUPPLY_PIN_COMPLETE:
2479 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2480 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002481 mRetryCount = msg.arg1;
2482 if (ar.exception != null) {
2483 if (ar.exception instanceof CommandException &&
2484 ((CommandException)(ar.exception)).getCommandError()
2485 == CommandException.Error.PASSWORD_INCORRECT) {
2486 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002487 } //When UiccCardApp dispose,handle message and return exception
2488 else if (ar.exception instanceof CommandException &&
2489 ((CommandException) (ar.exception)).getCommandError()
2490 == CommandException.Error.ABORTED) {
2491 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002492 } else {
2493 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2494 }
2495 } else {
2496 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 mDone = true;
2499 UnlockSim.this.notifyAll();
2500 }
2501 break;
2502 }
2503 }
2504 };
2505 UnlockSim.this.notifyAll();
2506 }
2507 Looper.loop();
2508 }
2509
2510 /*
2511 * Use PIN or PUK to unlock SIM card
2512 *
2513 * If PUK is null, unlock SIM card with PIN
2514 *
2515 * If PUK is not null, unlock SIM card with PUK and set PIN code
2516 */
Wink Saville9de0f752013-10-22 19:04:03 -07002517 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518
2519 while (mHandler == null) {
2520 try {
2521 wait();
2522 } catch (InterruptedException e) {
2523 Thread.currentThread().interrupt();
2524 }
2525 }
2526 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2527
2528 if (puk == null) {
2529 mSimCard.supplyPin(pin, callback);
2530 } else {
2531 mSimCard.supplyPuk(puk, pin, callback);
2532 }
2533
2534 while (!mDone) {
2535 try {
2536 Log.d(LOG_TAG, "wait for done");
2537 wait();
2538 } catch (InterruptedException e) {
2539 // Restore the interrupted status
2540 Thread.currentThread().interrupt();
2541 }
2542 }
2543 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002544 int[] resultArray = new int[2];
2545 resultArray[0] = mResult;
2546 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002547
2548 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002549 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002550 }
2551
Wink Saville9de0f752013-10-22 19:04:03 -07002552 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554 }
2555
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002556 /**
2557 * This method has been removed due to privacy and stability concerns.
2558 */
2559 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002561 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2562 return;
Wink Saville36469e72014-06-11 15:17:00 -07002563 }
2564
Nathan Harold1f889d82020-06-04 17:05:26 -07002565 @Override
2566 public void updateServiceLocationWithPackageName(String callingPackage) {
2567 mApp.getSystemService(AppOpsManager.class)
2568 .checkPackage(Binder.getCallingUid(), callingPackage);
2569
Nathan Haroldf096d982020-11-18 17:18:06 -08002570 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002571 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2572 // Callers targeting S have no business invoking this method.
2573 return;
2574 }
2575
2576 LocationAccessPolicy.LocationPermissionResult locationResult =
2577 LocationAccessPolicy.checkLocationPermission(mApp,
2578 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2579 .setCallingPackage(callingPackage)
2580 .setCallingFeatureId(null)
2581 .setCallingPid(Binder.getCallingPid())
2582 .setCallingUid(Binder.getCallingUid())
2583 .setMethod("updateServiceLocation")
2584 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2585 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2586 .build());
2587 // Apps that lack location permission have no business calling this method;
2588 // however, because no permission was declared in the public API, denials must
2589 // all be "soft".
2590 switch (locationResult) {
2591 case DENIED_HARD: /* fall through */
2592 case DENIED_SOFT:
2593 return;
2594 }
2595
2596 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002599 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002601 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 }
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
2607
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002608 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002609 @Override
2610 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002611 return isRadioOnWithFeature(callingPackage, null);
2612 }
2613
2614
2615 @Override
2616 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2617 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2618 callingFeatureId);
2619 }
2620
2621 @Deprecated
2622 @Override
2623 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2624 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002625 }
2626
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002627 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002628 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2629 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002631 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002632 return false;
2633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 return isRadioOnForSubscriber(subId);
2638 } finally {
2639 Binder.restoreCallingIdentity(identity);
2640 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002641 }
2642
2643 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
2647 if (phone != null) {
2648 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2649 } else {
2650 return false;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 }
2656
2657 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002658 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
Wink Saville36469e72014-06-11 15:17:00 -07002660
Wink Savilleb564aae2014-10-23 10:18:09 -07002661 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663
2664 final long identity = Binder.clearCallingIdentity();
2665 try {
2666 final Phone phone = getPhone(subId);
2667 if (phone != null) {
2668 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 }
Wink Saville36469e72014-06-11 15:17:00 -07002673 }
2674
2675 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002676 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002677 }
2678
Wink Savilleb564aae2014-10-23 10:18:09 -07002679 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 final Phone phone = getPhone(subId);
2685 if (phone == null) {
2686 return false;
2687 }
2688 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2689 toggleRadioOnOffForSubscriber(subId);
2690 }
2691 return true;
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
Wink Saville36469e72014-06-11 15:17:00 -07002696
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002697 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002698 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002699 /*
2700 * If any of the Radios are available, it will need to be
2701 * shutdown. So return true if any Radio is available.
2702 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2706 Phone phone = PhoneFactory.getPhone(i);
2707 if (phone != null && phone.isRadioAvailable()) return true;
2708 }
2709 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2710 return false;
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002713 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002714 }
2715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002717 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 enforceModifyPermission();
2719
2720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2723 logv("Shutting down Phone " + i);
2724 shutdownRadioUsingPhoneId(i);
2725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002728 }
2729 }
2730
2731 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 Phone phone = PhoneFactory.getPhone(phoneId);
2733 if (phone != null && phone.isRadioAvailable()) {
2734 phone.shutdownRadio();
2735 }
2736 }
2737
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2744 if (defaultPhone != null) {
2745 defaultPhone.setRadioPower(turnOn);
2746 return true;
2747 } else {
2748 loge("There's no default phone.");
2749 return false;
2750 }
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002753 }
Wink Saville36469e72014-06-11 15:17:00 -07002754 }
2755
Wink Savilleb564aae2014-10-23 10:18:09 -07002756 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758
2759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 final Phone phone = getPhone(subId);
2762 if (phone != null) {
2763 phone.setRadioPower(turnOn);
2764 return true;
2765 } else {
2766 return false;
2767 }
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
Wink Saville36469e72014-06-11 15:17:00 -07002773 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 public boolean enableDataConnectivity() {
2776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 int subId = mSubscriptionController.getDefaultDataSubId();
2781 final Phone phone = getPhone(subId);
2782 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002783 phone.getDataEnabledSettings().setDataEnabled(
2784 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 return true;
2786 } else {
2787 return false;
2788 }
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
Wink Saville36469e72014-06-11 15:17:00 -07002794 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 public boolean disableDataConnectivity() {
2797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 int subId = mSubscriptionController.getDefaultDataSubId();
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002804 phone.getDataEnabledSettings().setDataEnabled(
2805 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 return true;
2807 } else {
2808 return false;
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 }
2814
Sanket Padawe356d7632015-06-22 14:03:32 -07002815 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002816 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 final Phone phone = getPhone(subId);
2820 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002821 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822 } else {
2823 return false;
2824 }
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 }
2829
2830 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002831 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002832 }
2833
pkanwarae03a6b2016-11-06 20:37:09 -08002834 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 enforceCallPermission();
2836
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2840 return;
2841 }
2842 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2843 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
2846 }
pkanwar32d516d2016-10-14 19:37:38 -07002847 };
2848
Wink Savilleb564aae2014-10-23 10:18:09 -07002849 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851
2852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2855 return false;
2856 }
2857 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 }
2862
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002863 /**
2864 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2865 * tag on getCallState Binder call.
2866 */
2867 @Deprecated
2868 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002870 if (CompatChanges.isChangeEnabled(
2871 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2872 Binder.getCallingUid())) {
2873 // Do not allow this API to be called on API version 31+, it should only be
2874 // called on old apps using this Binder call directly.
2875 throw new SecurityException("This method can only be used for applications "
2876 + "targeting API version 30 or less.");
2877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 final long identity = Binder.clearCallingIdentity();
2879 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002880 Phone phone = getPhone(getDefaultSubscription());
2881 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2882 PhoneConstantConversions.convertCallState(phone.getState());
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
2885 }
2886 }
2887
2888 @Override
2889 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2890 if (CompatChanges.isChangeEnabled(
2891 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2892 Binder.getCallingUid())) {
2893 // Check READ_PHONE_STATE for API version 31+
2894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2895 featureId, "getCallStateForSubscription")) {
2896 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2897 + "targeting API level 31+.");
2898 }
2899 }
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2904 PhoneConstantConversions.convertCallState(phone.getState());
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002908 }
2909
Sanket Padawe356d7632015-06-22 14:03:32 -07002910 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002911 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002912 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2913 }
2914
2915 @Override
2916 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 final long identity = Binder.clearCallingIdentity();
2918 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002919 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 if (phone != null) {
2921 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2922 } else {
2923 return PhoneConstantConversions.convertDataState(
2924 PhoneConstants.DataState.DISCONNECTED);
2925 }
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
Sanket Padawe356d7632015-06-22 14:03:32 -07002931 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002932 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002933 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2934 }
2935
2936 @Override
2937 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002940 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 if (phone != null) {
2942 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2943 } else {
2944 return TelephonyManager.DATA_ACTIVITY_NONE;
2945 }
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 }
2950
2951 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002952 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002954 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002955
2956 LocationAccessPolicy.LocationPermissionResult locationResult =
2957 LocationAccessPolicy.checkLocationPermission(mApp,
2958 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2959 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002960 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002961 .setCallingPid(Binder.getCallingPid())
2962 .setCallingUid(Binder.getCallingUid())
2963 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002964 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002965 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2966 .build());
2967 switch (locationResult) {
2968 case DENIED_HARD:
2969 throw new SecurityException("Not allowed to access cell location");
2970 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002971 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2972 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 }
2974
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002979 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002980 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
Svetoslav64fad262015-04-14 14:35:21 -07002984 }
2985
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002987 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002988 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2989 // registered cell info, so return a NULL country instead.
2990 final long identity = Binder.clearCallingIdentity();
2991 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002992 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2993 // Get default phone in this case.
2994 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2995 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002996 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002998 if (phone == null) return "";
2999 ServiceStateTracker sst = phone.getServiceStateTracker();
3000 if (sst == null) return "";
3001 LocaleTracker lt = sst.getLocaleTracker();
3002 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003003 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003007 }
3008
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003009 /**
3010 * This method was removed due to potential issues caused by performing partial
3011 * updates of service state, and lack of a credible use case.
3012 *
3013 * This has the ability to break the telephony implementation by disabling notification of
3014 * changes in device connectivity. DO NOT USE THIS!
3015 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003016 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003017 public void enableLocationUpdates() {
3018 mApp.enforceCallingOrSelfPermission(
3019 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 }
3021
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003022 /**
3023 * This method was removed due to potential issues caused by performing partial
3024 * updates of service state, and lack of a credible use case.
3025 *
3026 * This has the ability to break the telephony implementation by disabling notification of
3027 * changes in device connectivity. DO NOT USE THIS!
3028 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 @Override
3030 public void disableLocationUpdates() {
3031 mApp.enforceCallingOrSelfPermission(
3032 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 }
3034
3035 @Override
3036 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003037 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3038 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08003039 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003040 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3041 throw new SecurityException(
3042 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3043 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003044
Jordan Liu1617b712019-07-10 15:06:26 -07003045 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003046 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3047 return null;
3048 }
Svetoslav64fad262015-04-14 14:35:21 -07003049
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003050 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003052 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003053 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054
Nathan Haroldf180aac2018-06-01 18:43:55 -07003055 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3056 for (CellInfo ci : info) {
3057 if (ci instanceof CellInfoGsm) {
3058 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3059 } else if (ci instanceof CellInfoWcdma) {
3060 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003063 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064 }
3065
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003066 private List<CellInfo> getCachedCellInfo() {
3067 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3068 for (Phone phone : PhoneFactory.getPhones()) {
3069 List<CellInfo> info = phone.getAllCellInfo();
3070 if (info != null) cellInfos.addAll(info);
3071 }
3072 return cellInfos;
3073 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074
3075 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003076 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003077 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003078 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003079
3080 LocationAccessPolicy.LocationPermissionResult locationResult =
3081 LocationAccessPolicy.checkLocationPermission(mApp,
3082 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3083 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003084 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003085 .setCallingPid(Binder.getCallingPid())
3086 .setCallingUid(Binder.getCallingUid())
3087 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003088 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003089 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3090 .build());
3091 switch (locationResult) {
3092 case DENIED_HARD:
3093 throw new SecurityException("Not allowed to access cell info");
3094 case DENIED_SOFT:
3095 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096 }
3097
Nathan Haroldf096d982020-11-18 17:18:06 -08003098 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003099 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3100 return getCachedCellInfo();
3101 }
3102
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003103 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003104 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3108 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003109 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003110 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111 if (info != null) cellInfos.addAll(info);
3112 }
3113 return cellInfos;
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 }
3117 }
3118
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003119 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003120 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3121 String callingFeatureId) {
3122 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3123 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003124 }
3125
3126 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003127 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3128 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003129 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003130 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003131 }
3132
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003133 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3134 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003135 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003136 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003137
3138 LocationAccessPolicy.LocationPermissionResult locationResult =
3139 LocationAccessPolicy.checkLocationPermission(mApp,
3140 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3141 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003142 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003143 .setCallingPid(Binder.getCallingPid())
3144 .setCallingUid(Binder.getCallingUid())
3145 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003146 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3147 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003148 .build());
3149 switch (locationResult) {
3150 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003151 if (TelephonyPermissions
3152 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003153 // Safetynet logging for b/154934934
3154 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3155 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003156 throw new SecurityException("Not allowed to access cell info");
3157 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003158 if (TelephonyPermissions
3159 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003160 // Safetynet logging for b/154934934
3161 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3162 }
Nathan Harold5320c422019-05-09 10:26:08 -07003163 try {
3164 cb.onCellInfo(new ArrayList<CellInfo>());
3165 } catch (RemoteException re) {
3166 // Drop without consequences
3167 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003168 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003169 }
3170
Nathan Harolda939a962019-05-09 10:13:47 -07003171
3172 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003173 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3174
3175 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3176 }
3177
3178 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003179 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003180 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003181 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182
3183 final long identity = Binder.clearCallingIdentity();
3184 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003185 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 }
3190
Shishir Agrawala9f32182016-04-12 12:00:16 -07003191 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003192 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003193 Phone phone = PhoneFactory.getPhone(slotIndex);
3194 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003195 return null;
3196 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003197 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003198 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003199 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003200 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003201 return null;
3202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203
3204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 return phone.getImei();
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003210 }
3211
3212 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003213 public String getTypeAllocationCodeForSlot(int slotIndex) {
3214 Phone phone = PhoneFactory.getPhone(slotIndex);
3215 String tac = null;
3216 if (phone != null) {
3217 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003218 try {
3219 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3220 } catch (IndexOutOfBoundsException e) {
3221 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3222 return null;
3223 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003224 }
3225 return tac;
3226 }
3227
3228 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003229 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003230 Phone phone = PhoneFactory.getPhone(slotIndex);
3231 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003232 return null;
3233 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003234
Jeff Davidson913390f2018-02-23 17:11:49 -08003235 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003236 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003237 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003238 return null;
3239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240
3241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 return phone.getMeid();
3244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
Jack Yu2af8d712017-03-15 17:14:14 -07003247 }
3248
3249 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003250 public String getManufacturerCodeForSlot(int slotIndex) {
3251 Phone phone = PhoneFactory.getPhone(slotIndex);
3252 String manufacturerCode = null;
3253 if (phone != null) {
3254 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003255 try {
3256 manufacturerCode =
3257 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3258 } catch (IndexOutOfBoundsException e) {
3259 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3260 return null;
3261 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003262 }
3263 return manufacturerCode;
3264 }
3265
3266 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003267 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3268 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003269 Phone phone = PhoneFactory.getPhone(slotIndex);
3270 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003271 return null;
3272 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003273 int subId = phone.getSubId();
3274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003275 mApp, subId, callingPackage, callingFeatureId,
3276 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003277 return null;
3278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
3280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 return phone.getDeviceSvn();
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003286 }
3287
fionaxu43304da2017-11-27 22:51:16 -08003288 @Override
3289 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290 final long identity = Binder.clearCallingIdentity();
3291 try {
3292 final Phone phone = getPhone(subId);
3293 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3294 } finally {
3295 Binder.restoreCallingIdentity(identity);
3296 }
fionaxu43304da2017-11-27 22:51:16 -08003297 }
3298
3299 @Override
3300 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003301 final long identity = Binder.clearCallingIdentity();
3302 try {
3303 final Phone phone = getPhone(subId);
3304 return phone == null ? null : phone.getCarrierName();
3305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
fionaxu43304da2017-11-27 22:51:16 -08003308 }
3309
calvinpanffe225e2018-11-01 19:43:06 +08003310 @Override
chen xu0026ca62019-03-06 15:28:50 -08003311 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 final Phone phone = getPhone(subId);
3315 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003316 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
3320 }
3321
3322 @Override
chen xu0026ca62019-03-06 15:28:50 -08003323 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003327 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003328 } finally {
3329 Binder.restoreCallingIdentity(identity);
3330 }
3331 }
3332
chen xu651eec72018-11-11 19:03:44 -08003333 @Override
chen xu864e11c2018-12-06 22:10:03 -08003334 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3335 if (!isSubscriptionMccMnc) {
3336 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3337 }
chen xu651eec72018-11-11 19:03:44 -08003338 final Phone phone = PhoneFactory.getPhone(slotIndex);
3339 if (phone == null) {
3340 return TelephonyManager.UNKNOWN_CARRIER_ID;
3341 }
3342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3345 } finally {
3346 Binder.restoreCallingIdentity(identity);
3347 }
3348 }
3349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 //
3351 // Internal helper methods.
3352 //
3353
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003354 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003355 * Make sure the caller is the calling package itself
3356 *
3357 * @throws SecurityException if the caller is not the calling package
3358 */
3359 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3360 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003361 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3362 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003363 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003364 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003365 } catch (PackageManager.NameNotFoundException e) {
3366 // packageUid is -1
3367 }
3368 if (packageUid != callingUid) {
3369 throw new SecurityException(message + ": Package " + callingPackage
3370 + " does not belong to " + callingUid);
3371 }
3372 }
3373
3374 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003375 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3376 *
3377 * @throws SecurityException if the caller does not have the required permission
3378 */
3379 private void enforceModifyPermission() {
3380 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3381 }
3382
Shuo Qian3b6ee772019-11-13 17:43:31 -08003383 private void enforceActiveEmergencySessionPermission() {
3384 mApp.enforceCallingOrSelfPermission(
3385 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3386 }
3387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388 /**
3389 * Make sure the caller has the CALL_PHONE permission.
3390 *
3391 * @throws SecurityException if the caller does not have the required permission
3392 */
3393 private void enforceCallPermission() {
3394 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3395 }
3396
paulhu5a773602019-08-23 19:17:33 +08003397 private void enforceSettingsPermission() {
3398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003399 }
3400
Michele Berionne5e411512020-11-13 02:36:59 +00003401 private void enforceRebootPermission() {
3402 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3403 }
3404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003405 private String createTelUrl(String number) {
3406 if (TextUtils.isEmpty(number)) {
3407 return null;
3408 }
3409
Jake Hambye994d462014-02-03 13:10:13 -08003410 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003411 }
3412
Ihab Awadf9e92732013-12-05 18:02:52 -08003413 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3415 }
3416
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003417 private static void logv(String msg) {
3418 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3419 }
3420
Ihab Awadf9e92732013-12-05 18:02:52 -08003421 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003422 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3423 }
3424
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003425 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003426 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003427 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003428 }
3429
Sanket Padawe356d7632015-06-22 14:03:32 -07003430 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003431 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432 final long identity = Binder.clearCallingIdentity();
3433 try {
3434 final Phone phone = PhoneFactory.getPhone(slotIndex);
3435 if (phone == null) {
3436 return PhoneConstants.PHONE_TYPE_NONE;
3437 } else {
3438 return phone.getPhoneType();
3439 }
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003443 }
3444
3445 /**
3446 * Returns the CDMA ERI icon index to display
3447 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003449 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3450 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3451 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003452 }
3453
Sanket Padawe356d7632015-06-22 14:03:32 -07003454 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003455 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3456 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003458 mApp, subId, callingPackage, callingFeatureId,
3459 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003460 return -1;
3461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462
3463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 final Phone phone = getPhone(subId);
3466 if (phone != null) {
3467 return phone.getCdmaEriIconIndex();
3468 } else {
3469 return -1;
3470 }
3471 } finally {
3472 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 }
3475
3476 /**
3477 * Returns the CDMA ERI icon mode,
3478 * 0 - ON
3479 * 1 - FLASHING
3480 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003481 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003482 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3483 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3484 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003485 }
3486
Sanket Padawe356d7632015-06-22 14:03:32 -07003487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003488 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3489 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003491 mApp, subId, callingPackage, callingFeatureId,
3492 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003493 return -1;
3494 }
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) {
3500 return phone.getCdmaEriIconMode();
3501 } else {
3502 return -1;
3503 }
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507 }
3508
3509 /**
3510 * Returns the CDMA ERI text,
3511 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003512 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003513 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3514 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3515 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003516 }
3517
Sanket Padawe356d7632015-06-22 14:03:32 -07003518 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003519 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3520 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003522 mApp, subId, callingPackage, callingFeatureId,
3523 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003524 return null;
3525 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003526
3527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 final Phone phone = getPhone(subId);
3530 if (phone != null) {
3531 return phone.getCdmaEriText();
3532 } else {
3533 return null;
3534 }
3535 } finally {
3536 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003538 }
3539
3540 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003541 * Returns the CDMA MDN.
3542 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003543 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003544 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3546 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003551 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003552 return phone.getLine1Number();
3553 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003554 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003555 return null;
3556 }
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003559 }
3560 }
3561
3562 /**
3563 * Returns the CDMA MIN.
3564 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003565 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003566 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3568 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569
3570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 final Phone phone = getPhone(subId);
3573 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3574 return phone.getCdmaMin();
3575 } else {
3576 return null;
3577 }
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003580 }
3581 }
3582
Hall Liud892bec2018-11-30 14:51:45 -08003583 @Override
3584 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3585 INumberVerificationCallback callback, String callingPackage) {
3586 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3587 != PERMISSION_GRANTED) {
3588 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3589 }
3590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3591
3592 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3593 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003594 throw new SecurityException("Calling package must be configured in the device config: "
3595 + "calling package: " + callingPackage
3596 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003597 }
3598
3599 if (range == null) {
3600 throw new NullPointerException("Range must be non-null");
3601 }
3602
3603 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003604 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003605
3606 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3607 }
3608
Junda Liuca05d5d2014-08-14 22:36:34 -07003609 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 * Returns true if CDMA provisioning needs to run.
3611 */
3612 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003613 final long identity = Binder.clearCallingIdentity();
3614 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003615 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003616 } finally {
3617 Binder.restoreCallingIdentity(identity);
3618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003619 }
3620
3621 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003622 * Sets the voice mail number of a given subId.
3623 */
3624 @Override
3625 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003626 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3627 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003628
3629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3632 new Pair<String, String>(alphaTag, number), new Integer(subId));
3633 return success;
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003637 }
3638
Ta-wei Yen87c49842016-05-13 21:19:52 -07003639 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003640 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3641 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003642 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3643 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003644 if (!TextUtils.equals(callingPackage, systemDialer)) {
3645 throw new SecurityException("caller must be system dialer");
3646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3651 if (phoneAccountHandle == null) {
3652 return null;
3653 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 } finally {
3656 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003657 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003658 }
3659
3660 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003661 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3662 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003665 mApp, subId, callingPackage, callingFeatureId,
3666 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003667 return null;
3668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003670 final long identity = Binder.clearCallingIdentity();
3671 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003672 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003676 }
3677
3678 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003679 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3680 VisualVoicemailSmsFilterSettings settings) {
3681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003686 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003690 }
3691
3692 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003693 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3694 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003695
3696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003699 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003700 } finally {
3701 Binder.restoreCallingIdentity(identity);
3702 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003703 }
3704
3705 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003706 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3707 String callingPackage, int subId) {
3708 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003709
3710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003717 }
3718
3719 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003720 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003722
3723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003726 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003730 }
3731
3732 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003733 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3734 String callingAttributionTag, int subId, String number, int port, String text,
3735 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003737 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003738 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003739 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003740 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3741 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003742 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003743
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003744 /**
fionaxu0152e512016-11-14 13:36:14 -08003745 * Sets the voice activation state of a given subId.
3746 */
3747 @Override
3748 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3750 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751
3752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 final Phone phone = getPhone(subId);
3755 if (phone != null) {
3756 phone.setVoiceActivationState(activationState);
3757 } else {
3758 loge("setVoiceActivationState fails with invalid subId: " + subId);
3759 }
3760 } finally {
3761 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003762 }
3763 }
3764
3765 /**
3766 * Sets the data activation state of a given subId.
3767 */
3768 @Override
3769 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3771 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772
3773 final long identity = Binder.clearCallingIdentity();
3774 try {
3775 final Phone phone = getPhone(subId);
3776 if (phone != null) {
3777 phone.setDataActivationState(activationState);
3778 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003779 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780 }
3781 } finally {
3782 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003783 }
3784 }
3785
3786 /**
3787 * Returns the voice activation state of a given subId.
3788 */
3789 @Override
3790 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003791 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
fionaxu0152e512016-11-14 13:36:14 -08003793 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 if (phone != null) {
3797 return phone.getVoiceActivationState();
3798 } else {
3799 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003803 }
3804 }
3805
3806 /**
3807 * Returns the data activation state of a given subId.
3808 */
3809 @Override
3810 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003811 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
fionaxu0152e512016-11-14 13:36:14 -08003813 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 if (phone != null) {
3817 return phone.getDataActivationState();
3818 } else {
3819 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3820 }
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003823 }
3824 }
3825
3826 /**
Wink Saville36469e72014-06-11 15:17:00 -07003827 * Returns the unread count of voicemails for a subId
3828 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003829 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003830 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3831 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003832 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003833 mApp, subId, callingPackage, callingFeatureId,
3834 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003835 return 0;
3836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 final Phone phone = getPhone(subId);
3840 if (phone != null) {
3841 return phone.getVoiceMessageCount();
3842 } else {
3843 return 0;
3844 }
3845 } finally {
3846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003848 }
3849
3850 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003851 * returns true, if the device is in a state where both voice and data
3852 * are supported simultaneously. This can change based on location or network condition.
3853 */
3854 @Override
3855 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 final Phone phone = getPhone(subId);
3859 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3860 } finally {
3861 Binder.restoreCallingIdentity(identity);
3862 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003863 }
3864
3865 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003866 * Send the dialer code if called from the current default dialer or the caller has
3867 * carrier privilege.
3868 * @param inputCode The dialer code to send
3869 */
3870 @Override
3871 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003872 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003873 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003874 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3875 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003876 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003877 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003878 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003880
3881 final long identity = Binder.clearCallingIdentity();
3882 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003883 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884 } finally {
3885 Binder.restoreCallingIdentity(identity);
3886 }
fionaxu235cc5e2017-03-06 22:25:57 -08003887 }
3888
Pengquan Menga1bb6272018-09-06 09:59:22 -07003889 @Override
3890 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003891 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003892 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003893 mApp, subId, "getNetworkSelectionMode");
3894 final long identity = Binder.clearCallingIdentity();
3895 try {
3896 if (!isActiveSubscription(subId)) {
3897 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3898 }
3899 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003902 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003903 }
3904
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003906 public boolean isInEmergencySmsMode() {
3907 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 for (Phone phone : PhoneFactory.getPhones()) {
3911 if (phone.isInEmergencySmsMode()) {
3912 return true;
3913 }
3914 }
3915 } finally {
3916 Binder.restoreCallingIdentity(identity);
3917 }
3918 return false;
3919 }
3920
shilu366312e2019-12-17 09:28:10 -08003921 /**
3922 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3923 * @param subId The subscription to use to check the configuration.
3924 * @param c The callback that will be used to send the result.
3925 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003926 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003927 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3928 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003929 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003930 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003931
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003932 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3933 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3934 "IMS not available on device.");
3935 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 final long token = Binder.clearCallingIdentity();
3937 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003938 int slotId = getSlotIndexOrException(subId);
3939 verifyImsMmTelConfiguredOrThrow(slotId);
3940 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003941 } catch (ImsException e) {
3942 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003943 } finally {
3944 Binder.restoreCallingIdentity(token);
3945 }
3946 }
3947
shilu366312e2019-12-17 09:28:10 -08003948 /**
3949 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3950 * @param subId The subscription to use to check the configuration.
3951 * @param c The callback that will be used to send the result.
3952 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003953 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003954 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003955 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003956 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003957 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3958 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3959 }
Meng Wangafbc5852019-09-19 17:37:13 -07003960 final long token = Binder.clearCallingIdentity();
3961 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003962 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3963 .removeRegistrationCallbackForSubscription(c, subId);
3964 } catch (ImsException e) {
3965 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3966 + "is inactive, ignoring unregister.");
3967 // If the subscription is no longer active, just return, since the callback
3968 // will already have been removed internally.
3969 } finally {
3970 Binder.restoreCallingIdentity(token);
3971 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 }
3973
Brad Ebingera34a6c22019-10-22 17:36:18 -07003974 /**
3975 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3976 */
3977 @Override
3978 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3979 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3980 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3981 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3982 "IMS not available on device.");
3983 }
3984 final long token = Binder.clearCallingIdentity();
3985 try {
3986 Phone phone = getPhone(subId);
3987 if (phone == null) {
3988 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3989 + subId + "'");
3990 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3991 }
3992 phone.getImsRegistrationState(regState -> {
3993 try {
3994 consumer.accept((regState == null)
3995 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3996 } catch (RemoteException e) {
3997 // Ignore if the remote process is no longer available to call back.
3998 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3999 }
4000 });
4001 } finally {
4002 Binder.restoreCallingIdentity(token);
4003 }
4004 }
4005
4006 /**
4007 * Get the transport type for the IMS service registration state.
4008 */
4009 @Override
4010 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004011 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004012 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004013 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4014 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4015 "IMS not available on device.");
4016 }
4017 final long token = Binder.clearCallingIdentity();
4018 try {
4019 Phone phone = getPhone(subId);
4020 if (phone == null) {
4021 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4022 + subId + "'");
4023 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4024 }
4025 phone.getImsRegistrationTech(regTech -> {
4026 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4027 int regTechConverted = (regTech == null)
4028 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4029 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4030 regTechConverted);
4031 try {
4032 consumer.accept(regTechConverted);
4033 } catch (RemoteException e) {
4034 // Ignore if the remote process is no longer available to call back.
4035 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4036 }
4037 });
4038 } finally {
4039 Binder.restoreCallingIdentity(token);
4040 }
4041 }
4042
shilu366312e2019-12-17 09:28:10 -08004043 /**
4044 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4045 * @param subId The subscription to use to check the configuration.
4046 * @param c The callback that will be used to send the result.
4047 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004049 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4050 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004051 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004052 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004053 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4054 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4055 "IMS not available on device.");
4056 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 final long token = Binder.clearCallingIdentity();
4058 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004059 int slotId = getSlotIndexOrException(subId);
4060 verifyImsMmTelConfiguredOrThrow(slotId);
4061 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004062 } catch (ImsException e) {
4063 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 } finally {
4065 Binder.restoreCallingIdentity(token);
4066 }
4067 }
4068
shilu366312e2019-12-17 09:28:10 -08004069 /**
4070 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4071 * @param subId The subscription to use to check the configuration.
4072 * @param c The callback that will be used to send the result.
4073 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004075 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004076 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004077 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004078 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4079 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4080 }
Meng Wangafbc5852019-09-19 17:37:13 -07004081
4082 final long token = Binder.clearCallingIdentity();
4083 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004084 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004085 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004086 } catch (ImsException e) {
4087 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4088 + "is inactive, ignoring unregister.");
4089 // If the subscription is no longer active, just return, since the callback
4090 // will already have been removed internally.
4091 } finally {
4092 Binder.restoreCallingIdentity(token);
4093 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 }
4095
4096 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004097 public boolean isCapable(int subId, int capability, int regTech) {
4098 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004099 final long token = Binder.clearCallingIdentity();
4100 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004101 int slotId = getSlotIndexOrException(subId);
4102 verifyImsMmTelConfiguredOrThrow(slotId);
4103 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004104 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4106 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004107 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004108 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4109 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 } finally {
4111 Binder.restoreCallingIdentity(token);
4112 }
4113 }
4114
4115 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004116 public boolean isAvailable(int subId, int capability, int regTech) {
4117 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 final long token = Binder.clearCallingIdentity();
4119 try {
4120 Phone phone = getPhone(subId);
4121 if (phone == null) return false;
4122 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004123 } catch (com.android.ims.ImsException e) {
4124 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4125 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 } finally {
4127 Binder.restoreCallingIdentity(token);
4128 }
4129 }
4130
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004131 /**
4132 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4133 * subscription.
4134 * @param subId The subscription to use to check the configuration.
4135 * @param callback The callback that will be used to send the result.
4136 * @param capability The MmTelFeature capability that will be used to send the result.
4137 * @param transportType The transport type of the MmTelFeature capability.
4138 */
4139 @Override
4140 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4141 int transportType) {
4142 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4143 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4144 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4145 "IMS not available on device.");
4146 }
4147 final long token = Binder.clearCallingIdentity();
4148 try {
4149 int slotId = getSlotIndex(subId);
4150 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4151 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4152 + subId + "'");
4153 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4154 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004155 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004156 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4157 transportType, aBoolean -> {
4158 try {
4159 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4160 } catch (RemoteException e) {
4161 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4162 + "running. Ignore");
4163 }
4164 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004165 } catch (ImsException e) {
4166 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004167 } finally {
4168 Binder.restoreCallingIdentity(token);
4169 }
4170 }
4171
shilu366312e2019-12-17 09:28:10 -08004172 /**
4173 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4174 * @param subId The subscription to use to check the configuration.
4175 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 @Override
4177 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004178 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004179 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004180
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 final long token = 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).isEnhanced4gLteModeSettingEnabledByUser();
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(token);
4190 }
4191 }
4192
4193 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004194 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004196 "setAdvancedCallingSettingEnabled");
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).setEnhanced4gLteModeSetting(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 /**
4211 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4212 * @param subId The subscription to use to check the configuration.
4213 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004215 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004216 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004217 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 final long identity = Binder.clearCallingIdentity();
4219 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004220 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004221 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004222 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 } catch (ImsException e) {
4224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
4228 }
4229
4230 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004231 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004233 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 final long identity = Binder.clearCallingIdentity();
4235 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004236 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004237 // This setting doesn't require an active ImsService connection, so do not verify. The
4238 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004239 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004240 } catch (ImsException e) {
4241 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
4245 }
4246
shilu366312e2019-12-17 09:28:10 -08004247 /**
4248 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4249 * @param subId The subscription to use to check the configuration.
4250 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 @Override
4252 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004253 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004254 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 final long identity = Binder.clearCallingIdentity();
4256 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004257 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004258 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004260 } catch (ImsException e) {
4261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
4265 }
4266
4267 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004268 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004270 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 final long identity = Binder.clearCallingIdentity();
4272 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004273 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004274 // This setting doesn't require an active ImsService connection, so do not verify. The
4275 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004276 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004277 } catch (ImsException e) {
4278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
4282 }
4283
shilu366312e2019-12-17 09:28:10 -08004284 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004285 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4286 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4287 * @param subId The subscription to use to check the configuration.
4288 */
4289 @Override
4290 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004291 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004292 mApp, subId, "isCrossSimCallingEnabledByUser");
4293 final long identity = Binder.clearCallingIdentity();
4294 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004295 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004296 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004298 } catch (ImsException e) {
4299 throw new ServiceSpecificException(e.getCode());
4300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
4303 }
4304
4305 /**
4306 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4307 * Requires MODIFY_PHONE_STATE permission.
4308 * @param subId The subscription to use to check the configuration.
4309 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4310 * false otherwise
4311 */
4312 @Override
4313 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4315 "setCrossSimCallingEnabled");
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004318 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004319 // This setting doesn't require an active ImsService connection, so do not verify. The
4320 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004321 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004322 } catch (ImsException e) {
4323 throw new ServiceSpecificException(e.getCode());
4324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
4327 }
4328
4329 /**
shilu366312e2019-12-17 09:28:10 -08004330 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4331 * @param subId The subscription to use to check the configuration.
4332 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004333 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004334
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004336 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004337 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004338 final long identity = Binder.clearCallingIdentity();
4339 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004340 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004341 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004342 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004343 } catch (ImsException e) {
4344 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
4348 }
4349
4350 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004351 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004353 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 final long identity = Binder.clearCallingIdentity();
4355 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004356 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004357 // This setting doesn't require an active ImsService connection, so do not verify. The
4358 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004359 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004360 } catch (ImsException e) {
4361 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004362 } finally {
4363 Binder.restoreCallingIdentity(identity);
4364 }
4365 }
4366
4367 @Override
4368 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4370 "setVoWiFiNonPersistent");
4371 final long identity = Binder.clearCallingIdentity();
4372 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004373 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004374 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004375 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004376 } catch (ImsException e) {
4377 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
4381 }
4382
shilu366312e2019-12-17 09:28:10 -08004383 /**
4384 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4385 * @param subId The subscription to use to check the configuration.
4386 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 @Override
4388 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004389 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004390 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 final long identity = Binder.clearCallingIdentity();
4392 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004394 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004396 } catch (ImsException e) {
4397 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
4401 }
4402
4403 @Override
4404 public void setVoWiFiModeSetting(int subId, int mode) {
4405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4406 "setVoWiFiModeSetting");
4407 final long identity = Binder.clearCallingIdentity();
4408 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004409 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004410 // This setting doesn't require an active ImsService connection, so do not verify. The
4411 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004413 } catch (ImsException e) {
4414 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
4418 }
4419
4420 @Override
4421 public int getVoWiFiRoamingModeSetting(int subId) {
4422 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004425 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004426 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004427 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004428 } catch (ImsException e) {
4429 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
4433 }
4434
4435 @Override
4436 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4438 "setVoWiFiRoamingModeSetting");
4439 final long identity = Binder.clearCallingIdentity();
4440 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004441 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004442 // This setting doesn't require an active ImsService connection, so do not verify. The
4443 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004444 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004445 } catch (ImsException e) {
4446 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
4450 }
4451
4452 @Override
4453 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4455 "setRttCapabilityEnabled");
4456 final long identity = Binder.clearCallingIdentity();
4457 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004459 // This setting doesn't require an active ImsService connection, so do not verify. The
4460 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004462 } catch (ImsException e) {
4463 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
4467 }
4468
shilu366312e2019-12-17 09:28:10 -08004469 /**
4470 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4471 * @param subId The subscription to use to check the configuration.
4472 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004473 @Override
4474 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004475 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004476 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 final long identity = Binder.clearCallingIdentity();
4478 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004479 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004480 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004482 } catch (ImsException e) {
4483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
4487 }
4488
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004489 @Override
4490 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4491 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4492 final long identity = Binder.clearCallingIdentity();
4493 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004494 if (!isImsAvailableOnDevice()) {
4495 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4496 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004497 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 int slotId = getSlotIndexOrException(subId);
4499 verifyImsMmTelConfiguredOrThrow(slotId);
4500 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004501 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004502 } catch (ImsException e) {
4503 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
4507 }
4508
4509 @Override
4510 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4511 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4512 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004513 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4514 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4515 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004516 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004517 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004518 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004519 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004520 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4521 + "is inactive, ignoring unregister.");
4522 // If the subscription is no longer active, just return, since the callback will already
4523 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 }
4528
allenwtsu99c623b2020-01-03 18:24:23 +08004529
4530 private void checkModifyPhoneStatePermission(int subId, String message) {
4531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4532 message);
4533 }
4534
4535 private boolean isImsProvisioningRequired(int subId, int capability,
4536 boolean isMmtelCapability) {
4537 Phone phone = getPhone(subId);
4538 if (phone == null) {
4539 loge("phone instance null for subid " + subId);
4540 return false;
4541 }
4542 if (isMmtelCapability) {
4543 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4544 return false;
4545 }
4546 } else {
4547 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4548 return false;
4549 }
4550 }
4551 return true;
4552 }
4553
4554 @Override
4555 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4556 boolean isProvisioned) {
4557 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4558
4559 final long identity = Binder.clearCallingIdentity();
4560 try {
4561 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4562 if (!isImsProvisioningRequired(subId, capability, false)) {
4563 return;
4564 }
4565
4566 // this capability requires provisioning, route to the correct API.
4567 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4568 switch (capability) {
4569 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4570 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4571 ims.setEabProvisioned(isProvisioned);
4572 break;
4573 default: {
4574 throw new IllegalArgumentException("Tried to set provisioning for "
4575 + "rcs capability '" + capability + "', which does not require "
4576 + "provisioning.");
4577 }
4578 }
4579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
4582
4583 }
4584
4585
4586 @Override
4587 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4588 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4589 final long identity = Binder.clearCallingIdentity();
4590 try {
4591 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4592 if (!isImsProvisioningRequired(subId, capability, false)) {
4593 return true;
4594 }
4595
4596 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4597 switch (capability) {
4598 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4599 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4600 return ims.isEabProvisionedOnDevice();
4601
4602 default: {
4603 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4604 + "capability '" + capability + "', which does not require "
4605 + "provisioning.");
4606 }
4607 }
4608
4609 } finally {
4610 Binder.restoreCallingIdentity(identity);
4611 }
4612 }
4613
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004614 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004615 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4616 boolean isProvisioned) {
4617 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004618 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4619 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4620 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004621 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4622 }
allenwtsu99c623b2020-01-03 18:24:23 +08004623 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004624 final long identity = Binder.clearCallingIdentity();
4625 try {
4626 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004627 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004628 return;
4629 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004630 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4631 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4632 loge("setImsProvisioningStatusForCapability: called for technology that does "
4633 + "not support provisioning - " + tech);
4634 return;
4635 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004636
4637 // this capability requires provisioning, route to the correct API.
4638 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4639 switch (capability) {
4640 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4641 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4642 ims.setVolteProvisioned(isProvisioned);
4643 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4644 ims.setWfcProvisioned(isProvisioned);
4645 }
4646 break;
4647 }
4648 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4649 // There is currently no difference in VT provisioning type.
4650 ims.setVtProvisioned(isProvisioned);
4651 break;
4652 }
4653 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4654 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4655 // change the capability of the feature instead if needed.
4656 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4657 == isProvisioned) {
4658 // No change in provisioning.
4659 return;
4660 }
4661 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4662 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004663 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004664 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4666 + ", Exception" + e.getMessage());
4667 }
4668 break;
4669 }
4670 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004671 throw new IllegalArgumentException("Tried to set provisioning for "
4672 + "MmTel capability '" + capability + "', which does not require "
4673 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004674 }
4675 }
4676
4677 } finally {
4678 Binder.restoreCallingIdentity(identity);
4679 }
4680 }
4681
4682 @Override
4683 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4684 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004685 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4686 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4687 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004688 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4689 }
4690 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004694 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004695 return true;
4696 }
4697
Brad Ebinger0d79c572021-04-17 15:20:49 -07004698 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4699 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4700 loge("getImsProvisioningStatusForCapability: called for technology that does "
4701 + "not support provisioning - " + tech);
4702 return true;
4703 }
4704
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4706 switch (capability) {
4707 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4708 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4709 return ims.isVolteProvisionedOnDevice();
4710 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4711 return ims.isWfcProvisionedOnDevice();
4712 }
4713 // This should never happen, since we are checking tech above to make sure it
4714 // is either LTE or IWLAN.
4715 throw new IllegalArgumentException("Invalid radio technology for voice "
4716 + "capability.");
4717 }
4718 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4719 // There is currently no difference in VT provisioning type.
4720 return ims.isVtProvisionedOnDevice();
4721 }
4722 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4723 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4724 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4725 }
4726 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004727 throw new IllegalArgumentException(
4728 "Tried to get provisioning for MmTel capability '" + capability
4729 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730 }
4731 }
4732
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
4736 }
4737
4738 @Override
4739 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4740 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4741 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4742 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4743 }
4744 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4745 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4746 return (provisionedBits & capability) > 0;
4747 }
4748
4749 @Override
4750 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4751 boolean isProvisioned) {
4752 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4753 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4754 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4755 }
4756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4757 "setProvisioningStatusForCapability");
4758 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4759 // If the current provisioning status for capability already matches isProvisioned,
4760 // do nothing.
4761 if (((provisionedBits & capability) > 0) == isProvisioned) {
4762 return;
4763 }
4764 if (isProvisioned) {
4765 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4766 } else {
4767 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4768 }
4769 }
4770
4771 /**
4772 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4773 * technology. The bitfield should mirror the bitfield defined by
4774 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4775 */
4776 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4777 String key = getMmTelProvisioningKey(subId, tech);
4778 // Default is no capabilities are provisioned.
4779 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4780 }
4781
4782 /**
4783 * Sets the MmTel capability provisioning bitfield (defined by
4784 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4785 * technology specified.
4786 *
4787 * Note: This is a synchronous command and should not be called on UI thread.
4788 */
4789 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4790 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4791 String key = getMmTelProvisioningKey(subId, tech);
4792 editor.putInt(key, newField);
4793 editor.commit();
4794 }
4795
4796 private static String getMmTelProvisioningKey(int subId, int tech) {
4797 // resulting key is provision_ims_mmtel_{subId}_{tech}
4798 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4799 }
4800
4801 /**
4802 * Query CarrierConfig to see if the specified capability requires provisioning for the
4803 * carrier associated with the subscription id.
4804 */
4805 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4806 int capability) {
4807 CarrierConfigManager configManager = new CarrierConfigManager(context);
4808 PersistableBundle c = configManager.getConfigForSubId(subId);
4809 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004810 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004811 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4812 false);
4813 boolean requireVoiceVtProvisioning = c.getBoolean(
4814 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4815
4816 // First check to make sure that the capability requires provisioning.
4817 switch (capability) {
4818 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4819 // intentional fallthrough
4820 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4821 if (requireVoiceVtProvisioning) {
4822 // Voice and Video requires provisioning
4823 return true;
4824 }
4825 break;
4826 }
4827 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4828 if (requireUtProvisioning) {
4829 // UT requires provisioning
4830 return true;
4831 }
4832 break;
4833 }
4834 }
4835 return false;
4836 }
4837
allenwtsu99c623b2020-01-03 18:24:23 +08004838 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4839 int capability) {
4840 CarrierConfigManager configManager = new CarrierConfigManager(context);
4841 PersistableBundle c = configManager.getConfigForSubId(subId);
4842
4843 boolean requireRcsProvisioning = c.getBoolean(
4844 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4845
4846 // First check to make sure that the capability requires provisioning.
4847 switch (capability) {
4848 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4849 // intentional fallthrough
4850 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4851 if (requireRcsProvisioning) {
4852 // OPTION or PRESENCE requires provisioning
4853 return true;
4854 }
4855 break;
4856 }
4857 }
4858 return false;
4859 }
4860
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004861 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004862 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004863 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4864 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4865 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004866 enforceReadPrivilegedPermission("getImsProvisioningInt");
4867 final long identity = Binder.clearCallingIdentity();
4868 try {
4869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004870 int slotId = getSlotIndex(subId);
4871 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4872 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4873 + subId + "' for key:" + key);
4874 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4875 }
calvinpanb5a34062021-02-08 19:59:36 +08004876 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004877 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004878 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4879 + subId + "' for key:" + key);
4880 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004881 } finally {
4882 Binder.restoreCallingIdentity(identity);
4883 }
4884 }
4885
4886 @Override
4887 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4889 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4890 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004891 enforceReadPrivilegedPermission("getImsProvisioningString");
4892 final long identity = Binder.clearCallingIdentity();
4893 try {
4894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004895 int slotId = getSlotIndex(subId);
4896 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4897 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4898 + subId + "' for key:" + key);
4899 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4900 }
calvinpanb5a34062021-02-08 19:59:36 +08004901 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004902 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004903 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4904 + subId + "' for key:" + key);
4905 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004906 } finally {
4907 Binder.restoreCallingIdentity(identity);
4908 }
4909 }
4910
4911 @Override
4912 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4914 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4915 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4917 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 int slotId = getSlotIndex(subId);
4922 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4923 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4924 + subId + "' for key:" + key);
4925 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4926 }
calvinpanb5a34062021-02-08 19:59:36 +08004927 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4928 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004930 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
4937 @Override
4938 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4940 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4941 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4943 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 int slotId = getSlotIndex(subId);
4948 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4949 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4950 + subId + "' for key:" + key);
4951 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4952 }
calvinpanb5a34062021-02-08 19:59:36 +08004953 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4954 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004956 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
4961 }
4962
Brad Ebinger919631e2021-06-02 17:46:35 -07004963 /**
4964 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4965 * for the given slot ID or no ImsResolver instance has been created.
4966 * @param slotId The slot ID that the IMS service is created for.
4967 * @throws ImsException If there is no ImsService configured for this slot.
4968 */
4969 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4970 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4971 ImsFeature.FEATURE_MMTEL)) {
4972 throw new ImsException("This subscription does not support MMTEL over IMS",
4973 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4974 }
4975 }
4976
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004977 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004978 int slotId = SubscriptionManager.getSlotIndex(subId);
4979 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004980 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4981 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004982 }
4983 return slotId;
4984 }
4985
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004986 private int getSlotIndex(int subId) {
4987 int slotId = SubscriptionManager.getSlotIndex(subId);
4988 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4989 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4990 }
4991 return slotId;
4992 }
4993
Wink Saville36469e72014-06-11 15:17:00 -07004994 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004995 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004996 */
4997 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004998 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4999 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08005000 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005001 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005002 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005003 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005004 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005005 mApp, subId, callingPackage, callingFeatureId,
5006 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005007 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5008 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 final long identity = Binder.clearCallingIdentity();
5011 try {
5012 final Phone phone = getPhone(subId);
5013 if (phone != null) {
5014 return phone.getServiceState().getDataNetworkType();
5015 } else {
5016 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5017 }
5018 } finally {
5019 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005021 }
5022
5023 /**
5024 * Returns the data network type
5025 */
5026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005027 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005028 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5029 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005030 }
5031
5032 /**
5033 * Returns the data network type for a subId
5034 */
5035 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005036 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5037 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005039 mApp, subId, callingPackage, callingFeatureId,
5040 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005041 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5042 }
5043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 final Phone phone = getPhone(subId);
5047 if (phone != null) {
5048 return phone.getServiceState().getDataNetworkType();
5049 } else {
5050 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5051 }
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005055 }
5056
5057 /**
Wink Saville36469e72014-06-11 15:17:00 -07005058 * Returns the Voice network type for a subId
5059 */
5060 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005061 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5062 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005064 mApp, subId, callingPackage, callingFeatureId,
5065 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005066 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5067 }
5068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 final long identity = Binder.clearCallingIdentity();
5070 try {
5071 final Phone phone = getPhone(subId);
5072 if (phone != null) {
5073 return phone.getServiceState().getVoiceNetworkType();
5074 } else {
5075 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5076 }
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005080 }
5081
5082 /**
5083 * @return true if a ICC card is present
5084 */
5085 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005086 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005087 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5088 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005089 }
5090
5091 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005092 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005093 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005094 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005095 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 final Phone phone = PhoneFactory.getPhone(slotIndex);
5099 if (phone != null) {
5100 return phone.getIccCard().hasIccCard();
5101 } else {
5102 return false;
5103 }
5104 } finally {
5105 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005107 }
5108
5109 /**
5110 * Return if the current radio is LTE on CDMA. This
5111 * is a tri-state return value as for a period of time
5112 * the mode may be unknown.
5113 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005114 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005115 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005116 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005117 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005118 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005119 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5120 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5121 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005122 }
5123
Sanket Padawe356d7632015-06-22 14:03:32 -07005124 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005125 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5126 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005127 try {
5128 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5129 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005130 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5131 }
5132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 final Phone phone = getPhone(subId);
5136 if (phone == null) {
5137 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5138 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005139 return TelephonyProperties.lte_on_cdma_device()
5140 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141 }
5142 } finally {
5143 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005144 }
Wink Saville36469e72014-06-11 15:17:00 -07005145 }
5146
Wink Saville36469e72014-06-11 15:17:00 -07005147 /**
5148 * {@hide}
5149 * Returns Default subId, 0 in the case of single standby.
5150 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005151 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005152 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005153 }
5154
Shishir Agrawala9f32182016-04-12 12:00:16 -07005155 private int getSlotForDefaultSubscription() {
5156 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5157 }
5158
Wink Savilleb564aae2014-10-23 10:18:09 -07005159 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005160 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005161 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005162
Pengquan Menge92a50d2018-09-21 15:54:48 -07005163 private boolean isActiveSubscription(int subId) {
5164 return mSubscriptionController.isActiveSubId(subId);
5165 }
5166
Ihab Awadf2177b72013-11-25 13:33:23 -08005167 /**
5168 * @see android.telephony.TelephonyManager.WifiCallingChoices
5169 */
5170 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 final long identity = Binder.clearCallingIdentity();
5172 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005173 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5175 getWhenToMakeWifiCallsDefaultPreference());
5176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005179 }
5180
5181 /**
5182 * @see android.telephony.TelephonyManager.WifiCallingChoices
5183 */
5184 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005188 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005193 }
5194
Sailesh Nepald1e68152013-12-12 19:08:02 -08005195 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005196 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005197 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005198 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005199
Jordan Liu4c733742019-02-28 12:03:40 -08005200 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5201 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5202 if (phoneId == -1) {
5203 throw new IllegalArgumentException("Given slot index: " + slotIndex
5204 + " does not correspond to an active phone");
5205 }
5206 return PhoneFactory.getPhone(phoneId);
5207 }
5208
Shishir Agrawal566b7612013-10-28 14:41:00 -07005209 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005210 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5211 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5213 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005215 if (DBG) {
5216 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5217 }
5218 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5219 p2);
5220 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005221
Jordan Liu4c733742019-02-28 12:03:40 -08005222
5223 @Override
5224 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5225 int slotIndex, String callingPackage, String aid, int p2) {
5226 enforceModifyPermission();
5227 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5228 if (DBG) {
5229 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5230 }
5231 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5232 callingPackage, aid, p2);
5233 }
5234
5235 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5236 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 final long identity = Binder.clearCallingIdentity();
5238 try {
5239 if (TextUtils.equals(ISDR_AID, aid)) {
5240 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005241 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5242 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 if (bestComponent == null
5244 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5245 loge("The calling package is not allowed to access ISD-R.");
5246 throw new SecurityException(
5247 "The calling package is not allowed to access ISD-R.");
5248 }
Derek Tan740e1672017-06-27 14:56:27 -07005249 }
Derek Tan740e1672017-06-27 14:56:27 -07005250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005252 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5253 null /* workSource */);
5254 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 return response;
5256 } finally {
5257 Binder.restoreCallingIdentity(identity);
5258 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005259 }
5260
5261 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005262 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5264 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005265 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5266 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5267 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005268
Jordan Liu4c733742019-02-28 12:03:40 -08005269 @Override
5270 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5271 enforceModifyPermission();
5272 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5273 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5274 channel);
5275 }
5276
5277 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 final long identity = Binder.clearCallingIdentity();
5279 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 if (channel < 0) {
5281 return false;
5282 }
Jordan Liu4c733742019-02-28 12:03:40 -08005283 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5284 null /* workSource */);
5285 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 return success;
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005289 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005290 }
5291
5292 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005293 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005294 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5296 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005297 if (DBG) {
5298 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5299 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5300 + p3 + " data=" + data);
5301 }
5302 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5303 command, p1, p2, p3, data);
5304 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005305
Jordan Liu4c733742019-02-28 12:03:40 -08005306 @Override
5307 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5308 int command, int p1, int p2, int p3, String data) {
5309 enforceModifyPermission();
5310 if (DBG) {
5311 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5312 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5313 + p3 + " data=" + data);
5314 }
5315 return iccTransmitApduLogicalChannelWithPermission(
5316 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5317 data);
5318 }
5319
5320 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5321 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 final long identity = Binder.clearCallingIdentity();
5323 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005324 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 return "";
5326 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005329 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5330 null /* workSource */);
5331 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 // Append the returned status code to the end of the response payload.
5334 String s = Integer.toHexString(
5335 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5336 if (response.payload != null) {
5337 s = IccUtils.bytesToHexString(response.payload) + s;
5338 }
5339 return s;
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005342 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005343 }
Jake Hambye994d462014-02-03 13:10:13 -08005344
Evan Charltonc66da362014-05-16 14:06:40 -07005345 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005346 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5347 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5349 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005351 if (DBG) {
5352 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5353 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5354 }
5355 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5356 cla, command, p1, p2, p3, data);
5357 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005358
Jordan Liu4c733742019-02-28 12:03:40 -08005359 @Override
5360 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5361 int command, int p1, int p2, int p3, String data) {
5362 enforceModifyPermission();
5363 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5364 if (DBG) {
5365 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5366 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5367 + " data=" + data);
5368 }
5369
5370 return iccTransmitApduBasicChannelWithPermission(
5371 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5372 p2, p3, data);
5373 }
5374
5375 // open APDU basic channel assuming the caller has sufficient permissions
5376 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5377 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 final long identity = Binder.clearCallingIdentity();
5379 try {
5380 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5381 && TextUtils.equals(ISDR_AID, data)) {
5382 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005383 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5384 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 if (bestComponent == null
5386 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5387 loge("The calling package is not allowed to select ISD-R.");
5388 throw new SecurityException(
5389 "The calling package is not allowed to select ISD-R.");
5390 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005391 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005394 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5395 null /* workSource */);
5396 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 // Append the returned status code to the end of the response payload.
5399 String s = Integer.toHexString(
5400 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5401 if (response.payload != null) {
5402 s = IccUtils.bytesToHexString(response.payload) + s;
5403 }
5404 return s;
5405 } finally {
5406 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005407 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005408 }
5409
5410 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005411 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005412 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5414 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 final long identity = Binder.clearCallingIdentity();
5417 try {
5418 if (DBG) {
5419 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5420 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5421 }
5422
5423 IccIoResult response =
5424 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5425 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5426 subId);
5427
5428 if (DBG) {
5429 log("Exchange SIM_IO [R]" + response);
5430 }
5431
5432 byte[] result = null;
5433 int length = 2;
5434 if (response.payload != null) {
5435 length = 2 + response.payload.length;
5436 result = new byte[length];
5437 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5438 } else {
5439 result = new byte[length];
5440 }
5441
5442 result[length - 1] = (byte) response.sw2;
5443 result[length - 2] = (byte) response.sw1;
5444 return result;
5445 } finally {
5446 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005447 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005448 }
5449
Nathan Haroldb3014052017-01-25 15:57:32 -08005450 /**
5451 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5452 * on a particular subscription
5453 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005454 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5455 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005457 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005458 return null;
5459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460
5461 final long identity = Binder.clearCallingIdentity();
5462 try {
5463 if (appType != TelephonyManager.APPTYPE_USIM
5464 && appType != TelephonyManager.APPTYPE_SIM) {
5465 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5466 return null;
5467 }
5468 Object response = sendRequest(
5469 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5470 if (response instanceof String[]) {
5471 return (String[]) response;
5472 }
yincheng zhao2737e882019-09-06 17:06:54 -07005473 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005475 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 } finally {
5477 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005478 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005479 }
5480
yincheng zhao2737e882019-09-06 17:06:54 -07005481 /**
5482 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5483 * subscription.
5484 *
5485 * @param subId the id of the subscription.
5486 * @param appType the uicc app type, must be USIM or SIM.
5487 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5488 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005489 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005490 * @return number of fplmns that is successfully written to the SIM.
5491 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005492 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5493 String callingFeatureId) {
5494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5495 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005496 if (DBG) logv("no permissions for setForbiddenplmns");
5497 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5498 }
5499 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5500 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5501 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5502 }
5503 if (fplmns == null) {
5504 throw new IllegalArgumentException("Fplmn List provided is null");
5505 }
5506 for (String fplmn : fplmns) {
5507 if (!CellIdentity.isValidPlmn(fplmn)) {
5508 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5509 }
5510 }
5511 final long identity = Binder.clearCallingIdentity();
5512 try {
5513 Object response = sendRequest(
5514 CMD_SET_FORBIDDEN_PLMNS,
5515 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5516 subId);
5517 return (int) response;
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
5520 }
5521 }
5522
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005523 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005524 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5526 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5531 if (response.payload == null) {
5532 return "";
5533 }
Evan Charltonc66da362014-05-16 14:06:40 -07005534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535 // Append the returned status code to the end of the response payload.
5536 String s = Integer.toHexString(
5537 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5538 s = IccUtils.bytesToHexString(response.payload) + s;
5539 return s;
5540 } finally {
5541 Binder.restoreCallingIdentity(identity);
5542 }
Evan Charltonc66da362014-05-16 14:06:40 -07005543 }
5544
Jake Hambye994d462014-02-03 13:10:13 -08005545 /**
5546 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5547 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5548 *
5549 * @param itemID the ID of the item to read
5550 * @return the NV item as a String, or null on error.
5551 */
5552 @Override
5553 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005554 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5556 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557
5558 final long identity = Binder.clearCallingIdentity();
5559 try {
5560 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005561 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5563 return value;
5564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
Jake Hambye994d462014-02-03 13:10:13 -08005567 }
5568
5569 /**
5570 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5571 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5572 *
5573 * @param itemID the ID of the item to read
5574 * @param itemValue the value to write, as a String
5575 * @return true on success; false on any failure
5576 */
5577 @Override
5578 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005579 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5581 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582
5583 final long identity = Binder.clearCallingIdentity();
5584 try {
5585 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5586 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005587 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5589 return success;
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
Jake Hambye994d462014-02-03 13:10:13 -08005593 }
5594
5595 /**
5596 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5597 * Used for device configuration by some CDMA operators.
5598 *
5599 * @param preferredRoamingList byte array containing the new PRL
5600 * @return true on success; false on any failure
5601 */
5602 @Override
5603 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5605 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606
5607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5610 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5611 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5612 return success;
5613 } finally {
5614 Binder.restoreCallingIdentity(identity);
5615 }
Jake Hambye994d462014-02-03 13:10:13 -08005616 }
5617
5618 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005619 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005620 * Used for device configuration by some CDMA operators.
5621 *
chen xu6dac5ab2018-10-26 17:39:23 -07005622 * @param slotIndex - device slot.
5623 *
Jake Hambye994d462014-02-03 13:10:13 -08005624 * @return true on success; false on any failure
5625 */
5626 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005627 public boolean resetModemConfig(int slotIndex) {
5628 Phone phone = PhoneFactory.getPhone(slotIndex);
5629 if (phone != null) {
5630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5631 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632
chen xu6dac5ab2018-10-26 17:39:23 -07005633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5636 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5637 return success;
5638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 }
chen xu6dac5ab2018-10-26 17:39:23 -07005642 return false;
5643 }
5644
5645 /**
5646 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5647 *
5648 * @param slotIndex - device slot.
5649 *
5650 * @return true on success; false on any failure
5651 */
5652 @Override
5653 public boolean rebootModem(int slotIndex) {
5654 Phone phone = PhoneFactory.getPhone(slotIndex);
5655 if (phone != null) {
5656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5657 mApp, phone.getSubId(), "rebootModem");
5658
5659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5662 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5663 return success;
5664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
5667 }
5668 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005669 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005670
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005671 public String[] getPcscfAddress(String apnType, String callingPackage,
5672 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005673 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005674 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5675 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005676 return new String[0];
5677 }
5678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 final long identity = Binder.clearCallingIdentity();
5680 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005681 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
Wink Saville36469e72014-06-11 15:17:00 -07005685 }
5686
Brad Ebinger51f743a2017-01-23 13:50:20 -08005687 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005688 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5689 * {@link #disableIms(int)}.
5690 * @param slotIndex device slot.
5691 */
5692 public void resetIms(int slotIndex) {
5693 enforceModifyPermission();
5694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 if (mImsResolver == null) {
5698 // may happen if the does not support IMS.
5699 return;
5700 }
5701 mImsResolver.disableIms(slotIndex);
5702 mImsResolver.enableIms(slotIndex);
5703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
5706 }
5707
5708 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005709 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5710 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005711 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005712 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714
5715 final long identity = Binder.clearCallingIdentity();
5716 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005717 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005718 // may happen if the device does not support IMS.
5719 return;
5720 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005721 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005725 }
5726
5727 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005728 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5729 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005730 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005731 public void disableIms(int slotId) {
5732 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733
5734 final long identity = Binder.clearCallingIdentity();
5735 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005736 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005737 // may happen if the device does not support IMS.
5738 return;
5739 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005740 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005744 }
5745
5746 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005747 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5748 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005749 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005750 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005751 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005752 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753
5754 final long identity = Binder.clearCallingIdentity();
5755 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005756 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005757 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5758 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005759 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005760 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 } finally {
5762 Binder.restoreCallingIdentity(identity);
5763 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005764 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005765 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005766 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5767 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005768 @Override
5769 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005770 enforceModifyPermission();
5771
5772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005775 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
5779 }
5780
5781 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005782 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005783 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005784 */
5785 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787
5788 final long identity = Binder.clearCallingIdentity();
5789 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005790 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005791 // may happen if the device does not support IMS.
5792 return null;
5793 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005794 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005798 }
5799
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005800 /**
5801 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005802 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005803 */
5804 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5805 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806
5807 final long identity = Binder.clearCallingIdentity();
5808 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005809 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005810 // may happen if the device does not support IMS.
5811 return null;
5812 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005813 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005817 }
5818
Brad Ebinger884c07b2018-02-15 16:17:40 -08005819 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005820 * Sets the ImsService Package Name that Telephony will bind to.
5821 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 * @param slotIndex the slot ID that the ImsService should bind for.
5823 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005824 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005825 * @param featureTypes An integer array of feature types associated with a packageName.
5826 * @param packageName The name of the package that the current configuration will be replaced
5827 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005828 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005829 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005830 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5831 int[] featureTypes, String packageName) {
5832 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5835 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005836 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838 final long identity = Binder.clearCallingIdentity();
5839 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005840 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005841 // may happen if the device does not support IMS.
5842 return false;
5843 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005844 Map<Integer, String> featureConfig = new HashMap<>();
5845 for (int featureType : featureTypes) {
5846 featureConfig.put(featureType, packageName);
5847 }
5848 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5849 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 } finally {
5851 Binder.restoreCallingIdentity(identity);
5852 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005853 }
5854
5855 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005856 * Clears any carrier ImsService overrides for the slot index specified that were previously
5857 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5858 *
5859 * This should only be used for testing.
5860 *
5861 * @param slotIndex the slot ID that the ImsService should bind for.
5862 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5863 */
5864 @Override
5865 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5866 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5868 "clearCarrierImsServiceOverride");
5869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5870 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5871 "clearCarrierImsServiceOverride");
5872
5873 final long identity = Binder.clearCallingIdentity();
5874 try {
5875 if (mImsResolver == null) {
5876 // may happen if the device does not support IMS.
5877 return false;
5878 }
5879 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
5883 }
5884
5885 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005886 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005887 *
5888 * @param slotId The slot that the ImsService is associated with.
5889 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5890 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005891 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005892 * @return the package name of the ImsService configuration.
5893 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005894 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5895 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005896 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005897 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005898 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5900 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 final long identity = Binder.clearCallingIdentity();
5903 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005904 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005905 // may happen if the device does not support IMS.
5906 return "";
5907 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005908 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005909 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5910 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005914 }
5915
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005916 /**
5917 * Get the MmTelFeature state associated with the requested subscription id.
5918 * @param subId The subscription that the MmTelFeature is associated with.
5919 * @param callback A callback with an integer containing the
5920 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5921 */
5922 @Override
5923 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5924 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5925 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5926 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5927 "IMS not available on device.");
5928 }
5929 final long token = Binder.clearCallingIdentity();
5930 try {
5931 int slotId = getSlotIndex(subId);
5932 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5933 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5934 + subId + "'");
5935 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5936 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005937 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005938 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5939 try {
5940 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5941 } catch (RemoteException e) {
5942 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5943 + "Ignore");
5944 }
5945 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005946 } catch (ImsException e) {
5947 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005948 } finally {
5949 Binder.restoreCallingIdentity(token);
5950 }
5951 }
5952
Daniel Brightbb5840b2021-01-12 15:48:18 -08005953 /**
5954 * Sets the ims registration state on all valid {@link Phone}s.
5955 */
5956 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005957 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958
5959 final long identity = Binder.clearCallingIdentity();
5960 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005961 // NOTE: Before S, this method only set the default phone.
5962 for (final Phone phone : PhoneFactory.getPhones()) {
5963 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5964 phone.setImsRegistrationState(registered);
5965 }
5966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
Wink Saville36469e72014-06-11 15:17:00 -07005970 }
5971
5972 /**
Stuart Scott54788802015-03-30 13:18:01 -07005973 * Set the network selection mode to automatic.
5974 *
5975 */
5976 @Override
5977 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5979 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980
5981 final long identity = Binder.clearCallingIdentity();
5982 try {
shilufc958392020-01-20 11:36:01 -08005983 if (!isActiveSubscription(subId)) {
5984 return;
5985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005987 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5988 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 } finally {
5990 Binder.restoreCallingIdentity(identity);
5991 }
Stuart Scott54788802015-03-30 13:18:01 -07005992 }
5993
Jack Yud10cdd42020-09-28 20:28:01 -07005994 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005995 * Ask the radio to connect to the input network and change selection mode to manual.
5996 *
5997 * @param subId the id of the subscription.
5998 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5999 * the operator to attach to.
6000 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6001 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6002 * normal network selection next time.
6003 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006004 */
6005 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006006 public boolean setNetworkSelectionModeManual(
6007 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6009 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006010
6011 if (!isActiveSubscription(subId)) {
6012 return false;
6013 }
6014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 final long identity = Binder.clearCallingIdentity();
6016 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006017 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006019 if (DBG) {
6020 log("setNetworkSelectionModeManual: subId: " + subId
6021 + " operator: " + operatorInfo);
6022 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6024 } finally {
6025 Binder.restoreCallingIdentity(identity);
6026 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006027 }
shilu84f6e8b2019-12-19 13:58:01 -08006028 /**
6029 * Get the manual network selection
6030 *
6031 * @param subId the id of the subscription.
6032 *
6033 * @return the previously saved user selected PLMN
6034 */
6035 @Override
6036 public String getManualNetworkSelectionPlmn(int subId) {
6037 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006038 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006039 mApp, subId, "getManualNetworkSelectionPlmn");
6040
6041 final long identity = Binder.clearCallingIdentity();
6042 try {
6043 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006044 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006045 }
6046
6047 final Phone phone = getPhone(subId);
6048 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006049 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006050 }
6051 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6052 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6053 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6054 } finally {
6055 Binder.restoreCallingIdentity(identity);
6056 }
6057 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006058
6059 /**
6060 * Scans for available networks.
6061 */
6062 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006063 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6064 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6066 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006067 LocationAccessPolicy.LocationPermissionResult locationResult =
6068 LocationAccessPolicy.checkLocationPermission(mApp,
6069 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6070 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006071 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006072 .setCallingPid(Binder.getCallingPid())
6073 .setCallingUid(Binder.getCallingUid())
6074 .setMethod("getCellNetworkScanResults")
6075 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006076 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6077 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006078 .build());
6079 switch (locationResult) {
6080 case DENIED_HARD:
6081 throw new SecurityException("Not allowed to access scan results -- location");
6082 case DENIED_SOFT:
6083 return null;
6084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085
Pengquan Menga1bb6272018-09-06 09:59:22 -07006086 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 try {
6088 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006089 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006094 }
6095
6096 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006097 * Get the call forwarding info, given the call forwarding reason.
6098 */
6099 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006100 public void getCallForwarding(int subId, int callForwardingReason,
6101 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006102 enforceReadPrivilegedPermission("getCallForwarding");
6103 long identity = Binder.clearCallingIdentity();
6104 try {
6105 if (DBG) {
6106 log("getCallForwarding: subId " + subId
6107 + " callForwardingReason" + callForwardingReason);
6108 }
Hall Liu27d24262020-09-18 19:04:59 -07006109
6110 Phone phone = getPhone(subId);
6111 if (phone == null) {
6112 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006113 callback.onError(
6114 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006115 } catch (RemoteException e) {
6116 // ignore
6117 }
6118 return;
6119 }
6120
6121 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6122 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6123 @Override
6124 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6125 try {
6126 callback.onCallForwardingInfoAvailable(info);
6127 } catch (RemoteException e) {
6128 // ignore
6129 }
6130 }
6131
6132 @Override
6133 public void onError(int error) {
6134 try {
6135 callback.onError(error);
6136 } catch (RemoteException e) {
6137 // ignore
6138 }
6139 }
6140 });
6141 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006142 } finally {
6143 Binder.restoreCallingIdentity(identity);
6144 }
6145 }
6146
6147 /**
6148 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6149 * reason, the number to forward, and the timeout before the forwarding is attempted.
6150 */
6151 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006152 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6153 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006154 enforceModifyPermission();
6155 long identity = Binder.clearCallingIdentity();
6156 try {
6157 if (DBG) {
6158 log("setCallForwarding: subId " + subId
6159 + " callForwardingInfo" + callForwardingInfo);
6160 }
Hall Liu27d24262020-09-18 19:04:59 -07006161
6162 Phone phone = getPhone(subId);
6163 if (phone == null) {
6164 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006165 callback.accept(
6166 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006167 } catch (RemoteException e) {
6168 // ignore
6169 }
6170 return;
6171 }
6172
6173 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6174 FunctionalUtils.ignoreRemoteException(callback::accept));
6175
6176 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006177 } finally {
6178 Binder.restoreCallingIdentity(identity);
6179 }
6180 }
6181
6182 /**
Hall Liu27d24262020-09-18 19:04:59 -07006183 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006184 */
6185 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006186 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006187 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006188 long identity = Binder.clearCallingIdentity();
6189 try {
Hall Liu27d24262020-09-18 19:04:59 -07006190 Phone phone = getPhone(subId);
6191 if (phone == null) {
6192 try {
6193 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6194 } catch (RemoteException e) {
6195 // ignore
6196 }
6197 return;
6198 }
SongFerngWang0e767992021-03-31 22:08:45 +08006199 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6200 PersistableBundle c = configManager.getConfigForSubId(subId);
6201 boolean requireUssd = c.getBoolean(
6202 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006203
Shuo Qian4a594052020-01-23 11:59:30 -08006204 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006205 if (requireUssd) {
6206 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6207 getSubscriptionCarrierId(subId));
6208 String newUssdCommand = "";
6209 try {
6210 newUssdCommand = carrierXmlParser.getFeature(
6211 CarrierXmlParser.FEATURE_CALL_WAITING)
6212 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6213 } catch (NullPointerException e) {
6214 loge("Failed to generate USSD number" + e);
6215 }
6216 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6217 mMainThreadHandler, callback, carrierXmlParser,
6218 CarrierXmlParser.SsEntry.SSAction.QUERY);
6219 final String ussdCommand = newUssdCommand;
6220 Executors.newSingleThreadExecutor().execute(() -> {
6221 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6222 });
6223 } else {
6224 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6225 callback::accept);
6226 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6227 }
Shuo Qian4a594052020-01-23 11:59:30 -08006228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
6231 }
6232
6233 /**
Hall Liu27d24262020-09-18 19:04:59 -07006234 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006235 */
6236 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006237 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006238 enforceModifyPermission();
6239 long identity = Binder.clearCallingIdentity();
6240 try {
Hall Liu27d24262020-09-18 19:04:59 -07006241 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6242
6243 Phone phone = getPhone(subId);
6244 if (phone == null) {
6245 try {
6246 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6247 } catch (RemoteException e) {
6248 // ignore
6249 }
6250 return;
6251 }
6252
SongFerngWang0e767992021-03-31 22:08:45 +08006253 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6254 PersistableBundle c = configManager.getConfigForSubId(subId);
6255 boolean requireUssd = c.getBoolean(
6256 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006257
SongFerngWang0e767992021-03-31 22:08:45 +08006258 if (DBG) log("getCallWaitingStatus: subId " + subId);
6259 if (requireUssd) {
6260 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6261 getSubscriptionCarrierId(subId));
6262 CarrierXmlParser.SsEntry.SSAction ssAction =
6263 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6264 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6265 String newUssdCommand = "";
6266 try {
6267 newUssdCommand = carrierXmlParser.getFeature(
6268 CarrierXmlParser.FEATURE_CALL_WAITING)
6269 .makeCommand(ssAction, null);
6270 } catch (NullPointerException e) {
6271 loge("Failed to generate USSD number" + e);
6272 }
6273 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6274 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6275 final String ussdCommand = newUssdCommand;
6276 Executors.newSingleThreadExecutor().execute(() -> {
6277 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6278 });
6279 } else {
6280 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6281 FunctionalUtils.ignoreRemoteException(callback::accept));
6282
6283 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6284 }
Shuo Qian4a594052020-01-23 11:59:30 -08006285 } finally {
6286 Binder.restoreCallingIdentity(identity);
6287 }
6288 }
6289
6290 /**
yinxub1bed742017-04-17 11:45:04 -07006291 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006292 *
yinxub1bed742017-04-17 11:45:04 -07006293 * @param subId id of the subscription
6294 * @param request contains the radio access networks with bands/channels to scan
6295 * @param messenger callback messenger for scan results or errors
6296 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006297 * @return the id of the requested scan which can be used to stop the scan.
6298 */
6299 @Override
6300 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006301 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6303 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006304 LocationAccessPolicy.LocationPermissionResult locationResult =
6305 LocationAccessPolicy.checkLocationPermission(mApp,
6306 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6307 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006308 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006309 .setCallingPid(Binder.getCallingPid())
6310 .setCallingUid(Binder.getCallingUid())
6311 .setMethod("requestNetworkScan")
6312 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006313 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6314 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006315 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006316 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006317 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6318 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006319 if (e != null) {
6320 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6321 throw e;
6322 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006323 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006324 return TelephonyScanManager.INVALID_SCAN_ID;
6325 }
6326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 }
Hall Liu912dfd32019-04-25 14:02:26 -07006328 int callingUid = Binder.getCallingUid();
6329 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006330 final long identity = Binder.clearCallingIdentity();
6331 try {
6332 return mNetworkScanRequestTracker.startNetworkScan(
6333 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006334 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
yinxu504e1392017-04-12 16:03:22 -07006338 }
6339
Hall Liub2ac8ef2019-02-28 15:56:23 -08006340 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006341 NetworkScanRequest request, int subId, String callingPackage) {
6342 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006343 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6344 boolean hasNetworkScanPermission =
6345 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6346 == PERMISSION_GRANTED;
6347
6348 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6349 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6350 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006351 }
6352
6353 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6354 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006355 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6356 return new SecurityException("Specific channels must not be"
6357 + " scanned without location access.");
6358 }
6359 }
6360 }
6361
Hall Liub2ac8ef2019-02-28 15:56:23 -08006362 return null;
6363 }
6364
yinxu504e1392017-04-12 16:03:22 -07006365 /**
6366 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006367 *
6368 * @param subId id of the subscription
6369 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006370 */
6371 @Override
6372 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6374 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375
Hall Liu912dfd32019-04-25 14:02:26 -07006376 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 final long identity = Binder.clearCallingIdentity();
6378 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006379 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
yinxu504e1392017-04-12 16:03:22 -07006383 }
6384
6385 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006386 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006387 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006388 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006389 */
6390 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006391 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006392 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006393 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006394 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395
6396 final long identity = Binder.clearCallingIdentity();
6397 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006398 if (DBG) log("getAllowedNetworkTypesBitmask");
6399 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6400 int networkTypesBitmask = (result != null ? result[0] : -1);
6401 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6402 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 } finally {
6404 Binder.restoreCallingIdentity(identity);
6405 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006406 }
6407
6408 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006409 * Get the allowed network types for certain reason.
6410 *
6411 * @param subId the id of the subscription.
6412 * @param reason the reason the allowed network type change is taking place
6413 * @return the allowed network types.
6414 */
6415 @Override
6416 public long getAllowedNetworkTypesForReason(int subId,
6417 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006418 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006419 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006420 final long identity = Binder.clearCallingIdentity();
6421 try {
6422 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6423 } finally {
6424 Binder.restoreCallingIdentity(identity);
6425 }
6426 }
6427
6428 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006429 * Enable/Disable E-UTRA-NR Dual Connectivity
6430 * @param subId subscription id of the sim card
6431 * @param nrDualConnectivityState expected NR dual connectivity state
6432 * This can be passed following states
6433 * <ol>
6434 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6435 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6436 * <li>Disable NR dual connectivity and force secondary cell to be released
6437 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6438 * </ol>
6439 * @return operation result.
6440 */
6441 @Override
6442 public int setNrDualConnectivityState(int subId,
6443 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6445 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006446 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006447 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6448 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6449 }
6450
Sooraj Sasindran37444802020-08-11 10:40:43 -07006451 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6452 final long identity = Binder.clearCallingIdentity();
6453 try {
6454 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6455 nrDualConnectivityState, subId,
6456 workSource);
6457 if (DBG) log("enableNRDualConnectivity result: " + result);
6458 return result;
6459 } finally {
6460 Binder.restoreCallingIdentity(identity);
6461 }
6462 }
6463
6464 /**
6465 * Is E-UTRA-NR Dual Connectivity enabled
6466 * @return true if dual connectivity is enabled else false
6467 */
6468 @Override
6469 public boolean isNrDualConnectivityEnabled(int subId) {
6470 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006471 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006472 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006473 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006474 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6475 return false;
6476 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006477 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6478 final long identity = Binder.clearCallingIdentity();
6479 try {
6480 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6481 null, subId, workSource);
6482 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6483 return isEnabled;
6484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
6487 }
6488
6489 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006490 * Set the allowed network types of the device and
6491 * provide the reason triggering the allowed network change.
6492 *
6493 * @param subId the id of the subscription.
6494 * @param reason the reason the allowed network type change is taking place
6495 * @param allowedNetworkTypes the allowed network types.
6496 * @return true on success; false on any failure.
6497 */
6498 @Override
6499 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006500 @TelephonyManager.AllowedNetworkTypesReason int reason,
6501 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6503 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006504 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006505 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6506 return false;
6507 }
6508 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6509 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006510 return false;
6511 }
6512
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006513 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6514 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6515
6516
6517 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6518 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6519 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006520 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006521
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006522 final long identity = Binder.clearCallingIdentity();
6523 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006524 Boolean success = (Boolean) sendRequest(
6525 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6526 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6527
6528 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6529 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006530 } finally {
6531 Binder.restoreCallingIdentity(identity);
6532 }
6533 }
6534
6535 /**
Miaoa84611c2019-03-15 09:21:10 +08006536 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006537 *
Miaoa84611c2019-03-15 09:21:10 +08006538 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006539 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006540 * @hide
6541 */
6542 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006543 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006546 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 try {
Miaoa84611c2019-03-15 09:21:10 +08006548 if (phone != null) {
6549 return phone.hasMatchedTetherApnSetting();
6550 } else {
6551 return false;
6552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553 } finally {
6554 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006555 }
Junda Liu475951f2014-11-07 16:45:03 -08006556 }
6557
6558 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006559 * Get the user enabled state of Mobile Data.
6560 *
6561 * TODO: remove and use isUserDataEnabled.
6562 * This can't be removed now because some vendor codes
6563 * calls through ITelephony directly while they should
6564 * use TelephonyManager.
6565 *
6566 * @return true on enabled
6567 */
6568 @Override
6569 public boolean getDataEnabled(int subId) {
6570 return isUserDataEnabled(subId);
6571 }
6572
6573 /**
6574 * Get whether mobile data is enabled per user setting.
6575 *
6576 * There are other factors deciding whether mobile data is actually enabled, but they are
6577 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006578 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006579 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006580 *
6581 * @return {@code true} if data is enabled else {@code false}
6582 */
6583 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006584 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006585 try {
6586 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6587 null);
6588 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6590 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592
6593 final long identity = Binder.clearCallingIdentity();
6594 try {
6595 int phoneId = mSubscriptionController.getPhoneId(subId);
6596 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6597 Phone phone = PhoneFactory.getPhone(phoneId);
6598 if (phone != null) {
6599 boolean retVal = phone.isUserDataEnabled();
6600 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6601 return retVal;
6602 } else {
6603 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6604 return false;
6605 }
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006608 }
6609 }
6610
6611 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006612 * Checks if the device is capable of mobile data by considering whether whether the
6613 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6614 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006615 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006616 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006617 */
6618 @Override
6619 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006620 try {
6621 try {
6622 mApp.enforceCallingOrSelfPermission(
6623 android.Manifest.permission.ACCESS_NETWORK_STATE,
6624 null);
6625 } catch (Exception e) {
6626 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6627 "isDataEnabled");
6628 }
6629 } catch (Exception e) {
6630 enforceReadPrivilegedPermission("isDataEnabled");
6631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006632
6633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 int phoneId = mSubscriptionController.getPhoneId(subId);
6636 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6637 Phone phone = PhoneFactory.getPhone(phoneId);
6638 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006639 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6641 return retVal;
6642 } else {
6643 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6644 return false;
6645 }
6646 } finally {
6647 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006648 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006649 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006650
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006651 /**
6652 * Check if data is enabled for a specific reason
6653 * @param subId Subscription index
6654 * @param reason the reason the data enable change is taking place
6655 * @return {@code true} if the overall data is enabled; {@code false} if not.
6656 */
6657 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006658 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006659 @TelephonyManager.DataEnabledReason int reason) {
6660 try {
6661 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6662 null);
6663 } catch (Exception e) {
6664 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006666 }
6667
6668
6669 final long identity = Binder.clearCallingIdentity();
6670 try {
6671 int phoneId = mSubscriptionController.getPhoneId(subId);
6672 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006673 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006674 + " reason=" + reason);
6675 }
6676 Phone phone = PhoneFactory.getPhone(phoneId);
6677 if (phone != null) {
6678 boolean retVal;
6679 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6680 retVal = phone.isUserDataEnabled();
6681 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006682 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006683 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006684 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006685 return retVal;
6686 } else {
6687 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006688 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006689 + subId + " retVal=false");
6690 }
6691 return false;
6692 }
6693 } finally {
6694 Binder.restoreCallingIdentity(identity);
6695 }
6696 }
6697
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006698 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006699 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006700 if (uid == Process.PHONE_UID) {
6701 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6702 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006703 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6704 }
6705
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006706 //load access rules from carrier configs, and check those as well: b/139133814
6707 SubscriptionController subController = SubscriptionController.getInstance();
6708 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6709 || subController == null) return privilegeFromSim;
6710
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006711 PackageManager pkgMgr = phone.getContext().getPackageManager();
6712 String[] packages = pkgMgr.getPackagesForUid(uid);
6713
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006716 int subId = phone.getSubId();
6717 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6718 // A test override is in place for the privileges for this subId, so don't try to
6719 // read the subscription privileges.
6720 return privilegeFromSim;
6721 }
6722 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006723 SubscriptionManager subManager = (SubscriptionManager)
6724 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6725 for (String pkg : packages) {
6726 if (subManager.canManageSubscription(subInfo, pkg)) {
6727 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6728 }
6729 }
6730 return privilegeFromSim;
6731 } finally {
6732 Binder.restoreCallingIdentity(identity);
6733 }
6734 }
6735
6736 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6737 String pkgName) {
6738 //load access rules from carrier configs, and check those as well: b/139133814
6739 SubscriptionController subController = SubscriptionController.getInstance();
6740 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6741 || subController == null) return privilegeFromSim;
6742
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006745 int subId = phone.getSubId();
6746 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6747 // A test override is in place for the privileges for this subId, so don't try to
6748 // read the subscription privileges.
6749 return privilegeFromSim;
6750 }
6751 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006752 SubscriptionManager subManager = (SubscriptionManager)
6753 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6754 return subManager.canManageSubscription(subInfo, pkgName)
6755 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
6758 }
6759 }
6760
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006761 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006762 public int getCarrierPrivilegeStatus(int subId) {
6763 final Phone phone = getPhone(subId);
6764 if (phone == null) {
6765 loge("getCarrierPrivilegeStatus: Invalid subId");
6766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6767 }
6768 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006769 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006770 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6772 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006773
6774 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6775 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006776 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006777 }
Junda Liu29340342014-07-10 15:23:27 -07006778
6779 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006780 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006781 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 final Phone phone = getPhone(subId);
6783 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006784 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006785 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6786 }
6787 UiccProfile profile =
6788 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6789 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006790 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6792 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006793 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006794 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006795 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006796 }
6797
6798 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006799 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006800 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006801 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006802 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006803 }
6804
6805 int phoneId = SubscriptionManager.getPhoneId(subId);
6806 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006807 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006808 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006809 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6810 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006811 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6812 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6813 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006814 }
6815
6816 @Override
6817 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006818 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006819 if (TextUtils.isEmpty(pkgName))
6820 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006821 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6822 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6823 UiccCard card = UiccController.getInstance().getUiccCard(i);
6824 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006825 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006826 continue;
6827 }
6828
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006829 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6830 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6831 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006832 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6833 break;
6834 }
6835 }
6836
6837 return result;
Junda Liu29340342014-07-10 15:23:27 -07006838 }
Derek Tan89e89d42014-07-08 17:00:10 -07006839
6840 @Override
Junda Liue64de782015-04-16 17:19:16 -07006841 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006842 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006843 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6844 loge("phoneId " + phoneId + " is not valid.");
6845 return null;
6846 }
6847 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006848 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006849 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006850 return null ;
6851 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006852 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006853 }
6854
Amith Yamasani6e118872016-02-19 12:53:51 -08006855 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006856 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006857 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006858 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006859 List<String> privilegedPackages = new ArrayList<>();
6860 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006861 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6862 // has UICC in that slot.
6863 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006864 if (card.hasCarrierPrivilegeRules()) {
6865 if (packages == null) {
6866 // Only check packages in user 0 for now
6867 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006868 PackageManager.MATCH_DISABLED_COMPONENTS
6869 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006870 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006871 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006872 }
6873 for (int p = packages.size() - 1; p >= 0; p--) {
6874 PackageInfo pkgInfo = packages.get(p);
6875 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006876 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6877 card.getCarrierPrivilegeStatus(pkgInfo),
6878 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006879 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006880 privilegedPackages.add(pkgInfo.packageName);
6881 }
6882 }
6883 }
6884 }
6885 return privilegedPackages;
6886 }
6887
chen xuf7e9fe82019-05-09 19:31:02 -07006888 @Override
6889 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006890 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6891
6892 final long identity = Binder.clearCallingIdentity();
6893
chen xuf7e9fe82019-05-09 19:31:02 -07006894 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006895 try {
6896 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6897 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6898 }
6899 } finally {
6900 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006901 }
6902 return privilegedPackages;
6903 }
6904
Wink Savilleb564aae2014-10-23 10:18:09 -07006905 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006906 final Phone phone = getPhone(subId);
6907 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006908 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006909 return null;
6910 }
6911 String iccId = card.getIccId();
6912 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006913 return null;
6914 }
6915 return iccId;
6916 }
6917
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006918 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006919 public void setCallComposerStatus(int subId, int status) {
6920 enforceModifyPermission();
6921
6922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 Phone phone = getPhone(subId);
6925 if (phone != null) {
6926 Phone defaultPhone = phone.getImsPhone();
6927 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6928 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6929 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006930 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6931 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006932 }
6933 }
Shuo Qian284ae752020-12-22 19:10:14 -08006934 } catch (ImsException e) {
6935 throw new ServiceSpecificException(e.getCode());
6936 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006937 Binder.restoreCallingIdentity(identity);
6938 }
6939 }
6940
6941 @Override
6942 public int getCallComposerStatus(int subId) {
6943 enforceReadPrivilegedPermission("getCallComposerStatus");
6944
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
6947 Phone phone = getPhone(subId);
6948 if (phone != null) {
6949 Phone defaultPhone = phone.getImsPhone();
6950 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6951 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6952 return imsPhone.getCallComposerStatus();
6953 }
6954 }
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
6958 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6959 }
6960
6961 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006962 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6963 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006964 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006965 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 final String iccId = getIccId(subId);
6970 final Phone phone = getPhone(subId);
6971 if (phone == null) {
6972 return false;
6973 }
6974 final String subscriberId = phone.getSubscriberId();
6975
6976 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006977 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 + subscriberId + " to " + number);
6979 }
6980
6981 if (TextUtils.isEmpty(iccId)) {
6982 return false;
6983 }
6984
6985 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6986
6987 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6988 if (alphaTag == null) {
6989 editor.remove(alphaTagPrefKey);
6990 } else {
6991 editor.putString(alphaTagPrefKey, alphaTag);
6992 }
6993
6994 // Record both the line number and IMSI for this ICCID, since we need to
6995 // track all merged IMSIs based on line number
6996 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6997 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6998 if (number == null) {
6999 editor.remove(numberPrefKey);
7000 editor.remove(subscriberPrefKey);
7001 } else {
7002 editor.putString(numberPrefKey, number);
7003 editor.putString(subscriberPrefKey, subscriberId);
7004 }
7005
7006 editor.commit();
7007 return true;
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007010 }
Derek Tan7226c842014-07-02 17:42:23 -07007011 }
7012
7013 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007014 public String getLine1NumberForDisplay(int subId, String callingPackage,
7015 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007016 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007018 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007019 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007020 return null;
7021 }
Derek Tan97ebb422014-09-05 16:55:38 -07007022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 String iccId = getIccId(subId);
7026 if (iccId != null) {
7027 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7028 if (DBG_MERGE) {
7029 log("getLine1NumberForDisplay returning "
7030 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7031 }
7032 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7035 return null;
7036 } finally {
7037 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007038 }
Derek Tan7226c842014-07-02 17:42:23 -07007039 }
7040
7041 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007042 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7043 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007045 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007046 return null;
7047 }
Derek Tan97ebb422014-09-05 16:55:38 -07007048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 final long identity = Binder.clearCallingIdentity();
7050 try {
7051 String iccId = getIccId(subId);
7052 if (iccId != null) {
7053 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7054 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7055 }
7056 return null;
7057 } finally {
7058 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007059 }
Derek Tan7226c842014-07-02 17:42:23 -07007060 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007061
7062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007063 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7064 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007065 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7066 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007068 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007069 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007070 return null;
7071 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007072
Jordan Liub49b04b2019-05-06 14:45:15 -07007073 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7074 // the process, where TelephonyManager was instantiated.
7075 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007076 final long identity = Binder.clearCallingIdentity();
7077 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007078 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 final TelephonyManager tele = TelephonyManager.from(context);
7080 final SubscriptionManager sub = SubscriptionManager.from(context);
7081
7082 // Figure out what subscribers are currently active
7083 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084
Jordan Liub49b04b2019-05-06 14:45:15 -07007085 // Only consider subs which match the current subId
7086 // This logic can be simplified. See b/131189269 for progress.
7087 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007088 activeSubscriberIds.add(tele.getSubscriberId(subId));
7089 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090
7091 // First pass, find a number override for an active subscriber
7092 String mergeNumber = null;
7093 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7094 for (String key : prefs.keySet()) {
7095 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7096 final String subscriberId = (String) prefs.get(key);
7097 if (activeSubscriberIds.contains(subscriberId)) {
7098 final String iccId = key.substring(
7099 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7100 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7101 mergeNumber = (String) prefs.get(numberKey);
7102 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007103 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 + " for active subscriber " + subscriberId);
7105 }
7106 if (!TextUtils.isEmpty(mergeNumber)) {
7107 break;
7108 }
7109 }
7110 }
7111 }
7112
7113 // Shortcut when no active merged subscribers
7114 if (TextUtils.isEmpty(mergeNumber)) {
7115 return null;
7116 }
7117
7118 // Second pass, find all subscribers under that line override
7119 final ArraySet<String> result = new ArraySet<>();
7120 for (String key : prefs.keySet()) {
7121 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7122 final String number = (String) prefs.get(key);
7123 if (mergeNumber.equals(number)) {
7124 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7125 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7126 final String subscriberId = (String) prefs.get(subscriberKey);
7127 if (!TextUtils.isEmpty(subscriberId)) {
7128 result.add(subscriberId);
7129 }
7130 }
7131 }
7132 }
7133
7134 final String[] resultArray = result.toArray(new String[result.size()]);
7135 Arrays.sort(resultArray);
7136 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007137 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7139 }
7140 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007141 } finally {
7142 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007143 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007144 }
7145
7146 @Override
zoey chen38003472019-12-13 17:16:31 +08007147 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7148 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007149
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 final TelephonyManager telephonyManager = mApp.getSystemService(
7153 TelephonyManager.class);
7154 String subscriberId = telephonyManager.getSubscriberId(subId);
7155 if (subscriberId == null) {
7156 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007157 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007158 + subId);
7159 }
7160 return null;
7161 }
7162
7163 final SubscriptionInfo info = SubscriptionController.getInstance()
7164 .getSubscriptionInfo(subId);
7165 final ParcelUuid groupUuid = info.getGroupUuid();
7166 // If it doesn't belong to any group, return just subscriberId of itself.
7167 if (groupUuid == null) {
7168 return new String[]{subscriberId};
7169 }
7170
7171 // Get all subscriberIds from the group.
7172 final List<String> mergedSubscriberIds = new ArrayList<>();
7173 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007174 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007175 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007176 for (SubscriptionInfo subInfo : groupInfos) {
7177 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7178 if (subscriberId != null) {
7179 mergedSubscriberIds.add(subscriberId);
7180 }
7181 }
7182
7183 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186
7187 }
7188 }
7189
7190 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007191 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007192 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007193 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194
7195 final long identity = Binder.clearCallingIdentity();
7196 try {
7197 final Phone phone = getPhone(subId);
7198 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7199 } finally {
7200 Binder.restoreCallingIdentity(identity);
7201 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007202 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007203
7204 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007205 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007206 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7207 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007208 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7209 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210
7211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 final Phone phone = getPhone(subId);
7214 if (phone == null) {
7215 return false;
7216 }
7217 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7218 cdmaNonRoamingList);
7219 } finally {
7220 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007221 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007222 }
7223
7224 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007225 @Deprecated
7226 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7227 enforceModifyPermission();
7228
7229 int returnValue = 0;
7230 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007231 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007232 if(result.exception == null) {
7233 if (result.result != null) {
7234 byte[] responseData = (byte[])(result.result);
7235 if(responseData.length > oemResp.length) {
7236 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7237 responseData.length + "bytes. Buffer Size is " +
7238 oemResp.length + "bytes.");
7239 }
7240 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7241 returnValue = responseData.length;
7242 }
7243 } else {
7244 CommandException ex = (CommandException) result.exception;
7245 returnValue = ex.getCommandError().ordinal();
7246 if(returnValue > 0) returnValue *= -1;
7247 }
7248 } catch (RuntimeException e) {
7249 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7250 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7251 if(returnValue > 0) returnValue *= -1;
7252 }
7253
7254 return returnValue;
7255 }
7256
7257 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007258 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007259 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007260 try {
7261 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007262 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007263 mApp, phone.getSubId(), "getRadioAccessFamily");
7264 } catch (SecurityException e) {
7265 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7266 throw e;
7267 }
chen xub97461a2018-10-26 14:17:57 -07007268 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007269 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007270 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 final long identity = Binder.clearCallingIdentity();
7273 try {
chen xub97461a2018-10-26 14:17:57 -07007274 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007275 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007276 mApp, phone.getSubId(), "getRadioAccessFamily");
7277 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
chen xub97461a2018-10-26 14:17:57 -07007281 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007282 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007283
7284 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007285 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007286 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007287 try {
7288 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7289 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007290 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007291 }
7292 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007293 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007294 }
7295 RoleManager rm = mApp.getSystemService(RoleManager.class);
7296 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7297 if (!dialerRoleHolders.contains(callingPackage)) {
7298 throw new SecurityException("App must be the dialer role holder to"
7299 + " upload a call composer pic");
7300 }
7301
7302 Executors.newSingleThreadExecutor().execute(() -> {
7303 ByteArrayOutputStream output = new ByteArrayOutputStream(
7304 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7305 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7306 boolean readUntilEnd = false;
7307 int totalBytesRead = 0;
7308 byte[] buffer = new byte[16 * 1024];
7309 while (true) {
7310 int numRead;
7311 try {
7312 numRead = input.read(buffer);
7313 } catch (IOException e) {
7314 try {
7315 fd.checkError();
7316 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7317 null);
7318 } catch (IOException e1) {
7319 // This means that the other side closed explicitly with an error. If this
7320 // happens, log and ignore.
7321 loge("Remote end of call composer picture pipe closed: " + e1);
7322 }
7323 break;
7324 }
7325 if (numRead == -1) {
7326 readUntilEnd = true;
7327 break;
7328 }
7329 totalBytesRead += numRead;
7330 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7331 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7332 try {
7333 input.close();
7334 } catch (IOException e) {
7335 // ignore
7336 }
7337 break;
7338 }
7339 output.write(buffer, 0, numRead);
7340 }
7341 // Generally, the remote end will close the file descriptors. The only case where we
7342 // close is above, where the picture size is too big.
7343
7344 try {
7345 fd.checkError();
7346 } catch (IOException e) {
7347 loge("Remote end for call composer closed with an error: " + e);
7348 return;
7349 }
7350
Hall Liuaa4211e2021-01-20 15:43:39 -08007351 if (!readUntilEnd) {
7352 loge("Did not finish reading entire image; aborting");
7353 return;
7354 }
Hall Liu82694d52020-12-11 18:22:04 -08007355
Hall Liuaa4211e2021-01-20 15:43:39 -08007356 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7357 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7358 new CallComposerPictureTransfer.Factory() {},
7359 imageData,
7360 (result) -> {
7361 if (result.first != null) {
7362 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7363 Bundle outputResult = new Bundle();
7364 outputResult.putParcelable(
7365 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7366 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7367 outputResult);
7368 } else {
7369 callback.send(result.second, null);
7370 }
7371 }
7372 );
Hall Liu82694d52020-12-11 18:22:04 -08007373 });
7374 }
7375
7376 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007377 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007378 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007379 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380
7381 final long identity = Binder.clearCallingIdentity();
7382 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007383 ImsManager.getInstance(defaultPhone.getContext(),
7384 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 } finally {
7386 Binder.restoreCallingIdentity(identity);
7387 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007388 }
7389
7390 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007391 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007392 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7394 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007395 return false;
7396 }
Svet Ganovb320e182015-04-16 12:30:10 -07007397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 final long identity = Binder.clearCallingIdentity();
7399 try {
7400 // Check the user preference and the system-level IMS setting. Even if the user has
7401 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7402 // In the long run, we may instead need to check if there exists a connection service
7403 // which can support video calling.
7404 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007405 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 return imsManager.isVtEnabledByPlatform()
7407 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7408 && imsManager.isVtEnabledByUser();
7409 } finally {
7410 Binder.restoreCallingIdentity(identity);
7411 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007412 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007413
Andrew Leea1239f22015-03-02 17:44:07 -08007414 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007415 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7416 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007418 mApp, subId, callingPackage, callingFeatureId,
7419 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 return false;
7421 }
7422
7423 final long identity = Binder.clearCallingIdentity();
7424 try {
7425 CarrierConfigManager configManager =
7426 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
7431 }
Andrew Leea1239f22015-03-02 17:44:07 -08007432 }
7433
7434 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007435 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007437 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 return false;
7439 }
7440
7441 final long identity = Binder.clearCallingIdentity();
7442 try {
7443 CarrierConfigManager configManager =
7444 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
Andrew Leea1239f22015-03-02 17:44:07 -08007450 }
7451
Andrew Lee9431b832015-03-09 18:46:45 -07007452 @Override
7453 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007454 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007455 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007456 }
7457
7458 @Override
7459 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 final long identity = Binder.clearCallingIdentity();
7461 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007462 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 } finally {
7464 Binder.restoreCallingIdentity(identity);
7465 }
Andrew Lee9431b832015-03-09 18:46:45 -07007466 }
7467
Hall Liuf6668912018-10-31 17:05:23 -07007468 /**
7469 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7470 * support for the feature and device firmware support.
7471 *
7472 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7473 */
7474 @Override
7475 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007477 final Phone phone = getPhone(subscriptionId);
7478 if (phone == null) {
7479 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7480 return false;
7481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007483 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7485 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007486 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 return isCarrierSupported && isDeviceSupported;
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Hall Liu98187582018-01-22 19:15:32 -08007491 }
7492
Hall Liuf6668912018-10-31 17:05:23 -07007493 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007494 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7495 * RTT setting, will return true if the device and carrier both support RTT.
7496 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007497 */
7498 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 final long identity = Binder.clearCallingIdentity();
7500 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007501 boolean isRttSupported = isRttSupported(subscriptionId);
7502 boolean isUserRttSettingOn = Settings.Secure.getInt(
7503 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7504 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7505 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7506 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007510 }
7511
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007512 @Deprecated
7513 @Override
7514 public String getDeviceId(String callingPackage) {
7515 return getDeviceIdWithFeature(callingPackage, null);
7516 }
7517
Sanket Padawe7310cc72015-01-14 09:53:20 -08007518 /**
7519 * Returns the unique device ID of phone, for example, the IMEI for
7520 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7521 *
7522 * <p>Requires Permission:
7523 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7524 */
7525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007527 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007528 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007529 return null;
7530 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007531 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007532 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007533 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007534 return null;
7535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536
7537 final long identity = Binder.clearCallingIdentity();
7538 try {
7539 return phone.getDeviceId();
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007543 }
7544
Ping Sunc67b7c22016-03-02 19:16:45 +08007545 /**
7546 * {@hide}
7547 * Returns the IMS Registration Status on a particular subid
7548 *
7549 * @param subId
7550 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007551 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007552 Phone phone = getPhone(subId);
7553 if (phone != null) {
7554 return phone.isImsRegistered();
7555 } else {
7556 return false;
7557 }
7558 }
7559
Santos Cordon7a1885b2015-02-03 11:15:19 -08007560 @Override
7561 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 final long identity = Binder.clearCallingIdentity();
7563 try {
7564 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7565 } finally {
7566 Binder.restoreCallingIdentity(identity);
7567 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007568 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007569
Tyler Gunnf70ed162019-04-03 15:28:53 -07007570 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007571 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007572 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007574 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007575 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7576 }
7577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7580 } finally {
7581 Binder.restoreCallingIdentity(identity);
7582 }
7583 }
7584
7585 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007586 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007587 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007588 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007589 mApp,
7590 subscriptionId,
7591 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007592 final long identity = Binder.clearCallingIdentity();
7593 try {
7594 Phone phone = getPhone(subscriptionId);
7595 if (phone == null) {
7596 return null;
7597 }
7598 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
7601 }
7602 }
7603
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007604 /**
7605 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007606 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007607 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007608 final long identity = Binder.clearCallingIdentity();
7609 try {
7610 Phone phone = getPhone(subId);
7611 if (phone != null) {
7612 return phone.isWifiCallingEnabled();
7613 } else {
7614 return false;
7615 }
7616 } finally {
7617 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007618 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007619 }
7620
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007621 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007622 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007623 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007624 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625 final long identity = Binder.clearCallingIdentity();
7626 try {
7627 Phone phone = getPhone(subId);
7628 if (phone != null) {
7629 return phone.isVideoEnabled();
7630 } else {
7631 return false;
7632 }
7633 } finally {
7634 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007635 }
7636 }
7637
7638 /**
7639 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7640 * defined in {@link ImsRegistrationImplBase}.
7641 */
7642 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 final long identity = Binder.clearCallingIdentity();
7644 try {
7645 Phone phone = getPhone(subId);
7646 if (phone != null) {
7647 return phone.getImsRegistrationTech();
7648 } else {
7649 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7650 }
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007653 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007654 }
7655
Stuart Scott8eef64f2015-04-08 15:13:54 -07007656 @Override
7657 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007658 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007659 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7660 return;
7661 }
Kai Shif70f46f2021-03-03 13:59:46 -08007662 Phone defaultPhone = getDefaultPhone();
7663 if (defaultPhone != null) {
7664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7665 mApp, getDefaultPhone().getSubId(), "factoryReset");
7666 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007667 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007668
Svet Ganovcc087f82015-05-12 20:35:54 -07007669 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007670 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7671 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007672 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007673 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007674 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007675 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007676 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007677 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007678 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007679 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007680 // There has been issues when Sms raw table somehow stores orphan
7681 // fragments. They lead to garbled message when new fragments come
7682 // in and combined with those stale ones. In case this happens again,
7683 // user can reset all network settings which will clean up this table.
7684 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007685 // Clean up IMS settings as well here.
7686 int slotId = getSlotIndex(subId);
7687 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7688 ImsManager.getInstance(mApp, slotId).factoryReset();
7689 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007690
Kai Shif70f46f2021-03-03 13:59:46 -08007691 if (defaultPhone == null) {
7692 return;
7693 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007694 // Erase modem config if erase modem on network setting is enabled.
7695 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7696 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7697 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007698 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007699 }
Kai Shif70f46f2021-03-03 13:59:46 -08007700
7701 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007702 } finally {
7703 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007704 }
7705 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007706
SongFerngWangfd89b102021-05-27 22:44:54 +08007707 @VisibleForTesting
7708 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7709 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7710 return;
7711 }
7712 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7713 RILConstants.PREFERRED_NETWORK_MODE);
7714 SubscriptionManager.setSubscriptionProperty(subId,
7715 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7716 "user=" + defaultNetworkType);
7717 phone.loadAllowedNetworksFromSubscriptionDatabase();
7718 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7719 defaultNetworkType, null);
7720 }
7721
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007722 private void cleanUpSmsRawTable(Context context) {
7723 ContentResolver resolver = context.getContentResolver();
7724 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7725 resolver.delete(uri, null, null);
7726 }
7727
Narayan Kamath1c496c22015-04-16 14:40:19 +01007728 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007729 public String getSimLocaleForSubscriber(int subId) {
7730 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7731 final Phone phone = getPhone(subId);
7732 if (phone == null) {
7733 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007734 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007736 final long identity = Binder.clearCallingIdentity();
7737 try {
chen xu5d3637b2019-01-21 23:31:38 -08007738 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007739 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007740 if (info == null) {
7741 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7742 return null;
7743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744 // Try and fetch the locale from the carrier properties or from the SIM language
7745 // preferences (EF-PL and EF-LI)...
7746 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007748 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7749 if (localeFromDefaultSim != null) {
7750 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7751 if (DBG) log("Using locale from subId: " + subId + " locale: "
7752 + localeFromDefaultSim);
7753 return localeFromDefaultSim.toLanguageTag();
7754 } else {
7755 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 }
7757 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 // The SIM language preferences only store a language (e.g. fr = French), not an
7760 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7761 // the SIM and carrier preferences does not include a country we add the country
7762 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007763 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007765 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 return mccLocale.toLanguageTag();
7767 }
7768
7769 if (DBG) log("No locale found - returning null");
7770 return null;
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
7773 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007774 }
7775
7776 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007777 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007778 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007779 }
7780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 /**
7782 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7783 */
7784 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007785 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007786 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007787 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007788
Chenjie Yu1ba97252018-01-11 18:16:20 -08007789 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007790 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007791
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007792 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007793 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7794 * representing the state of the modem.
7795 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007796 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7797 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007798 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007799 */
7800 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007801 public void requestModemActivityInfo(ResultReceiver result) {
7802 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007803 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804
7805 final long identity = Binder.clearCallingIdentity();
7806 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007807 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 } finally {
7809 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007810 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007811 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007812
Siddharth Rayb8114062018-06-17 15:02:38 -07007813 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7814 // less than total activity duration.
7815 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7816 if (info == null) {
7817 return false;
7818 }
7819 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007820 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7821 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7822
Siddharth Rayb8114062018-06-17 15:02:38 -07007823 return (info.isValid()
7824 && (info.getSleepTimeMillis() <= activityDurationMs)
7825 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007826 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007827 && (totalTxTimeMs <= activityDurationMs));
7828 }
7829
Jack Yu85bd38a2015-11-09 11:34:32 -08007830 /**
7831 * {@hide}
7832 * Returns the service state information on specified subscription.
7833 */
7834 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007835 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7836 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007838 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007839 return null;
7840 }
7841
Hall Liuf19c44f2018-11-27 14:38:17 -08007842 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7843 LocationAccessPolicy.checkLocationPermission(mApp,
7844 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7845 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007846 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007847 .setCallingPid(Binder.getCallingPid())
7848 .setCallingUid(Binder.getCallingUid())
7849 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007850 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007851 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007852 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7853 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007854 .build());
7855
7856 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7857 LocationAccessPolicy.checkLocationPermission(mApp,
7858 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7859 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007860 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007861 .setCallingPid(Binder.getCallingPid())
7862 .setCallingUid(Binder.getCallingUid())
7863 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007864 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007865 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007866 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7867 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007868 .build());
7869 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7870 boolean hasFinePermission =
7871 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7872 boolean hasCoarsePermission =
7873 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7874
Jack Yu479f40e2020-10-27 21:29:25 -07007875 final Phone phone = getPhone(subId);
7876 if (phone == null) {
7877 return null;
7878 }
7879
Jordan Liu0f2bc442020-11-18 16:47:37 -08007880 final long identity = Binder.clearCallingIdentity();
7881
Jack Yu479f40e2020-10-27 21:29:25 -07007882 boolean isCallingPackageDataService = phone.getDataServicePackages()
7883 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007884 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007885 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7886 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7887 Rlog.d(LOG_TAG,
7888 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7889 return null;
7890 }
7891
Hall Liuf19c44f2018-11-27 14:38:17 -08007892 ServiceState ss = phone.getServiceState();
7893
7894 // Scrub out the location info in ServiceState depending on what level of access
7895 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007896 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007897 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7898 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 } finally {
7900 Binder.restoreCallingIdentity(identity);
7901 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007902 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007903
7904 /**
7905 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7906 *
7907 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7908 * voicemail ringtone.
7909 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7910 * PhoneAccount.
7911 */
7912 @Override
7913 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 final long identity = Binder.clearCallingIdentity();
7915 try {
7916 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7917 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007918 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007919 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7922 } finally {
7923 Binder.restoreCallingIdentity(identity);
7924 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007925 }
7926
7927 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007928 * Sets the per-account voicemail ringtone.
7929 *
7930 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7931 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7932 *
7933 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7934 * voicemail ringtone.
7935 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7936 * PhoneAccount.
7937 */
7938 @Override
7939 public void setVoicemailRingtoneUri(String callingPackage,
7940 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007941 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007942 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007943 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7944 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7946 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7947 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007949
7950 final long identity = Binder.clearCallingIdentity();
7951 try {
7952 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7953 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007954 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 }
7956 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7957 } finally {
7958 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007959 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007960 }
7961
7962 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007963 * Returns whether vibration is set for voicemail notification in Phone settings.
7964 *
7965 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7966 * voicemail vibration setting.
7967 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7968 */
7969 @Override
7970 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971 final long identity = Binder.clearCallingIdentity();
7972 try {
7973 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7974 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007975 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007976 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7979 } finally {
7980 Binder.restoreCallingIdentity(identity);
7981 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007982 }
7983
Youhan Wange64578a2016-05-02 15:32:42 -07007984 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007985 * Sets the per-account voicemail vibration.
7986 *
7987 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7988 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7989 *
7990 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7991 * voicemail vibration setting.
7992 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7993 * specific PhoneAccount.
7994 */
7995 @Override
7996 public void setVoicemailVibrationEnabled(String callingPackage,
7997 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007998 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007999 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008000 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8001 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8003 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8004 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008005 }
8006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008007 final long identity = Binder.clearCallingIdentity();
8008 try {
8009 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8010 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008011 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 }
8013 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8014 } finally {
8015 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008016 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008017 }
8018
8019 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008020 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8021 *
8022 * @throws SecurityException if the caller does not have the required permission
8023 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008024 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008025 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008026 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008027 }
8028
8029 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008030 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8031 * permission.
8032 *
8033 * @throws SecurityException if the caller does not have the required permission
8034 */
8035 private void enforceSendSmsPermission() {
8036 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8037 }
8038
8039 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008040 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008041 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008042 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008043 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008044 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045 final long identity = Binder.clearCallingIdentity();
8046 try {
8047 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008048 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 if (componentName == null) {
8050 throw new SecurityException(
8051 "Caller not current active visual voicemail package[null]");
8052 }
8053 String vvmPackage = componentName.getPackageName();
8054 if (!callingPackage.equals(vvmPackage)) {
8055 throw new SecurityException("Caller not current active visual voicemail package["
8056 + vvmPackage + "]");
8057 }
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008060 }
8061 }
8062
8063 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008064 * Return the application ID for the app type.
8065 *
8066 * @param subId the subscription ID that this request applies to.
8067 * @param appType the uicc app type.
8068 * @return Application ID for specificied app type, or null if no uicc.
8069 */
8070 @Override
8071 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008072 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008073 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074
8075 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008076 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008077 if (phone == null) {
8078 return null;
8079 }
8080 String aid = null;
8081 try {
8082 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8083 .getApplicationByType(appType).getAid();
8084 } catch (Exception e) {
8085 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8086 }
8087 return aid;
8088 } finally {
8089 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008090 }
Youhan Wange64578a2016-05-02 15:32:42 -07008091 }
8092
Youhan Wang4001d252016-05-11 10:29:41 -07008093 /**
8094 * Return the Electronic Serial Number.
8095 *
8096 * @param subId the subscription ID that this request applies to.
8097 * @return ESN or null if error.
8098 */
8099 @Override
8100 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008101 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008102 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008103
8104 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008105 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008106 if (phone == null) {
8107 return null;
8108 }
8109 String esn = null;
8110 try {
8111 esn = phone.getEsn();
8112 } catch (Exception e) {
8113 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8114 }
8115 return esn;
8116 } finally {
8117 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008118 }
Youhan Wang4001d252016-05-11 10:29:41 -07008119 }
8120
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008121 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008122 * Return the Preferred Roaming List Version.
8123 *
8124 * @param subId the subscription ID that this request applies to.
8125 * @return PRLVersion or null if error.
8126 */
8127 @Override
8128 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008129 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008130 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131
8132 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008133 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008134 if (phone == null) {
8135 return null;
8136 }
8137 String cdmaPrlVersion = null;
8138 try {
8139 cdmaPrlVersion = phone.getCdmaPrlVersion();
8140 } catch (Exception e) {
8141 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8142 }
8143 return cdmaPrlVersion;
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008146 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008147 }
8148
8149 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008150 * Get snapshot of Telephony histograms
8151 * @return List of Telephony histograms
8152 * @hide
8153 */
8154 @Override
8155 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8157 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158
8159 final long identity = Binder.clearCallingIdentity();
8160 try {
8161 return RIL.getTelephonyRILTimingHistograms();
8162 } finally {
8163 Binder.restoreCallingIdentity(identity);
8164 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008165 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008166
8167 /**
8168 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008169 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8170 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008171 * Require system privileges. In the future we may add this to carrier APIs.
8172 *
Michele Berionne482f8202018-11-27 18:57:59 -08008173 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008174 */
8175 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008176 @TelephonyManager.SetCarrierRestrictionResult
8177 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008178 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008179 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008180
Michele Berionne482f8202018-11-27 18:57:59 -08008181 if (carrierRestrictionRules == null) {
8182 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008183 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008185 final long identity = Binder.clearCallingIdentity();
8186 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008187 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008188 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 } finally {
8190 Binder.restoreCallingIdentity(identity);
8191 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008192 }
8193
8194 /**
8195 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008196 * Get the allowed carrier list and the excluded carrier list, including the priority between
8197 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008198 * Require system privileges. In the future we may add this to carrier APIs.
8199 *
Michele Berionne482f8202018-11-27 18:57:59 -08008200 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008201 */
8202 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008203 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008204 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008205 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008206
8207 final long identity = Binder.clearCallingIdentity();
8208 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008209 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8210 if (response instanceof CarrierRestrictionRules) {
8211 return (CarrierRestrictionRules) response;
8212 }
8213 // Response is an Exception of some kind,
8214 // which is signalled to the user as a NULL retval
8215 return null;
8216 } catch (Exception e) {
8217 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8218 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 } finally {
8220 Binder.restoreCallingIdentity(identity);
8221 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008222 }
8223
fionaxu59545b42016-05-25 15:53:37 -07008224 /**
fionaxu59545b42016-05-25 15:53:37 -07008225 * Action set from carrier signalling broadcast receivers to enable/disable radio
8226 * @param subId the subscription ID that this action applies to.
8227 * @param enabled control enable or disable radio.
8228 * {@hide}
8229 */
8230 @Override
8231 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8232 enforceModifyPermission();
8233 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234
8235 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008236 if (phone == null) {
8237 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8238 return;
8239 }
8240 try {
8241 phone.carrierActionSetRadioEnabled(enabled);
8242 } catch (Exception e) {
8243 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 } finally {
8245 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008246 }
8247 }
8248
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008249 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008250 * Enable or disable Voice over NR (VoNR)
8251 * @param subId the subscription ID that this action applies to.
8252 * @param enabled enable or disable VoNR.
8253 * @return operation result.
8254 */
8255 @Override
8256 public int setVoNrEnabled(int subId, boolean enabled) {
8257 enforceModifyPermission();
8258 final Phone phone = getPhone(subId);
8259
8260 final long identity = Binder.clearCallingIdentity();
8261 if (phone == null) {
8262 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8263 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8264 }
8265
8266 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8267 try {
8268 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8269 workSource);
8270 if (DBG) log("setVoNrEnabled result: " + result);
8271 return result;
8272 } finally {
8273 Binder.restoreCallingIdentity(identity);
8274 }
8275 }
8276
8277 /**
8278 * Is voice over NR enabled
8279 * @return true if VoNR is enabled else false
8280 */
8281 @Override
8282 public boolean isVoNrEnabled(int subId) {
8283 enforceReadPrivilegedPermission("isVoNrEnabled");
8284 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8285 final long identity = Binder.clearCallingIdentity();
8286 try {
8287 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8288 null, subId, workSource);
8289 if (DBG) log("isVoNrEnabled: " + isEnabled);
8290 return isEnabled;
8291 } finally {
8292 Binder.restoreCallingIdentity(identity);
8293 }
8294 }
8295
8296 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008297 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8298 * network status based on which carrier apps could apply actions accordingly,
8299 * enable/disable default url handler for example.
8300 *
8301 * @param subId the subscription ID that this action applies to.
8302 * @param report control start/stop reporting the default network status.
8303 * {@hide}
8304 */
8305 @Override
8306 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8307 enforceModifyPermission();
8308 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309
8310 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008311 if (phone == null) {
8312 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8313 return;
8314 }
8315 try {
8316 phone.carrierActionReportDefaultNetworkStatus(report);
8317 } catch (Exception e) {
8318 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319 } finally {
8320 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008321 }
8322 }
8323
8324 /**
fionaxud9622282017-07-17 17:51:30 -07008325 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8326 * @param subId the subscription ID that this action applies to.
8327 * {@hide}
8328 */
8329 @Override
8330 public void carrierActionResetAll(int subId) {
8331 enforceModifyPermission();
8332 final Phone phone = getPhone(subId);
8333 if (phone == null) {
8334 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8335 return;
8336 }
8337 try {
8338 phone.carrierActionResetAll();
8339 } catch (Exception e) {
8340 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8341 }
8342 }
8343
8344 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008345 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8346 * bug report is being generated.
8347 */
8348 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008349 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008350 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8351 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008352 writer.println("Permission Denial: can't dump Phone from pid="
8353 + Binder.getCallingPid()
8354 + ", uid=" + Binder.getCallingUid()
8355 + "without permission "
8356 + android.Manifest.permission.DUMP);
8357 return;
8358 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008359 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008360 }
Jack Yueb89b242016-06-22 13:27:47 -07008361
Brad Ebingerdac2f002018-04-03 15:17:52 -07008362 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008363 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8364 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8365 @NonNull String[] args) {
8366 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8367 this, in.getFileDescriptor(), out.getFileDescriptor(),
8368 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008369 }
8370
Jack Yueb89b242016-06-22 13:27:47 -07008371 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008372 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008373 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008374 * @param reason the reason the data enable change is taking place
8375 * @param enabled True if enabling the data, otherwise disabling.
8376 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008377 */
8378 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008379 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008380 boolean enabled) {
8381 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8382 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8383 try {
8384 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008385 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008386 } catch (SecurityException se) {
8387 enforceModifyPermission();
8388 }
8389 } else {
8390 enforceModifyPermission();
8391 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392
8393 final long identity = Binder.clearCallingIdentity();
8394 try {
8395 Phone phone = getPhone(subId);
8396 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008397 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8398 phone.carrierActionSetMeteredApnsEnabled(enabled);
8399 } else {
8400 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008402 }
8403 } finally {
8404 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008405 }
8406 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008407
8408 /**
8409 * Get Client request stats
8410 * @return List of Client Request Stats
8411 * @hide
8412 */
8413 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008414 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8415 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008417 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008418 return null;
8419 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008420 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008422 final long identity = Binder.clearCallingIdentity();
8423 try {
8424 if (phone != null) {
8425 return phone.getClientRequestStats();
8426 }
8427
8428 return null;
8429 } finally {
8430 Binder.restoreCallingIdentity(identity);
8431 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008432 }
8433
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008434 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008435 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008436 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008437 }
Jack Yueb4124c2017-02-16 15:32:43 -08008438
8439 /**
Grace Chen70990072017-03-24 17:21:30 -07008440 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008441 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008442 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008443 * @param state State of SIM (power down, power up, pass through)
8444 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8445 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8446 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008447 *
8448 **/
8449 @Override
Grace Chen70990072017-03-24 17:21:30 -07008450 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008451 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008452 Phone phone = PhoneFactory.getPhone(slotIndex);
8453
vagdeviaf9a5b92018-08-15 16:01:53 -07008454 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456 final long identity = Binder.clearCallingIdentity();
8457 try {
8458 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008459 phone.setSimPowerState(state, null, workSource);
8460 }
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
8464 }
8465
8466 /**
8467 * Set SIM card power state.
8468 *
8469 * @param slotIndex SIM slot id.
8470 * @param state State of SIM (power down, power up, pass through)
8471 * @param callback callback to trigger after success or failure
8472 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8473 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8474 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8475 *
8476 **/
8477 @Override
8478 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8479 IIntegerConsumer callback) {
8480 enforceModifyPermission();
8481 Phone phone = PhoneFactory.getPhone(slotIndex);
8482
8483 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8484
8485 final long identity = Binder.clearCallingIdentity();
8486 try {
8487 if (phone != null) {
8488 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8489 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490 }
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008493 }
8494 }
Shuo Qiandd210312017-04-12 22:11:33 +00008495
Tyler Gunn65d45c22017-06-05 11:22:26 -07008496 private boolean isUssdApiAllowed(int subId) {
8497 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008498 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008499 if (configManager == null) {
8500 return false;
8501 }
8502 PersistableBundle pb = configManager.getConfigForSubId(subId);
8503 if (pb == null) {
8504 return false;
8505 }
8506 return pb.getBoolean(
8507 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8508 }
8509
Shuo Qiandd210312017-04-12 22:11:33 +00008510 /**
8511 * Check if phone is in emergency callback mode
8512 * @return true if phone is in emergency callback mode
8513 * @param subId sub id
8514 */
goneil9c5f4872017-12-05 14:07:56 -08008515 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008516 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008517 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008518 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008519
8520 final long identity = Binder.clearCallingIdentity();
8521 try {
8522 if (phone != null) {
8523 return phone.isInEcm();
8524 } else {
8525 return false;
8526 }
8527 } finally {
8528 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008529 }
8530 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008531
8532 /**
8533 * Get the current signal strength information for the given subscription.
8534 * Because this information is not updated when the device is in a low power state
8535 * it should not be relied-upon to be current.
8536 * @param subId Subscription index
8537 * @return the most recent cached signal strength info from the modem
8538 */
8539 @Override
8540 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 Phone p = getPhone(subId);
8544 if (p == null) {
8545 return null;
8546 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008548 return p.getSignalStrength();
8549 } finally {
8550 Binder.restoreCallingIdentity(identity);
8551 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008552 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008553
Pengquan Meng77b7f132018-08-22 14:49:57 -07008554 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008555 * Get the current modem radio state for the given slot.
8556 * @param slotIndex slot index.
8557 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008558 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008559 * @return the current radio power state from the modem
8560 */
8561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008562 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008563 Phone phone = PhoneFactory.getPhone(slotIndex);
8564 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8566 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008567 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8568 }
8569
8570 final long identity = Binder.clearCallingIdentity();
8571 try {
8572 return phone.getRadioPowerState();
8573 } finally {
8574 Binder.restoreCallingIdentity(identity);
8575 }
8576 }
8577 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8578 }
8579
8580 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008581 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8582 *
8583 * <p>Requires one of the following permissions:
8584 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8585 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8586 * privileges.
8587 *
8588 * @param subId subscription id
8589 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8590 * {@code false}.
8591 */
8592 @Override
8593 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008594 try {
8595 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8596 null);
8597 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008598 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008599 mApp, subId, "isDataRoamingEnabled");
8600 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008601
Pengquan Menga1bb6272018-09-06 09:59:22 -07008602 boolean isEnabled = false;
8603 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008604 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008605 Phone phone = getPhone(subId);
8606 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008607 } finally {
8608 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008609 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008610 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008611 }
8612
8613
8614 /**
8615 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8616 *
8617 * <p> Requires permission:
8618 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8619 * privileges.
8620 *
8621 * @param subId subscription id
8622 * @param isEnabled {@code true} means enable, {@code false} means disable.
8623 */
8624 @Override
8625 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8627 mApp, subId, "setDataRoamingEnabled");
8628
Pengquan Menga1bb6272018-09-06 09:59:22 -07008629 final long identity = Binder.clearCallingIdentity();
8630 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008631 Phone phone = getPhone(subId);
8632 if (phone != null) {
8633 phone.setDataRoamingEnabled(isEnabled);
8634 }
8635 } finally {
8636 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008637 }
8638 }
8639
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008640 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008641 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008642 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008643 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008644 mApp, subId, "isManualNetworkSelectionAllowed");
8645
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008646 boolean isAllowed = true;
8647 final long identity = Binder.clearCallingIdentity();
8648 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008649 Phone phone = getPhone(subId);
8650 if (phone != null) {
8651 isAllowed = phone.isCspPlmnEnabled();
8652 }
8653 } finally {
8654 Binder.restoreCallingIdentity(identity);
8655 }
8656 return isAllowed;
8657 }
8658
8659 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008660 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008661 // Verify that tha callingPackage belongs to the calling UID
8662 mApp.getSystemService(AppOpsManager.class)
8663 .checkPackage(Binder.getCallingUid(), callingPackage);
8664
Jordan Liu1e142fc2019-04-22 15:10:43 -07008665 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008666 try {
8667 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008668 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008669 } catch (SecurityException e) {
8670 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8671 // has carrier privileges on an active UICC
8672 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8673 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008674 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008675 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008676 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008677
8678 final long identity = Binder.clearCallingIdentity();
8679 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008680 UiccController uiccController = UiccController.getInstance();
8681 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008682 if (hasReadPermission) {
8683 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008684 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008685
8686 // Remove private info if the caller doesn't have access
8687 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8688 for (UiccCardInfo cardInfo : cardInfos) {
8689 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8690 // is available
8691 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8692 if (card == null || card.getUiccProfile() == null) {
8693 // assume no access if the card or profile is unavailable
8694 filteredInfos.add(cardInfo.getUnprivileged());
8695 continue;
8696 }
8697 UiccProfile profile = card.getUiccProfile();
8698 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8699 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8700 filteredInfos.add(cardInfo);
8701 } else {
8702 filteredInfos.add(cardInfo.getUnprivileged());
8703 }
8704 }
8705 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008706 } finally {
8707 Binder.restoreCallingIdentity(identity);
8708 }
8709 }
8710
8711 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008712 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008713 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008715 final long identity = Binder.clearCallingIdentity();
8716 try {
8717 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8718 if (slots == null) {
8719 Rlog.i(LOG_TAG, "slots is null.");
8720 return null;
8721 }
8722
8723 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8724 for (int i = 0; i < slots.length; i++) {
8725 UiccSlot slot = slots[i];
8726 if (slot == null) {
8727 continue;
8728 }
8729
Jordan Liu7be7e652019-05-06 18:55:02 +00008730 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008731 UiccCard card = slot.getUiccCard();
8732 if (card != null) {
8733 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008734 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008735 cardId = slot.getEid();
8736 if (TextUtils.isEmpty(cardId)) {
8737 cardId = slot.getIccId();
8738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008739 }
8740
Jordan Liu857451f2019-05-09 16:35:35 -07008741 if (cardId != null) {
8742 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8743 // if cardId is an EID, it's all digits so this is fine
8744 cardId = IccUtils.stripTrailingFs(cardId);
8745 }
8746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008747 int cardState = 0;
8748 switch (slot.getCardState()) {
8749 case CARDSTATE_ABSENT:
8750 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8751 break;
8752 case CARDSTATE_PRESENT:
8753 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8754 break;
8755 case CARDSTATE_ERROR:
8756 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8757 break;
8758 case CARDSTATE_RESTRICTED:
8759 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8760 break;
8761 default:
8762 break;
8763
8764 }
8765
8766 infos[i] = new UiccSlotInfo(
8767 slot.isActive(),
8768 slot.isEuicc(),
8769 cardId,
8770 cardState,
8771 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008772 slot.isExtendedApduSupported(),
8773 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008774 }
8775 return infos;
8776 } finally {
8777 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008778 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008779 }
8780
8781 @Override
8782 public boolean switchSlots(int[] physicalSlots) {
8783 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008784
8785 final long identity = Binder.clearCallingIdentity();
8786 try {
8787 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8788 } finally {
8789 Binder.restoreCallingIdentity(identity);
8790 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008791 }
Jack Yu4c988042018-02-27 15:30:01 -08008792
8793 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008794 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008795 final long identity = Binder.clearCallingIdentity();
8796 try {
8797 return UiccController.getInstance().getCardIdForDefaultEuicc();
8798 } finally {
8799 Binder.restoreCallingIdentity(identity);
8800 }
8801 }
8802
Pengquan Meng85728fb2018-03-12 16:31:21 -07008803 /**
goneil47ffb6e2018-04-06 15:40:58 -07008804 * A test API to reload the UICC profile.
8805 *
8806 * <p>Requires that the calling app has permission
8807 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8808 * @hide
8809 */
8810 @Override
8811 public void refreshUiccProfile(int subId) {
8812 enforceModifyPermission();
8813
8814 final long identity = Binder.clearCallingIdentity();
8815 try {
8816 Phone phone = getPhone(subId);
8817 if (phone == null) {
8818 return;
8819 }
8820 UiccCard uiccCard = phone.getUiccCard();
8821 if (uiccCard == null) {
8822 return;
8823 }
8824 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8825 if (uiccProfile == null) {
8826 return;
8827 }
8828 uiccProfile.refresh();
8829 } finally {
8830 Binder.restoreCallingIdentity(identity);
8831 }
8832 }
8833
8834 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008835 * Returns false if the mobile data is disabled by default, otherwise return true.
8836 */
8837 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008838 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008839 }
8840
8841 /**
8842 * Returns true if the data roaming is enabled by default, i.e the system property
8843 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8844 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8845 */
8846 private boolean getDefaultDataRoamingEnabled(int subId) {
8847 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008848 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008849 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008850 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8851 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8852 return isDataRoamingEnabled;
8853 }
8854
8855 /**
8856 * Returns the default network type for the given {@code subId}, if the default network type is
8857 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8858 */
8859 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008860 List<Integer> list = TelephonyProperties.default_network();
8861 int phoneId = mSubscriptionController.getPhoneId(subId);
8862 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8863 return list.get(phoneId);
8864 }
8865 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008866 }
fionaxua13278b2018-03-21 00:08:13 -07008867
8868 @Override
8869 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008870 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008871 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008872
8873 final long identity = Binder.clearCallingIdentity();
8874 try {
8875 final Phone phone = getPhone(subId);
8876 if (phone == null) {
8877 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8878 return;
8879 }
chen xueaba88a2019-03-15 13:15:10 -07008880 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8881 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008882 if (carrierPrivilegeRules == null) {
8883 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8884 } else {
8885 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8886 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008887 } finally {
8888 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008889 }
fionaxua13278b2018-03-21 00:08:13 -07008890 }
8891
8892 @Override
8893 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008894 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008895
8896 final long identity = Binder.clearCallingIdentity();
8897 try {
8898 final Phone phone = getPhone(subId);
8899 if (phone == null) {
8900 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8901 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8902 }
8903 return phone.getCarrierIdListVersion();
8904 } finally {
8905 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008906 }
fionaxua13278b2018-03-21 00:08:13 -07008907 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008908
8909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008910 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8911 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008913 mApp, subId, callingPackage, callingFeatureId,
8914 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008915 return -1;
8916 }
8917
8918 final long identity = Binder.clearCallingIdentity();
8919 try {
8920 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8921 } finally {
8922 Binder.restoreCallingIdentity(identity);
8923 }
8924 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008925
8926 @Override
8927 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008928 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008929 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008930 mApp, subId, "getCdmaRoamingMode");
8931
8932 final long identity = Binder.clearCallingIdentity();
8933 try {
8934 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8935 } finally {
8936 Binder.restoreCallingIdentity(identity);
8937 }
8938 }
8939
8940 @Override
8941 public boolean setCdmaRoamingMode(int subId, int mode) {
8942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8943 mApp, subId, "setCdmaRoamingMode");
8944
8945 final long identity = Binder.clearCallingIdentity();
8946 try {
8947 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8948 } finally {
8949 Binder.restoreCallingIdentity(identity);
8950 }
8951 }
8952
8953 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008954 public int getCdmaSubscriptionMode(int subId) {
8955 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008956 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008957 mApp, subId, "getCdmaSubscriptionMode");
8958
8959 final long identity = Binder.clearCallingIdentity();
8960 try {
8961 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8962 } finally {
8963 Binder.restoreCallingIdentity(identity);
8964 }
8965 }
8966
8967 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008968 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8970 mApp, subId, "setCdmaSubscriptionMode");
8971
8972 final long identity = Binder.clearCallingIdentity();
8973 try {
8974 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8975 } finally {
8976 Binder.restoreCallingIdentity(identity);
8977 }
8978 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008979
sqianc5eccab2018-10-19 18:46:41 -07008980 @Override
sqian8c685422019-02-22 15:55:18 -08008981 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008982 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008984 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8985 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008986 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8987 }
8988 final long identity = Binder.clearCallingIdentity();
8989 try {
sqian854d44b2018-12-12 16:48:18 -08008990 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8991 for (Phone phone: PhoneFactory.getPhones()) {
8992 if (phone.getEmergencyNumberTracker() != null
8993 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8994 emergencyNumberListInternal.put(
8995 phone.getSubId(),
8996 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8997 }
sqian11b7a0e2018-12-05 18:48:28 -08008998 }
sqian854d44b2018-12-12 16:48:18 -08008999 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009000 } finally {
9001 Binder.restoreCallingIdentity(identity);
9002 }
sqianc5eccab2018-10-19 18:46:41 -07009003 }
9004
9005 @Override
sqian8c685422019-02-22 15:55:18 -08009006 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009007 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009008 if (!exactMatch) {
9009 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009010 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009011 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009012 }
9013 final long identity = Binder.clearCallingIdentity();
9014 try {
sqian854d44b2018-12-12 16:48:18 -08009015 for (Phone phone: PhoneFactory.getPhones()) {
9016 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009017 && phone.getEmergencyNumberTracker()
9018 .isEmergencyNumber(number, exactMatch)) {
9019 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009020 }
sqian11b7a0e2018-12-05 18:48:28 -08009021 }
9022 return false;
9023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
9027
sqianf4ca7ed2019-01-15 18:32:07 -08009028 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009029 * Start emergency callback mode for GsmCdmaPhone for testing.
9030 */
9031 @Override
9032 public void startEmergencyCallbackMode() {
9033 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9034 "startEmergencyCallbackMode");
9035 enforceModifyPermission();
9036 final long identity = Binder.clearCallingIdentity();
9037 try {
9038 for (Phone phone : PhoneFactory.getPhones()) {
9039 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9040 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9041 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9042 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9043 gsmCdmaPhone.obtainMessage(
9044 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9045 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9046 }
9047 }
9048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
9051 }
9052
9053 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009054 * Update emergency number list for test mode.
9055 */
9056 @Override
9057 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9058 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9059 "updateEmergencyNumberListTestMode");
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.executeEmergencyNumberTestModeCommand(action, num);
9067 }
9068 }
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
9072 }
9073
9074 /**
9075 * Get the full emergency number list for test mode.
9076 */
9077 @Override
9078 public List<String> getEmergencyNumberListTestMode() {
9079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9080 "getEmergencyNumberListTestMode");
9081
9082 final long identity = Binder.clearCallingIdentity();
9083 try {
9084 Set<String> emergencyNumbers = new HashSet<>();
9085 for (Phone phone: PhoneFactory.getPhones()) {
9086 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9087 if (tracker != null) {
9088 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9089 emergencyNumbers.add(num.getNumber());
9090 }
9091 }
9092 }
9093 return new ArrayList<>(emergencyNumbers);
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
9096 }
9097 }
9098
chen xud6b45bd2018-10-30 22:27:10 -07009099 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009100 public int getEmergencyNumberDbVersion(int subId) {
9101 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9102
9103 final long identity = Binder.clearCallingIdentity();
9104 try {
9105 final Phone phone = getPhone(subId);
9106 if (phone == null) {
9107 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9108 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9109 }
9110 return phone.getEmergencyNumberDbVersion();
9111 } finally {
9112 Binder.restoreCallingIdentity(identity);
9113 }
9114 }
9115
9116 @Override
9117 public void notifyOtaEmergencyNumberDbInstalled() {
9118 enforceModifyPermission();
9119
9120 final long identity = Binder.clearCallingIdentity();
9121 try {
9122 for (Phone phone: PhoneFactory.getPhones()) {
9123 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9124 if (tracker != null) {
9125 tracker.updateOtaEmergencyNumberDatabase();
9126 }
9127 }
9128 } finally {
9129 Binder.restoreCallingIdentity(identity);
9130 }
9131 }
9132
9133 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009134 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009135 enforceActiveEmergencySessionPermission();
9136
9137 final long identity = Binder.clearCallingIdentity();
9138 try {
9139 for (Phone phone: PhoneFactory.getPhones()) {
9140 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9141 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009142 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9143 }
9144 }
9145 } finally {
9146 Binder.restoreCallingIdentity(identity);
9147 }
9148 }
9149
9150 @Override
9151 public void resetOtaEmergencyNumberDbFilePath() {
9152 enforceActiveEmergencySessionPermission();
9153
9154 final long identity = Binder.clearCallingIdentity();
9155 try {
9156 for (Phone phone: PhoneFactory.getPhones()) {
9157 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9158 if (tracker != null) {
9159 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009160 }
9161 }
9162 } finally {
9163 Binder.restoreCallingIdentity(identity);
9164 }
9165 }
9166
9167 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009168 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9169 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9170 Phone phone = getPhone(subId);
9171 if (phone == null) {
9172 return null;
9173 }
9174 final long identity = Binder.clearCallingIdentity();
9175 try {
9176 UiccProfile profile = UiccController.getInstance()
9177 .getUiccProfileForPhone(phone.getPhoneId());
9178 if (profile != null) {
9179 return profile.getCertsFromCarrierPrivilegeAccessRules();
9180 }
9181 } finally {
9182 Binder.restoreCallingIdentity(identity);
9183 }
9184 return null;
9185 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009186
9187 /**
9188 * Enable or disable a modem stack.
9189 */
9190 @Override
9191 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9192 enforceModifyPermission();
9193
9194 final long identity = Binder.clearCallingIdentity();
9195 try {
9196 Phone phone = PhoneFactory.getPhone(slotIndex);
9197 if (phone == null) {
9198 return false;
9199 } else {
9200 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9201 }
9202 } finally {
9203 Binder.restoreCallingIdentity(identity);
9204 }
9205 }
Michelecea4cf22018-12-21 15:00:11 -08009206
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009207 /**
9208 * Whether a modem stack is enabled or not.
9209 */
9210 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009211 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9212 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009213 Phone phone = PhoneFactory.getPhone(slotIndex);
9214 if (phone == null) return false;
9215
9216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009217 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9218 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009219 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9220 }
9221
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009224 try {
9225 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9226 } catch (NoSuchElementException ex) {
9227 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9228 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009229 } finally {
9230 Binder.restoreCallingIdentity(identity);
9231 }
9232 }
9233
Michelecea4cf22018-12-21 15:00:11 -08009234 @Override
Michele0ea7d782019-03-19 14:58:42 -07009235 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009236 enforceModifyPermission();
9237
9238 final long identity = Binder.clearCallingIdentity();
9239 try {
9240 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009241 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009242 .commit();
9243 } finally {
9244 Binder.restoreCallingIdentity(identity);
9245 }
9246 }
9247
9248 @Override
Michele0ea7d782019-03-19 14:58:42 -07009249 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009250 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009252 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9253 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009254 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009255 }
Michelecea4cf22018-12-21 15:00:11 -08009256
9257 final long identity = Binder.clearCallingIdentity();
9258 try {
Michele0ea7d782019-03-19 14:58:42 -07009259 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009260 } finally {
9261 Binder.restoreCallingIdentity(identity);
9262 }
9263 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009264
Michele0ea7d782019-03-19 14:58:42 -07009265 @TelephonyManager.IsMultiSimSupportedResult
9266 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009267 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9268 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9269 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009270 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9271 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009272 }
9273 // Check if the hardware supports multisim functionality. If usage of multisim is not
9274 // supported by the modem, indicate that it is restricted.
9275 PhoneCapability staticCapability =
9276 mPhoneConfigurationManager.getStaticPhoneCapability();
9277 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009278 loge("isMultiSimSupportedInternal: no static configuration available");
9279 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009280 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009281 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009282 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9283 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009284 }
9285 // Check if support of multiple SIMs is restricted by carrier
9286 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009287 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009288 }
9289
Michele0ea7d782019-03-19 14:58:42 -07009290 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009291 }
9292
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009293 /**
9294 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009295 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9296 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9297 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009298 * @param numOfSims number of active sims we want to switch to
9299 */
9300 @Override
9301 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009302 if (numOfSims == 1) {
9303 enforceModifyPermission();
9304 } else {
9305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9306 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9307 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009308 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009309
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009310 try {
Michele30b57b22019-03-01 12:01:14 -08009311 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009312 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009313 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9314 return;
9315 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009316 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9317 } finally {
9318 Binder.restoreCallingIdentity(identity);
9319 }
9320 }
9321
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009322 @Override
9323 public boolean isApplicationOnUicc(int subId, int appType) {
9324 enforceReadPrivilegedPermission("isApplicationOnUicc");
9325 Phone phone = getPhone(subId);
9326 if (phone == null) {
9327 return false;
9328 }
9329 final long identity = Binder.clearCallingIdentity();
9330 try {
9331 UiccCard uiccCard = phone.getUiccCard();
9332 if (uiccCard == null) {
9333 return false;
9334 }
9335 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9336 if (uiccProfile == null) {
9337 return false;
9338 }
9339 if (TelephonyManager.APPTYPE_SIM <= appType
9340 && appType <= TelephonyManager.APPTYPE_ISIM) {
9341 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9342 }
9343 return false;
9344 } finally {
9345 Binder.restoreCallingIdentity(identity);
9346 }
9347 }
9348
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009349 /**
chen xub4baa772019-04-03 10:23:41 -07009350 * Get whether making changes to modem configurations will trigger reboot.
9351 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009352 */
9353 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009354 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9355 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009357 mApp, subId, callingPackage, callingFeatureId,
9358 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009359 return false;
9360 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009361 final long identity = Binder.clearCallingIdentity();
9362 try {
9363 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9364 } finally {
9365 Binder.restoreCallingIdentity(identity);
9366 }
9367 }
9368
Nathan Harold29f5f052019-02-15 13:41:57 -08009369 private void updateModemStateMetrics() {
9370 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9371 // TODO: check the state for each modem if the api is ready.
9372 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9373 }
9374
Pengquan Meng3889a572019-01-23 11:16:29 -08009375 @Override
9376 public int[] getSlotsMapping() {
9377 enforceReadPrivilegedPermission("getSlotsMapping");
9378
9379 final long identity = Binder.clearCallingIdentity();
9380 try {
9381 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9382 // All logical slots should have a mapping to a physical slot.
9383 int[] logicalSlotsMapping = new int[phoneCount];
9384 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9385 for (int i = 0; i < slotInfos.length; i++) {
9386 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9387 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9388 }
9389 }
9390 return logicalSlotsMapping;
9391 } finally {
9392 Binder.restoreCallingIdentity(identity);
9393 }
9394 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009395
9396 /**
9397 * Get the IRadio HAL Version
9398 */
9399 @Override
9400 public int getRadioHalVersion() {
9401 Phone phone = getDefaultPhone();
9402 if (phone == null) return -1;
9403 HalVersion hv = phone.getHalVersion();
9404 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9405 return hv.major * 100 + hv.minor;
9406 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009407
9408 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009409 * Get the current calling package name.
9410 * @return the current calling package name
9411 */
9412 @Override
9413 public String getCurrentPackageName() {
9414 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9415 }
9416
9417 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009418 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9419 * corresponding network requests on a subId.
9420 *
9421 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009422 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009423 * 2) APN is un-metered for this subscription, or
9424 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009425 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009426 *
9427 * @return whether data is allowed for a apn type.
9428 *
9429 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009430 */
9431 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009432 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009433 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9434 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009435
9436 // Now that all security checks passes, perform the operation as ourselves.
9437 final long identity = Binder.clearCallingIdentity();
9438 try {
9439 Phone phone = getPhone(subId);
9440 if (phone == null) return false;
9441
Jack Yu41407ee2019-05-13 16:54:09 -07009442 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009443 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9444 } finally {
9445 Binder.restoreCallingIdentity(identity);
9446 }
9447 }
9448
9449 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009450 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009451 enforceReadPrivilegedPermission("isApnMetered");
9452
9453 // Now that all security checks passes, perform the operation as ourselves.
9454 final long identity = Binder.clearCallingIdentity();
9455 try {
9456 Phone phone = getPhone(subId);
9457 if (phone == null) return true; // By default return true.
9458
Jack Yu41407ee2019-05-13 16:54:09 -07009459 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009460 } finally {
9461 Binder.restoreCallingIdentity(identity);
9462 }
9463 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009464
9465 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009466 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9467 int subscriptionId, IBooleanConsumer resultCallback) {
9468 enforceModifyPermission();
9469 long token = Binder.clearCallingIdentity();
9470 try {
9471 Phone phone = getPhone(subscriptionId);
9472 if (phone == null) {
9473 try {
9474 if (resultCallback != null) {
9475 resultCallback.accept(false);
9476 }
9477 } catch (RemoteException e) {
9478 // ignore
9479 }
9480 return;
9481 }
9482 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9483 Pair.create(specifiers, (x) -> {
9484 try {
9485 if (resultCallback != null) {
9486 resultCallback.accept(x);
9487 }
9488 } catch (RemoteException e) {
9489 // ignore
9490 }
9491 });
9492 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9493 } finally {
9494 Binder.restoreCallingIdentity(token);
9495 }
9496 }
9497
9498 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009499 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9500 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009501 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009502 mApp, subId, "getSystemSelectionChannels");
9503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9504 final long identity = Binder.clearCallingIdentity();
9505 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009506 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9507 if (result instanceof IllegalStateException) {
9508 throw (IllegalStateException) result;
9509 }
9510 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009511 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9512 return specifiers;
9513 } finally {
9514 Binder.restoreCallingIdentity(identity);
9515 }
9516 }
9517
9518 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009519 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009520 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009521 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9522 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9523 if (iccRecords == null) {
9524 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9525 return false;
9526 }
9527 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9528 }
9529
9530 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009531 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9532 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009533 if (callingPackage == null) {
9534 callingPackage = getCurrentPackageName();
9535 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009536 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9537 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009538 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9539 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009540 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9541 }
9542 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9543 Intent intent = new Intent();
9544 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9545 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9546 // Bring up choose default SMS subscription dialog right now
9547 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9548 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9549 mApp.startActivity(intent);
9550 }
chen xud5ca2d52019-05-28 15:20:57 -07009551
9552 @Override
9553 public String getMmsUAProfUrl(int subId) {
9554 //TODO investigate if this API should require proper permission check in R b/133791609
9555 final long identity = Binder.clearCallingIdentity();
9556 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009557 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9558 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9559 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9560 return carrierUAProfUrl;
9561 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009562 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9563 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
9568
9569 @Override
9570 public String getMmsUserAgent(int subId) {
9571 //TODO investigate if this API should require proper permission check in R b/133791609
9572 final long identity = Binder.clearCallingIdentity();
9573 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009574 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9575 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9576 if (!TextUtils.isEmpty(carrierUserAgent)) {
9577 return carrierUserAgent;
9578 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009579 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9580 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009581 } finally {
9582 Binder.restoreCallingIdentity(identity);
9583 }
9584 }
Jack Yub07d4972019-05-28 16:12:25 -07009585
9586 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009587 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9588 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009589
Jack Yub07d4972019-05-28 16:12:25 -07009590 final long identity = Binder.clearCallingIdentity();
9591 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009592 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009593 if (phone == null) return false;
9594
Hall Liua62f5da2020-09-25 10:42:19 -07009595 switch (policy) {
9596 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9597 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9598 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9599 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9600 default:
9601 throw new IllegalArgumentException(policy + " is not a valid policy");
9602 }
Jack Yub07d4972019-05-28 16:12:25 -07009603 } finally {
9604 Binder.restoreCallingIdentity(identity);
9605 }
9606 }
9607
9608 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009609 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009610 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009611 enforceModifyPermission();
9612
changbettyd5c246e2019-12-24 15:40:37 +08009613 final long identity = Binder.clearCallingIdentity();
9614 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009615 Phone phone = getPhone(subscriptionId);
9616 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009617
Hall Liua62f5da2020-09-25 10:42:19 -07009618 switch (policy) {
9619 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9620 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9621 break;
9622 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9623 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9624 break;
9625 default:
9626 throw new IllegalArgumentException(policy + " is not a valid policy");
9627 }
changbettyd5c246e2019-12-24 15:40:37 +08009628 } finally {
9629 Binder.restoreCallingIdentity(identity);
9630 }
9631 }
9632
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009633 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009634 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009635 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9636 * otherwise.
9637 */
9638 @Override
9639 public void setCepEnabled(boolean isCepEnabled) {
9640 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9641
9642 final long identity = Binder.clearCallingIdentity();
9643 try {
9644 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9645 for (Phone phone : PhoneFactory.getPhones()) {
9646 Phone defaultPhone = phone.getImsPhone();
9647 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9648 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9649 ImsPhoneCallTracker imsPhoneCallTracker =
9650 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9651 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9652 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9653 + imsPhone.getMsisdn());
9654 }
9655 }
9656 } finally {
9657 Binder.restoreCallingIdentity(identity);
9658 }
9659 }
allenwtsu46dcc572020-01-08 18:24:03 +08009660
9661 /**
9662 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9663 *
9664 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9665 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9666 * before being read.
9667 */
9668 @Override
9669 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9670 isCompressed) {
9671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9672 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009673 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9674 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9675 }
9676 if (!isImsAvailableOnDevice()) {
9677 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9678 "IMS not available on device.");
9679 }
9680
9681 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009682 try {
Hui Wang761a6682020-10-31 05:12:53 +00009683 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9684 } finally {
9685 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009686 }
9687 }
zoey chene02881a2019-12-30 16:11:23 +08009688
9689 @Override
9690 public boolean isIccLockEnabled(int subId) {
9691 enforceReadPrivilegedPermission("isIccLockEnabled");
9692
9693 // Now that all security checks passes, perform the operation as ourselves.
9694 final long identity = Binder.clearCallingIdentity();
9695 try {
9696 Phone phone = getPhone(subId);
9697 if (phone != null && phone.getIccCard() != null) {
9698 return phone.getIccCard().getIccLockEnabled();
9699 } else {
9700 return false;
9701 }
9702 } finally {
9703 Binder.restoreCallingIdentity(identity);
9704 }
9705 }
9706
9707 /**
9708 * Set the ICC pin lock enabled or disabled.
9709 *
9710 * @return an integer representing the status of IccLock enabled or disabled in the following
9711 * three cases:
9712 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9713 * successfully.
9714 * - Positive number and zero for remaining password attempts.
9715 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9716 *
9717 */
9718 @Override
9719 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9720 enforceModifyPermission();
9721
9722 Phone phone = getPhone(subId);
9723 if (phone == null) {
9724 return 0;
9725 }
9726 // Now that all security checks passes, perform the operation as ourselves.
9727 final long identity = Binder.clearCallingIdentity();
9728 try {
9729 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9730 new Pair<Boolean, String>(enabled, password), phone, null);
9731 return attemptsRemaining;
9732
9733 } catch (Exception e) {
9734 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9735 } finally {
9736 Binder.restoreCallingIdentity(identity);
9737 }
9738 return 0;
9739 }
9740
9741 /**
9742 * Change the ICC password used in ICC pin lock.
9743 *
9744 * @return an integer representing the status of IccLock changed in the following three cases:
9745 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9746 * - Positive number and zero for remaining password attempts.
9747 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9748 *
9749 */
9750 @Override
9751 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9752 enforceModifyPermission();
9753
9754 Phone phone = getPhone(subId);
9755 if (phone == null) {
9756 return 0;
9757 }
9758 // Now that all security checks passes, perform the operation as ourselves.
9759 final long identity = Binder.clearCallingIdentity();
9760 try {
9761 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9762 new Pair<String, String>(oldPassword, newPassword), phone, null);
9763 return attemptsRemaining;
9764
9765 } catch (Exception e) {
9766 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9767 } finally {
9768 Binder.restoreCallingIdentity(identity);
9769 }
9770 return 0;
9771 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009772
9773 /**
9774 * Request for receiving user activity notification
9775 */
9776 @Override
9777 public void requestUserActivityNotification() {
9778 if (!mNotifyUserActivity.get()
9779 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9780 mNotifyUserActivity.set(true);
9781 }
9782 }
9783
9784 /**
9785 * Called when userActivity is signalled in the power manager.
9786 * This is safe to call from any thread, with any window manager locks held or not.
9787 */
9788 @Override
9789 public void userActivity() {
9790 // ***************************************
9791 // * Inherited from PhoneWindowManager *
9792 // ***************************************
9793 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9794 // WITH ITS LOCKS HELD.
9795 //
9796 // This code must be VERY careful about the locks
9797 // it acquires.
9798 // In fact, the current code acquires way too many,
9799 // and probably has lurking deadlocks.
9800
9801 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9802 throw new SecurityException("Only the OS may call notifyUserActivity()");
9803 }
9804
9805 if (mNotifyUserActivity.getAndSet(false)) {
9806 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9807 USER_ACTIVITY_NOTIFICATION_DELAY);
9808 }
9809 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009810
9811 @Override
9812 public boolean canConnectTo5GInDsdsMode() {
9813 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9814 }
Jack Yud10cdd42020-09-28 20:28:01 -07009815
9816 @Override
9817 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9818 String callingFeatureId) {
9819 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9820 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9821 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9822 }
9823
9824 Phone phone = getPhone(subId);
9825 if (phone == null) {
9826 throw new RuntimeException("phone is not available");
9827 }
9828 // Now that all security checks passes, perform the operation as ourselves.
9829 final long identity = Binder.clearCallingIdentity();
9830 try {
9831 return phone.getEquivalentHomePlmns();
9832 } finally {
9833 Binder.restoreCallingIdentity(identity);
9834 }
9835 }
Daniel Bright59e67312020-11-13 11:49:37 -08009836
9837 @Override
9838 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009839 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9840 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009841 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009842 if (radioInterfaceCapabilities == null) {
9843 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009844 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009845 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009846 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009847
Hui Wang641e81c2020-10-12 12:14:23 -07009848 @Override
9849 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9850 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009851 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9852 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9853 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9854 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9855 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009856 if (DBG) {
9857 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9858 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9859 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9860 }
9861
9862 if (!SubscriptionManager.isValidSubscriptionId(subId)
9863 || appType < TelephonyManager.APPTYPE_UNKNOWN
9864 || appType > TelephonyManager.APPTYPE_ISIM
9865 || nafUrl == null || securityProtocol == null || callback == null) {
9866 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9867 if (callback != null) {
9868 try {
9869 callback.onAuthenticationFailure(
9870 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9871 } catch (RemoteException exception) {
9872 log("Fail to notify onAuthenticationFailure due to " + exception);
9873 }
9874 return;
9875 }
9876 }
9877
9878 final long token = Binder.clearCallingIdentity();
9879 try {
9880 getGbaManager(subId).bootstrapAuthenticationRequest(
9881 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9882 forceBootStrapping, callback));
9883 } finally {
9884 Binder.restoreCallingIdentity(token);
9885 }
9886 }
9887
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009888 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009889 * Attempts to set the radio power state for all phones for thermal reason.
9890 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009891 * requested radio power state will actually be set. See {@link
9892 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9893 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009894 * @param enable {@code true} if trying to turn radio on.
9895 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9896 * false}.
9897 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009898 private boolean setRadioPowerForThermal(boolean enable) {
9899 boolean isPhoneAvailable = false;
9900 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9901 Phone phone = PhoneFactory.getPhone(i);
9902 if (phone != null) {
9903 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9904 isPhoneAvailable = true;
9905 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009906 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009907
9908 // return true if successfully informed the phone object about the thermal radio power
9909 // request.
9910 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009911 }
9912
9913 private int handleDataThrottlingRequest(int subId,
9914 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009915 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9916 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9917 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9918 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9919 throw new IllegalArgumentException("modem does not support data throttling");
9920 }
9921
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009922 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9923 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009924 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009925 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9926 }
9927
9928 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9929
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009930 if (isDataThrottlingSupported) {
9931 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009932 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009933 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9934 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9935 } else if (thermalMitigationResult
9936 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009937 log("Modem likely does not support data throttling on secondary carrier. Data " +
9938 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9939 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009940 }
9941 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009942 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009943
9944 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009945 }
9946
Jack Nudelman644b91a2021-03-12 14:09:48 -08009947 private static List<String> getThermalMitigationAllowlist(Context context) {
9948 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9949 for (String pckg : context.getResources()
9950 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9951 sThermalMitigationAllowlistedPackages.add(pckg);
9952 }
9953 }
9954
9955 return sThermalMitigationAllowlistedPackages;
9956 }
9957
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009958 private boolean isAnyPhoneInEmergencyState() {
9959 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9960 if (tm.isInEmergencyCall()) {
9961 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9962 return true;
9963 }
9964 for (Phone phone : PhoneFactory.getPhones()) {
9965 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9966 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9967 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9968 + phone.isInEcm());
9969 return true;
9970 }
9971 }
9972
9973 return false;
9974 }
9975
Jack Nudelman644b91a2021-03-12 14:09:48 -08009976 /**
9977 * Used by shell commands to add an authorized package name for thermal mitigation.
9978 * @param packageName name of package to be allowlisted
9979 * @param context
9980 */
9981 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9982 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9983 sThermalMitigationAllowlistedPackages.add(packageName);
9984 }
9985
9986 /**
9987 * Used by shell commands to remove an authorized package name for thermal mitigation.
9988 * @param packageName name of package to remove from allowlist
9989 * @param context
9990 */
9991 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9992 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9993 sThermalMitigationAllowlistedPackages.remove(packageName);
9994 }
9995
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009996 /**
9997 * Thermal mitigation request to control functionalities at modem.
9998 *
9999 * @param subId the id of the subscription.
10000 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010001 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010002 *
10003 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10004 */
10005 @Override
10006 @ThermalMitigationResult
10007 public int sendThermalMitigationRequest(
10008 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010009 ThermalMitigationRequest thermalMitigationRequest,
10010 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010011 enforceModifyPermission();
10012
Jack Nudelman644b91a2021-03-12 14:09:48 -080010013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10014 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10015 .contains(callingPackage)) {
10016 throw new SecurityException("Calling package must be configured in the device config. "
10017 + "calling package: " + callingPackage);
10018 }
10019
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10021 final long identity = Binder.clearCallingIdentity();
10022
10023 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10024 try {
10025 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10026 switch (thermalMitigationAction) {
10027 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10028 thermalMitigationResult =
10029 handleDataThrottlingRequest(subId,
10030 thermalMitigationRequest.getDataThrottlingRequest());
10031 break;
10032 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10033 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10034 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10035 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10036 }
10037
10038 // Ensure that radio is on. If not able to power on due to phone being
10039 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010040 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010041 thermalMitigationResult =
10042 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10043 break;
10044 }
10045
10046 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10047 false);
10048 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10049 break;
10050 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10051 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10052 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10053 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10054 }
10055
10056 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10057 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010058 Phone phone = getPhone(subId);
10059 if (phone == null) {
10060 thermalMitigationResult =
10061 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10062 break;
10063 }
10064
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010065 TelephonyConnectionService service =
10066 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010067 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010068 Log.e(LOG_TAG, "An emergency call is pending");
10069 thermalMitigationResult =
10070 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10071 break;
10072 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010073 thermalMitigationResult =
10074 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10075 break;
10076 }
10077 } else {
10078 thermalMitigationResult =
10079 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10080 break;
10081 }
10082
10083 // Turn radio off. If not able to power off due to phone being unavailable,
10084 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010085 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010086 thermalMitigationResult =
10087 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10088 break;
10089 }
10090 thermalMitigationResult =
10091 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10092 break;
10093 default:
10094 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10095 + "not exist. Requested action: " + thermalMitigationAction);
10096 }
10097 } catch (IllegalArgumentException e) {
10098 throw e;
10099 } catch (Exception e) {
10100 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10101 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10102 } finally {
10103 Binder.restoreCallingIdentity(identity);
10104 }
10105
10106 if (DBG) {
10107 log("thermalMitigationRequest returning with thermalMitigationResult: "
10108 + thermalMitigationResult);
10109 }
10110
10111 return thermalMitigationResult;
10112 }
Hui Wang641e81c2020-10-12 12:14:23 -070010113
10114 /**
10115 * Set the GbaService Package Name that Telephony will bind to.
10116 *
10117 * @param subId The sim that the GbaService is associated with.
10118 * @param packageName The name of the package to be replaced with.
10119 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10120 */
10121 @Override
10122 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10123 enforceModifyPermission();
10124
10125 final long identity = Binder.clearCallingIdentity();
10126 try {
10127 return getGbaManager(subId).overrideServicePackage(packageName);
10128 } finally {
10129 Binder.restoreCallingIdentity(identity);
10130 }
10131 }
10132
10133 /**
10134 * Return the package name of the currently bound GbaService.
10135 *
10136 * @param subId The sim that the GbaService is associated with.
10137 * @return the package name of the GbaService configuration, null if GBA is not supported.
10138 */
10139 @Override
10140 public String getBoundGbaService(int subId) {
10141 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10142
10143 final long identity = Binder.clearCallingIdentity();
10144 try {
10145 return getGbaManager(subId).getServicePackage();
10146 } finally {
10147 Binder.restoreCallingIdentity(identity);
10148 }
10149 }
10150
10151 /**
10152 * Set the release time for telephony to unbind GbaService.
10153 *
10154 * @param subId The sim that the GbaService is associated with.
10155 * @param interval The release time to unbind GbaService by millisecond.
10156 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10157 */
10158 @Override
10159 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10160 enforceModifyPermission();
10161
10162 final long identity = Binder.clearCallingIdentity();
10163 try {
10164 return getGbaManager(subId).overrideReleaseTime(interval);
10165 } finally {
10166 Binder.restoreCallingIdentity(identity);
10167 }
10168 }
10169
10170 /**
10171 * Return the release time for telephony to unbind GbaService.
10172 *
10173 * @param subId The sim that the GbaService is associated with.
10174 * @return The release time to unbind GbaService by millisecond.
10175 */
10176 @Override
10177 public int getGbaReleaseTime(int subId) {
10178 enforceReadPrivilegedPermission("getGbaReleaseTime");
10179
10180 final long identity = Binder.clearCallingIdentity();
10181 try {
10182 return getGbaManager(subId).getReleaseTime();
10183 } finally {
10184 Binder.restoreCallingIdentity(identity);
10185 }
10186 }
10187
10188 private GbaManager getGbaManager(int subId) {
10189 GbaManager instance = GbaManager.getInstance(subId);
10190 if (instance == null) {
10191 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10192 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10193 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10194 }
10195 return instance;
10196 }
Hui Wang761a6682020-10-31 05:12:53 +000010197
10198 /**
10199 * indicate whether the device and the carrier can support
10200 * RCS VoLTE single registration.
10201 */
10202 @Override
10203 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010204 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10205 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10206 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10207 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010208
10209 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10210 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10211 }
10212
10213 final long identity = Binder.clearCallingIdentity();
10214 try {
10215 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10216 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010217 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10218 if (isCapable != null) {
10219 return isCapable;
10220 }
Hui Wang761a6682020-10-31 05:12:53 +000010221 }
Hui Wang67af90e2021-06-04 16:57:15 -070010222 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10223 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
10228
10229 /**
10230 * Register RCS provisioning callback.
10231 */
10232 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010233 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010234 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010235 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010236 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010237 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10238 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010239
10240 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10241 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10242 }
10243 if (!isImsAvailableOnDevice()) {
10244 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10245 "IMS not available on device.");
10246 }
10247
10248 final long identity = Binder.clearCallingIdentity();
10249 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010250 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010251 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010252 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10253 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010254 }
Hui Wang761a6682020-10-31 05:12:53 +000010255 } finally {
10256 Binder.restoreCallingIdentity(identity);
10257 }
10258 }
10259
10260 /**
10261 * Unregister RCS provisioning callback.
10262 */
10263 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010264 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010265 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010266 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010267 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010268 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10269 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010270
10271 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10272 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10273 }
10274 if (!isImsAvailableOnDevice()) {
10275 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10276 "IMS not available on device.");
10277 }
10278
10279 final long identity = Binder.clearCallingIdentity();
10280 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010281 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010282 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010283 } finally {
10284 Binder.restoreCallingIdentity(identity);
10285 }
10286 }
10287
10288 /**
10289 * trigger RCS reconfiguration.
10290 */
10291 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010292 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10293 "triggerRcsReconfiguration",
10294 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010295
10296 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10297 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10298 }
10299 if (!isImsAvailableOnDevice()) {
10300 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10301 "IMS not available on device.");
10302 }
10303
10304 final long identity = Binder.clearCallingIdentity();
10305 try {
10306 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10307 } finally {
10308 Binder.restoreCallingIdentity(identity);
10309 }
10310 }
10311
10312 /**
10313 * Provide the client configuration parameters of the RCS application.
10314 */
10315 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010316 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10317 "setRcsClientConfiguration",
10318 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010319
10320 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10321 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10322 }
10323 if (!isImsAvailableOnDevice()) {
10324 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10325 "IMS not available on device.");
10326 }
10327
10328 final long identity = Binder.clearCallingIdentity();
10329
10330 try {
10331 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10332 if (configBinder == null) {
10333 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010334 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10335 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010336 } else {
10337 configBinder.setRcsClientConfiguration(rcc);
10338 }
10339 } catch (RemoteException e) {
10340 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010341 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10342 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010343 } finally {
10344 Binder.restoreCallingIdentity(identity);
10345 }
10346 }
10347
10348 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010349 * Enables or disables the test mode for RCS VoLTE single registration.
10350 */
10351 @Override
10352 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10353 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10354 "setRcsSingleRegistrationTestModeEnabled");
10355
10356 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10357 }
10358
10359 /**
10360 * Gets the test mode for RCS VoLTE single registration.
10361 */
10362 @Override
10363 public boolean getRcsSingleRegistrationTestModeEnabled() {
10364 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10365 "getRcsSingleRegistrationTestModeEnabled");
10366
10367 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10368 }
10369
10370 /**
Hui Wang761a6682020-10-31 05:12:53 +000010371 * Overrides the config of RCS VoLTE single registration enabled for the device.
10372 */
10373 @Override
10374 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10375 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10376 "setDeviceSingleRegistrationEnabledOverride");
10377 enforceModifyPermission();
10378
10379 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10380 : Boolean.parseBoolean(enabledStr);
10381 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010382 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010383 }
10384
10385 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010386 * Sends a device to device communication message. Only usable via shell.
10387 * @param message message to send.
10388 * @param value message value.
10389 */
10390 @Override
10391 public void sendDeviceToDeviceMessage(int message, int value) {
10392 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010393 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010394 enforceModifyPermission();
10395
10396 final long identity = Binder.clearCallingIdentity();
10397 try {
10398 TelephonyConnectionService service =
10399 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10400 if (service == null) {
10401 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10402 return;
10403 }
10404 service.sendTestDeviceToDeviceMessage(message, value);
10405 } finally {
10406 Binder.restoreCallingIdentity(identity);
10407 }
10408 }
10409
Tyler Gunnbabbda02021-02-10 11:05:02 -080010410 /**
10411 * Sets the specified device to device transport active.
10412 * @param transport The transport to set active.
10413 */
10414 @Override
10415 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10416 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10417 "setActiveDeviceToDeviceTransport");
10418 enforceModifyPermission();
10419
10420 final long identity = Binder.clearCallingIdentity();
10421 try {
10422 TelephonyConnectionService service =
10423 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10424 if (service == null) {
10425 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10426 return;
10427 }
10428 service.setActiveDeviceToDeviceTransport(transport);
10429 } finally {
10430 Binder.restoreCallingIdentity(identity);
10431 }
10432 }
Tyler Gunn92479152021-01-20 16:30:10 -080010433
Tyler Gunnd4575212021-05-03 14:46:49 -070010434 @Override
10435 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10436 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10437 "setDeviceToDeviceForceEnabled");
10438
10439 final long identity = Binder.clearCallingIdentity();
10440 try {
10441 Arrays.stream(PhoneFactory.getPhones()).forEach(
10442 p -> {
10443 Phone thePhone = p.getImsPhone();
10444 if (thePhone != null && thePhone instanceof ImsPhone) {
10445 ImsPhone imsPhone = (ImsPhone) thePhone;
10446 CallTracker tracker = imsPhone.getCallTracker();
10447 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10448 ImsPhoneCallTracker imsPhoneCallTracker =
10449 (ImsPhoneCallTracker) tracker;
10450 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10451 }
10452 }
10453 }
10454 );
10455 } finally {
10456 Binder.restoreCallingIdentity(identity);
10457 }
10458 }
10459
Tyler Gunn92479152021-01-20 16:30:10 -080010460 /**
Hui Wang761a6682020-10-31 05:12:53 +000010461 * Gets the config of RCS VoLTE single registration enabled for the device.
10462 */
10463 @Override
10464 public boolean getDeviceSingleRegistrationEnabled() {
10465 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10466 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10467 }
10468
10469 /**
10470 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10471 */
10472 @Override
10473 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10474 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10475 "setCarrierSingleRegistrationEnabledOverride");
10476 enforceModifyPermission();
10477
10478 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10479 : Boolean.parseBoolean(enabledStr);
10480 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10481 subId, enabled);
10482 }
10483
10484 /**
10485 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10486 */
10487 @Override
10488 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10489 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10490 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10491 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010492
10493 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010494 * Overrides the ims feature validation result
10495 */
10496 @Override
10497 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10498 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10499 "setImsFeatureValidationOverride");
10500
10501 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10502 : Boolean.parseBoolean(enabledStr);
10503 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10504 subId, enabled);
10505 }
10506
10507 /**
10508 * Gets the ims feature validation override value
10509 */
10510 @Override
10511 public boolean getImsFeatureValidationOverride(int subId) {
10512 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10513 "getImsFeatureValidationOverride");
10514 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10515 }
10516
10517 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010518 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10519 * their mobile plan.
10520 */
10521 @Override
10522 public String getMobileProvisioningUrl() {
10523 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10524 final long identity = Binder.clearCallingIdentity();
10525 try {
10526 return getDefaultPhone().getMobileProvisioningUrl();
10527 } finally {
10528 Binder.restoreCallingIdentity(identity);
10529 }
10530 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010531
James.cf Linbcdf8b32021-01-14 16:44:13 +080010532 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010533 * Get the EAB contact from the EAB database.
10534 */
10535 @Override
10536 public String getContactFromEab(String contact) {
10537 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10538 enforceModifyPermission();
10539 final long identity = Binder.clearCallingIdentity();
10540 try {
10541 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10542 } finally {
10543 Binder.restoreCallingIdentity(identity);
10544 }
10545 }
10546
10547 /**
Calvin Pana1434322021-07-01 19:27:01 +080010548 * Get the EAB capability from the EAB database.
10549 */
10550 @Override
10551 public String getCapabilityFromEab(String contact) {
10552 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10553 enforceModifyPermission();
10554 final long identity = Binder.clearCallingIdentity();
10555 try {
10556 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10557 } finally {
10558 Binder.restoreCallingIdentity(identity);
10559 }
10560 }
10561
10562 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010563 * Remove the EAB contacts from the EAB database.
10564 */
10565 @Override
10566 public int removeContactFromEab(int subId, String contacts) {
10567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10568 enforceModifyPermission();
10569 final long identity = Binder.clearCallingIdentity();
10570 try {
10571 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10572 } finally {
10573 Binder.restoreCallingIdentity(identity);
10574 }
10575 }
10576
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010577 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010578 public boolean getDeviceUceEnabled() {
10579 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10580 final long identity = Binder.clearCallingIdentity();
10581 try {
10582 return mApp.getDeviceUceEnabled();
10583 } finally {
10584 Binder.restoreCallingIdentity(identity);
10585 }
10586 }
10587
10588 @Override
10589 public void setDeviceUceEnabled(boolean isEnabled) {
10590 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10591 final long identity = Binder.clearCallingIdentity();
10592 try {
10593 mApp.setDeviceUceEnabled(isEnabled);
10594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
Brad Ebinger14d467f2021-02-12 06:18:28 +000010599 /**
10600 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10601 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10602 */
10603 // Used for SHELL command only right now.
10604 @Override
10605 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10606 List<String> featureTags) {
10607 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10608 "addUceRegistrationOverrideShell");
10609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10612 new ArraySet<>(featureTags));
10613 } catch (ImsException e) {
10614 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10615 } finally {
10616 Binder.restoreCallingIdentity(identity);
10617 }
10618 }
10619
10620 /**
10621 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10622 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10623 */
10624 // Used for SHELL command only right now.
10625 @Override
10626 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10627 List<String> featureTags) {
10628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10629 "removeUceRegistrationOverrideShell");
10630 final long identity = Binder.clearCallingIdentity();
10631 try {
10632 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10633 new ArraySet<>(featureTags));
10634 } catch (ImsException e) {
10635 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10636 } finally {
10637 Binder.restoreCallingIdentity(identity);
10638 }
10639 }
10640
10641 /**
10642 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10643 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10644 */
10645 // Used for SHELL command only right now.
10646 @Override
10647 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10648 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10649 "clearUceRegistrationOverrideShell");
10650 final long identity = Binder.clearCallingIdentity();
10651 try {
10652 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10653 } catch (ImsException e) {
10654 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10655 } finally {
10656 Binder.restoreCallingIdentity(identity);
10657 }
10658 }
10659
10660 /**
10661 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10662 */
10663 // Used for SHELL command only right now.
10664 @Override
10665 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10667 "getLatestRcsContactUceCapabilityShell");
10668 final long identity = Binder.clearCallingIdentity();
10669 try {
10670 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10671 } catch (ImsException e) {
10672 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10673 } finally {
10674 Binder.restoreCallingIdentity(identity);
10675 }
10676 }
10677
10678 /**
10679 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10680 * device does not have an active PUBLISH.
10681 */
10682 // Used for SHELL command only right now.
10683 @Override
10684 public String getLastUcePidfXmlShell(int subId) {
10685 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10686 final long identity = Binder.clearCallingIdentity();
10687 try {
10688 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10689 } catch (ImsException e) {
10690 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10691 } finally {
10692 Binder.restoreCallingIdentity(identity);
10693 }
10694 }
10695
James.cf Line8713a42021-04-29 16:04:26 +080010696 /**
10697 * Remove UCE requests cannot be sent to the network status.
10698 */
10699 // Used for SHELL command only right now.
10700 @Override
10701 public boolean removeUceRequestDisallowedStatus(int subId) {
10702 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10703 final long identity = Binder.clearCallingIdentity();
10704 try {
10705 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10706 } catch (ImsException e) {
10707 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
10712
James.cf Lin0fc71b02021-05-25 01:37:38 +080010713 /**
10714 * Remove UCE requests cannot be sent to the network status.
10715 */
10716 // Used for SHELL command only.
10717 @Override
10718 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10719 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10720 final long identity = Binder.clearCallingIdentity();
10721 try {
10722 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10723 } catch (ImsException e) {
10724 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10725 } finally {
10726 Binder.restoreCallingIdentity(identity);
10727 }
10728 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010729
James.cf Lin4b784aa2021-01-31 03:25:15 +080010730 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010731 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10732 String callingPackage) {
10733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10734 mApp, subId, "setSignalStrengthUpdateRequest");
10735
10736 final int callingUid = Binder.getCallingUid();
10737 // Verify that tha callingPackage belongs to the calling UID
10738 mApp.getSystemService(AppOpsManager.class)
10739 .checkPackage(callingUid, callingPackage);
10740
Rambo Wang3607f502021-02-01 21:51:40 -080010741 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010742
10743 final long identity = Binder.clearCallingIdentity();
10744 try {
10745 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10746 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10747
10748 if (result instanceof IllegalStateException) {
10749 throw (IllegalStateException) result;
10750 }
10751 } finally {
10752 Binder.restoreCallingIdentity(identity);
10753 }
10754 }
10755
10756 @Override
10757 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10758 String callingPackage) {
10759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10760 mApp, subId, "clearSignalStrengthUpdateRequest");
10761
10762 final int callingUid = Binder.getCallingUid();
10763 // Verify that tha callingPackage belongs to the calling UID
10764 mApp.getSystemService(AppOpsManager.class)
10765 .checkPackage(callingUid, callingPackage);
10766
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10770 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10771
10772 if (result instanceof IllegalStateException) {
10773 throw (IllegalStateException) result;
10774 }
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
10779
Rambo Wang3607f502021-02-01 21:51:40 -080010780 private static void validateSignalStrengthUpdateRequest(Context context,
10781 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010782 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10783 // phone/system process do not have further restriction on request
10784 return;
10785 }
10786
10787 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010788 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010789 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010790 context.enforceCallingOrSelfPermission(
10791 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10792 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010793 }
10794
10795 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10796 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10797 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10798 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10799 || info.isEnabled()) {
10800 throw new IllegalArgumentException(
10801 "Only system can set hide fields in SignalThresholdInfo");
10802 }
10803
10804 // Thresholds length for each RAN need in range. This has been validated in
10805 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10806 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10807 final int[] thresholds = info.getThresholds();
10808 Objects.requireNonNull(thresholds);
10809 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10810 || thresholds.length
10811 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10812 throw new IllegalArgumentException(
10813 "thresholds length is out of range: " + thresholds.length);
10814 }
10815 }
10816 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010817
10818 /**
10819 * Gets the current phone capability.
10820 *
10821 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10822 * @return the PhoneCapability which describes the data connection capability of modem.
10823 * It's used to evaluate possible phone config change, for example from single
10824 * SIM device to multi-SIM device.
10825 */
10826 @Override
10827 public PhoneCapability getPhoneCapability() {
10828 enforceReadPrivilegedPermission("getPhoneCapability");
10829 final long identity = Binder.clearCallingIdentity();
10830 try {
10831 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10832 } finally {
10833 Binder.restoreCallingIdentity(identity);
10834 }
10835 }
Michele Berionne5e411512020-11-13 02:36:59 +000010836
10837 /**
10838 * Prepare TelephonyManager for an unattended reboot. The reboot is
10839 * required to be done shortly after the API is invoked.
10840 */
10841 @Override
10842 @TelephonyManager.PrepareUnattendedRebootResult
10843 public int prepareForUnattendedReboot() {
10844 enforceRebootPermission();
10845
10846 final long identity = Binder.clearCallingIdentity();
10847 try {
10848 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10849 } finally {
10850 Binder.restoreCallingIdentity(identity);
10851 }
10852 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010853
10854 /**
10855 * Request to get the current slicing configuration including URSP rules and
10856 * NSSAIs (configured, allowed and rejected).
10857 *
10858 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10859 */
10860 @Override
10861 public void getSlicingConfig(ResultReceiver callback) {
10862 enforceReadPrivilegedPermission("getSlicingConfig");
10863
10864 final long identity = Binder.clearCallingIdentity();
10865 try {
10866 Phone phone = getDefaultPhone();
10867 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10868 } finally {
10869 Binder.restoreCallingIdentity(identity);
10870 }
10871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010872}