blob: b724d753ae3d0aa68a89bcafc63ea270f03e5187 [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;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000192import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800193import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000194import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800195import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700196import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700197import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800198import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800199import com.android.phone.callcomposer.CallComposerPictureManager;
200import com.android.phone.callcomposer.CallComposerPictureTransfer;
201import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700202import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700203import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800204import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700205import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700206import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800207import com.android.services.telephony.TelecomAccountRegistry;
208import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800209import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800210
Hall Liu82694d52020-12-11 18:22:04 -0800211import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700212import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800213import java.io.IOException;
214import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700215import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800217import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800218import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800219import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800220import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100221import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700223import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800226import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800227import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800228import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
230/**
231 * Implementation of the ITelephony interface.
232 */
Santos Cordon117fee72014-05-16 17:56:12 -0700233public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234 private static final String LOG_TAG = "PhoneInterfaceManager";
235 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
236 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800237 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238
239 // Message codes used with mMainThreadHandler
240 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700241 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
242 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243 private static final int CMD_OPEN_CHANNEL = 9;
244 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
245 private static final int CMD_CLOSE_CHANNEL = 11;
246 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800247 private static final int CMD_NV_READ_ITEM = 13;
248 private static final int EVENT_NV_READ_ITEM_DONE = 14;
249 private static final int CMD_NV_WRITE_ITEM = 15;
250 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
251 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
252 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700253 private static final int CMD_RESET_MODEM_CONFIG = 19;
254 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800255 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
256 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800257 private static final int CMD_SEND_ENVELOPE = 25;
258 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000259 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
260 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700261 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
262 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
263 private static final int CMD_EXCHANGE_SIM_IO = 31;
264 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800265 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
266 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700267 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
268 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700269 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
270 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700271 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
272 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
273 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
274 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700275 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
276 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
277 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
278 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700279 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800280 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
281 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000282 private static final int CMD_SWITCH_SLOTS = 50;
283 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700284 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
285 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
286 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
287 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
288 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
289 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
290 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
291 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700292 private static final int CMD_GET_ALL_CELL_INFO = 60;
293 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
294 private static final int CMD_GET_CELL_LOCATION = 62;
295 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700296 private static final int CMD_MODEM_REBOOT = 64;
297 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700298 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
299 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800300 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
301 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700302 private static final int CMD_GET_MODEM_STATUS = 70;
303 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700304 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
305 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700306 private static final int CMD_ERASE_MODEM_CONFIG = 74;
307 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800308 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
309 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
310 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
311 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800312 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
313 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800315 private static final int CMD_GET_CALL_FORWARDING = 83;
316 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
317 private static final int CMD_SET_CALL_FORWARDING = 85;
318 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
319 private static final int CMD_GET_CALL_WAITING = 87;
320 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
321 private static final int CMD_SET_CALL_WAITING = 89;
322 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700323 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
324 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
325 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
326 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700327 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
328 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800329 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
330 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800331 private static final int CMD_SET_DATA_THROTTLING = 99;
332 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800333 private static final int CMD_SET_SIM_POWER = 101;
334 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800335 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
336 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
337 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
338 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800339 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
340 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000341 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800342 private static final int CMD_GET_SLICING_CONFIG = 110;
343 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800344 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700345 private static final int CMD_ENABLE_VONR = 113;
346 private static final int EVENT_ENABLE_VONR_DONE = 114;
347 private static final int CMD_IS_VONR_ENABLED = 115;
348 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800350 // Parameters of select command.
351 private static final int SELECT_COMMAND = 0xA4;
352 private static final int SELECT_P1 = 0x04;
353 private static final int SELECT_P2 = 0;
354 private static final int SELECT_P3 = 0x10;
355
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 /** The singleton instance. */
357 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800358 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800362 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700363 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800364 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700365 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800366 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800367 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800368 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700369 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800370 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Peter Wangdafb9ac2020-01-15 14:13:38 -0800372 /** User Activity */
373 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800374 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
375
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700376 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
377
Derek Tan97ebb422014-09-05 16:55:38 -0700378 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
379 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800380 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800381 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700382
Michelecea4cf22018-12-21 15:00:11 -0800383 // String to store multi SIM allowed
384 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
385
Derek Tan740e1672017-06-27 14:56:27 -0700386 // The AID of ISD-R.
387 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
388
yinxub1bed742017-04-17 11:45:04 -0700389 private NetworkScanRequestTracker mNetworkScanRequestTracker;
390
David Kelly5e06a7f2018-03-12 14:10:59 +0000391 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
392 private static final int MANUFACTURER_CODE_LENGTH = 8;
393
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800394 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800395 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800396
Derek Tan89e89d42014-07-08 17:00:10 -0700397 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700398 * Experiment flag to enable erase modem config on reset network, default value is false
399 */
400 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
401 "reset_network_erase_modem_config_enabled";
402
Rambo Wang0f050d82021-02-12 11:43:36 -0800403 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
404
Naina Nallurid63128d2019-09-17 14:10:30 -0700405 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700406 * A request object to use for transmitting data to an ICC.
407 */
408 private static final class IccAPDUArgument {
409 public int channel, cla, command, p1, p2, p3;
410 public String data;
411
412 public IccAPDUArgument(int channel, int cla, int command,
413 int p1, int p2, int p3, String data) {
414 this.channel = channel;
415 this.cla = cla;
416 this.command = command;
417 this.p1 = p1;
418 this.p2 = p2;
419 this.p3 = p3;
420 this.data = data;
421 }
422 }
423
424 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700425 * A request object to use for transmitting data to an ICC.
426 */
427 private static final class ManualNetworkSelectionArgument {
428 public OperatorInfo operatorInfo;
429 public boolean persistSelection;
430
431 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
432 this.operatorInfo = operatorInfo;
433 this.persistSelection = persistSelection;
434 }
435 }
436
437 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
439 * request after sending. The main thread will notify the request when it is complete.
440 */
441 private static final class MainThreadRequest {
442 /** The argument to use for the request */
443 public Object argument;
444 /** The result of the request that is run on the main thread */
445 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800446 // The subscriber id that this request applies to. Defaults to
447 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
448 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449
Nathan Harold92bed182018-10-12 18:16:49 -0700450 // In cases where subId is unavailable, the caller needs to specify the phone.
451 public Phone phone;
452
vagdeviaf9a5b92018-08-15 16:01:53 -0700453 public WorkSource workSource;
454
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 public MainThreadRequest(Object argument) {
456 this.argument = argument;
457 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800458
Nathan Harold92bed182018-10-12 18:16:49 -0700459 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
460 this.argument = argument;
461 if (phone != null) {
462 this.phone = phone;
463 }
464 this.workSource = workSource;
465 }
466
vagdeviaf9a5b92018-08-15 16:01:53 -0700467 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800468 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800469 if (subId != null) {
470 this.subId = subId;
471 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700472 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 }
475
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800476 private static final class IncomingThirdPartyCallArgs {
477 public final ComponentName component;
478 public final String callId;
479 public final String callerDisplayName;
480
481 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
482 String callerDisplayName) {
483 this.component = component;
484 this.callId = callId;
485 this.callerDisplayName = callerDisplayName;
486 }
487 }
488
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 /**
490 * A handler that processes messages on the main thread in the phone process. Since many
491 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
492 * inbound binder threads to the main thread in the phone process. The Binder thread
493 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
494 * on, which will be notified when the operation completes and will contain the result of the
495 * request.
496 *
497 * <p>If a MainThreadRequest object is provided in the msg.obj field,
498 * note that request.result must be set to something non-null for the calling thread to
499 * unblock.
500 */
501 private final class MainThreadHandler extends Handler {
502 @Override
503 public void handleMessage(Message msg) {
504 MainThreadRequest request;
505 Message onCompleted;
506 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000507 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800509 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510
511 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 case CMD_HANDLE_USSD_REQUEST: {
513 request = (MainThreadRequest) msg.obj;
514 final Phone phone = getPhoneFromRequest(request);
515 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
516 String ussdRequest = ussdObject.first;
517 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700518
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 if (!isUssdApiAllowed(request.subId)) {
520 // Carrier does not support use of this API, return failure.
521 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
522 UssdResponse response = new UssdResponse(ussdRequest, null);
523 Bundle returnData = new Bundle();
524 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
525 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700526
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 request.result = true;
528 notifyRequester(request);
529 return;
530 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700531
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 try {
533 request.result = phone != null
534 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
535 } catch (CallStateException cse) {
536 request.result = false;
537 }
538 // Wake up the requesting thread
539 notifyRequester(request);
540 break;
pkanwar32d516d2016-10-14 19:37:38 -0700541 }
542
Yorke Lee716f67e2015-06-17 15:39:16 -0700543 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700545 final Phone phone = getPhoneFromRequest(request);
546 request.result = phone != null ?
547 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
548 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000557 uiccPort = getUiccPortFromRequest(request);
558 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 loge("iccTransmitApduLogicalChannel: No UICC");
560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
564 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000565 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 iccArgument.channel, iccArgument.cla, iccArgument.command,
567 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 break;
571
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
577 } else {
578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800581 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800583 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 } else {
585 loge("iccTransmitApduLogicalChannel: Unknown exception");
586 }
587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
593 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000594 uiccPort = getUiccPortFromRequest(request);
595 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 loge("iccTransmitApduBasicChannel: No UICC");
597 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 } else {
600 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
601 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000602 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
604 iccArgument.p3, iccArgument.data, onCompleted);
605 }
606 break;
607
608 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
611 if (ar.exception == null && ar.result != null) {
612 request.result = ar.result;
613 } else {
614 request.result = new IccIoResult(0x6F, 0, (byte[])null);
615 if (ar.result == null) {
616 loge("iccTransmitApduBasicChannel: Empty response");
617 } else if (ar.exception instanceof CommandException) {
618 loge("iccTransmitApduBasicChannel: CommandException: " +
619 ar.exception);
620 } else {
621 loge("iccTransmitApduBasicChannel: Unknown exception");
622 }
623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 break;
626
627 case CMD_EXCHANGE_SIM_IO:
628 request = (MainThreadRequest) msg.obj;
629 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000630 uiccPort = getUiccPortFromRequest(request);
631 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 loge("iccExchangeSimIO: No UICC");
633 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
637 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000638 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
640 iccArgument.data, onCompleted);
641 }
642 break;
643
644 case EVENT_EXCHANGE_SIM_IO_DONE:
645 ar = (AsyncResult) msg.obj;
646 request = (MainThreadRequest) ar.userObj;
647 if (ar.exception == null && ar.result != null) {
648 request.result = ar.result;
649 } else {
650 request.result = new IccIoResult(0x6f, 0, (byte[])null);
651 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 break;
654
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 case CMD_SEND_ENVELOPE:
656 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000657 uiccPort = getUiccPortFromRequest(request);
658 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 loge("sendEnvelopeWithStatus: No UICC");
660 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700661 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 } else {
663 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000664 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800666 break;
667
668 case EVENT_SEND_ENVELOPE_DONE:
669 ar = (AsyncResult) msg.obj;
670 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700671 if (ar.exception == null && ar.result != null) {
672 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800673 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700674 request.result = new IccIoResult(0x6F, 0, (byte[])null);
675 if (ar.result == null) {
676 loge("sendEnvelopeWithStatus: Empty response");
677 } else if (ar.exception instanceof CommandException) {
678 loge("sendEnvelopeWithStatus: CommandException: " +
679 ar.exception);
680 } else {
681 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
682 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 break;
686
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 case CMD_OPEN_CHANNEL:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800690 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000691 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800693 request.result = new IccOpenLogicalChannelResponse(-1,
694 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700696 } else {
697 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000698 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800699 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700700 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 break;
702
703 case EVENT_OPEN_CHANNEL_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 int[] result = (int[]) ar.result;
709 int channelId = result[0];
710 byte[] selectResponse = null;
711 if (result.length > 1) {
712 selectResponse = new byte[result.length - 1];
713 for (int i = 1; i < result.length; ++i) {
714 selectResponse[i - 1] = (byte) result[i];
715 }
716 }
717 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700718 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 if (ar.result == null) {
721 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 if (ar.exception != null) {
724 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
725 }
726
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700727 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700728 if (ar.exception instanceof CommandException) {
729 CommandException.Error error =
730 ((CommandException) (ar.exception)).getCommandError();
731 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700732 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700733 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700734 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 }
736 }
737 openChannelResp = new IccOpenLogicalChannelResponse(
738 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700740 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 break;
743
744 case CMD_CLOSE_CHANNEL:
745 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000746 uiccPort = getUiccPortFromRequest(request);
747 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700748 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900749 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700750 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700751 } else {
752 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000753 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700754 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 break;
756
757 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800758 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
759 break;
760
761 case CMD_NV_READ_ITEM:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
765 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800766 break;
767
768 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 ar = (AsyncResult) msg.obj;
770 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800771 if (ar.exception == null && ar.result != null) {
772 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800774 request.result = "";
775 if (ar.result == null) {
776 loge("nvReadItem: Empty response");
777 } else if (ar.exception instanceof CommandException) {
778 loge("nvReadItem: CommandException: " +
779 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700780 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800781 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 }
783 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
Jake Hambye994d462014-02-03 13:10:13 -0800787 case CMD_NV_WRITE_ITEM:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
790 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700792 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800793 break;
794
795 case EVENT_NV_WRITE_ITEM_DONE:
796 handleNullReturnEvent(msg, "nvWriteItem");
797 break;
798
799 case CMD_NV_WRITE_CDMA_PRL:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800802 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800803 break;
804
805 case EVENT_NV_WRITE_CDMA_PRL_DONE:
806 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
807 break;
808
chen xu6dac5ab2018-10-26 17:39:23 -0700809 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800810 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700811 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800812 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800813 break;
814
chen xu6dac5ab2018-10-26 17:39:23 -0700815 case EVENT_RESET_MODEM_CONFIG_DONE:
816 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800817 break;
818
Sooraj Sasindran37444802020-08-11 10:40:43 -0700819 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
822 request);
823 Phone phone = getPhoneFromRequest(request);
824 if (phone != null) {
825 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
826 } else {
827 loge("isNRDualConnectivityEnabled: No phone object");
828 request.result = false;
829 notifyRequester(request);
830 }
831 break;
832 }
833
834 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result;
839 } else {
840 // request.result must be set to something non-null
841 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700842 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700843 request.result = ar.result;
844 } else {
845 request.result = false;
846 }
847 if (ar.result == null) {
848 loge("isNRDualConnectivityEnabled: Empty response");
849 } else if (ar.exception instanceof CommandException) {
850 loge("isNRDualConnectivityEnabled: CommandException: "
851 + ar.exception);
852 } else {
853 loge("isNRDualConnectivityEnabled: Unknown exception");
854 }
855 }
856 notifyRequester(request);
857 break;
858
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700859 case CMD_IS_VONR_ENABLED: {
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
862 request);
863 Phone phone = getPhoneFromRequest(request);
864 if (phone != null) {
865 phone.isVoNrEnabled(onCompleted, request.workSource);
866 } else {
867 loge("isVoNrEnabled: No phone object");
868 request.result = false;
869 notifyRequester(request);
870 }
871 break;
872 }
873
874 case EVENT_IS_VONR_ENABLED_DONE:
875 ar = (AsyncResult) msg.obj;
876 request = (MainThreadRequest) ar.userObj;
877 if (ar.exception == null && ar.result != null) {
878 request.result = ar.result;
879 } else {
880 // request.result must be set to something non-null
881 // for the calling thread to unblock
882 if (ar.result != null) {
883 request.result = ar.result;
884 } else {
885 request.result = false;
886 }
887 if (ar.result == null) {
888 loge("isVoNrEnabled: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("isVoNrEnabled: CommandException: "
891 + ar.exception);
892 } else {
893 loge("isVoNrEnabled: Unknown exception");
894 }
895 }
896 notifyRequester(request);
897 break;
898
Sooraj Sasindran37444802020-08-11 10:40:43 -0700899 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
900 request = (MainThreadRequest) msg.obj;
901 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
902 Phone phone = getPhoneFromRequest(request);
903 if (phone != null) {
904 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
905 request.workSource);
906 } else {
907 loge("enableNrDualConnectivity: No phone object");
908 request.result =
909 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
910 notifyRequester(request);
911 }
912 break;
913 }
914
915 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null) {
919 request.result =
920 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
921 } else {
922 request.result =
923 TelephonyManager
924 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
925 if (ar.exception instanceof CommandException) {
926 CommandException.Error error =
927 ((CommandException) (ar.exception)).getCommandError();
928 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
929 request.result =
930 TelephonyManager
931 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000932 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
933 request.result =
934 TelephonyManager
935 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700936 }
937 loge("enableNrDualConnectivity" + ": CommandException: "
938 + ar.exception);
939 } else {
940 loge("enableNrDualConnectivity" + ": Unknown exception");
941 }
942 }
943 notifyRequester(request);
944 break;
945 }
946
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700947 case CMD_ENABLE_VONR: {
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
950 Phone phone = getPhoneFromRequest(request);
951 if (phone != null) {
952 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
953 request.workSource);
954 } else {
955 loge("setVoNrEnabled: No phone object");
956 request.result =
957 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
958 notifyRequester(request);
959 }
960 break;
961 }
962
963 case EVENT_ENABLE_VONR_DONE: {
964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
966 if (ar.exception == null) {
967 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
968 } else {
969 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
970 if (ar.exception instanceof CommandException) {
971 CommandException.Error error =
972 ((CommandException) (ar.exception)).getCommandError();
973 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
974 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
975 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
976 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
977 } else {
978 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
979 }
980 loge("setVoNrEnabled" + ": CommandException: "
981 + ar.exception);
982 } else {
983 loge("setVoNrEnabled" + ": Unknown exception");
984 }
985 }
986 notifyRequester(request);
987 break;
988 }
989
SongFerngWang3ef3e072020-12-21 16:41:52 +0800990 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800991 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800992 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
993 request);
994 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800995 break;
996
SongFerngWang3ef3e072020-12-21 16:41:52 +0800997 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception == null && ar.result != null) {
1001 request.result = ar.result; // Integer
1002 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301003 // request.result must be set to something non-null
1004 // for the calling thread to unblock
1005 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001006 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001007 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001008 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001009 loge("getAllowedNetworkTypesBitmask: CommandException: "
1010 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001011 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001012 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001013 }
1014 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001015 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 break;
1017
SongFerngWang3ef3e072020-12-21 16:41:52 +08001018 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001019 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001020 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1021 request);
1022 Pair<Integer, Long> reasonWithNetworkTypes =
1023 (Pair<Integer, Long>) request.argument;
1024 getPhoneFromRequest(request).setAllowedNetworkTypes(
1025 reasonWithNetworkTypes.first,
1026 reasonWithNetworkTypes.second,
1027 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001028 break;
1029
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1031 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001032 break;
1033
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001034 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1035 request = (MainThreadRequest)msg.obj;
1036 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001037 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001038 break;
1039
1040 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1041 ar = (AsyncResult)msg.obj;
1042 request = (MainThreadRequest)ar.userObj;
1043 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001044 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001045 break;
1046
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001047 case CMD_SET_VOICEMAIL_NUMBER:
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1050 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001051 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1052 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001053 break;
1054
1055 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1056 handleNullReturnEvent(msg, "setVoicemailNumber");
1057 break;
1058
Stuart Scott54788802015-03-30 13:18:01 -07001059 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1060 request = (MainThreadRequest) msg.obj;
1061 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1062 request);
1063 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1064 break;
1065
1066 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1067 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1068 break;
1069
Shishir Agrawal302c8692015-06-19 13:49:39 -07001070 case CMD_PERFORM_NETWORK_SCAN:
1071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1073 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1074 break;
1075
Hall Liu27d24262020-09-18 19:04:59 -07001076 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001077 request = (MainThreadRequest) msg.obj;
1078 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001079 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1080 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1081 request.argument;
1082 int callForwardingReason = args.first;
1083 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001084 break;
Hall Liu27d24262020-09-18 19:04:59 -07001085 }
1086 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001087 ar = (AsyncResult) msg.obj;
1088 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001089 TelephonyManager.CallForwardingInfoCallback callback =
1090 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1091 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001092 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001093 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001094 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1095 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1096 // Service Class is a bit mask per 3gpp 27.007. Search for
1097 // any service for voice call.
1098 if ((callForwardInfo.serviceClass
1099 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001100 callForwardingInfo = new CallForwardingInfo(
1101 callForwardInfo.status
1102 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001103 callForwardInfo.reason,
1104 callForwardInfo.number,
1105 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001106 break;
1107 }
1108 }
1109 // Didn't find a call forward info for voice call.
1110 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001111 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1112 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001113 }
Hall Liu27d24262020-09-18 19:04:59 -07001114 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001115 } else {
1116 if (ar.result == null) {
1117 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1118 }
1119 if (ar.exception != null) {
1120 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1121 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001122 int errorCode = TelephonyManager
1123 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001124 if (ar.exception instanceof CommandException) {
1125 CommandException.Error error =
1126 ((CommandException) (ar.exception)).getCommandError();
1127 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001128 errorCode = TelephonyManager
1129 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001130 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001131 errorCode = TelephonyManager
1132 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
1134 }
Hall Liu27d24262020-09-18 19:04:59 -07001135 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001136 }
Shuo Qian4a594052020-01-23 11:59:30 -08001137 break;
Hall Liu27d24262020-09-18 19:04:59 -07001138 }
Shuo Qian4a594052020-01-23 11:59:30 -08001139
Hall Liu27d24262020-09-18 19:04:59 -07001140 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001141 request = (MainThreadRequest) msg.obj;
1142 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001143 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001144 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001145 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1146 request.argument).first;
1147 request.phone.setCallForwardingOption(
1148 callForwardingInfoToSet.isEnabled()
1149 ? CommandsInterface.CF_ACTION_ENABLE
1150 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001151 callForwardingInfoToSet.getReason(),
1152 callForwardingInfoToSet.getNumber(),
1153 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1154 break;
Hall Liu27d24262020-09-18 19:04:59 -07001155 }
Shuo Qian4a594052020-01-23 11:59:30 -08001156
Hall Liu27d24262020-09-18 19:04:59 -07001157 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001158 ar = (AsyncResult) msg.obj;
1159 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001160 Consumer<Integer> callback =
1161 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1162 request.argument).second;
1163 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001164 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001165 int errorCode = TelephonyManager.CallForwardingInfoCallback
1166 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001167 if (ar.exception instanceof CommandException) {
1168 CommandException.Error error =
1169 ((CommandException) (ar.exception)).getCommandError();
1170 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001171 errorCode = TelephonyManager.CallForwardingInfoCallback
1172 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001173 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001174 errorCode = TelephonyManager.CallForwardingInfoCallback
1175 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001176 }
1177 }
1178 callback.accept(errorCode);
1179 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001180 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 }
Shuo Qian4a594052020-01-23 11:59:30 -08001182 break;
Hall Liu27d24262020-09-18 19:04:59 -07001183 }
Shuo Qian4a594052020-01-23 11:59:30 -08001184
Hall Liu27d24262020-09-18 19:04:59 -07001185 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1188 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1189 break;
Hall Liu27d24262020-09-18 19:04:59 -07001190 }
Shuo Qian4a594052020-01-23 11:59:30 -08001191
Hall Liu27d24262020-09-18 19:04:59 -07001192 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001193 ar = (AsyncResult) msg.obj;
1194 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001195 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1197 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001198 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 // Service Class is a bit mask per 3gpp 27.007.
1200 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001201 if (callForwardResults.length > 1
1202 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001203 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001204 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001205 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1206 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001208 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001209 }
1210 } else {
1211 if (ar.result == null) {
1212 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1213 }
1214 if (ar.exception != null) {
1215 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1216 }
1217 if (ar.exception instanceof CommandException) {
1218 CommandException.Error error =
1219 ((CommandException) (ar.exception)).getCommandError();
1220 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1221 callForwardingStatus =
1222 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1223 }
1224 }
1225 }
Hall Liu27d24262020-09-18 19:04:59 -07001226 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001227 break;
Hall Liu27d24262020-09-18 19:04:59 -07001228 }
Shuo Qian4a594052020-01-23 11:59:30 -08001229
Hall Liu27d24262020-09-18 19:04:59 -07001230 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001231 request = (MainThreadRequest) msg.obj;
1232 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001233 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1234 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001235 break;
Hall Liu27d24262020-09-18 19:04:59 -07001236 }
Shuo Qian4a594052020-01-23 11:59:30 -08001237
Hall Liu27d24262020-09-18 19:04:59 -07001238 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001239 ar = (AsyncResult) msg.obj;
1240 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001241 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1242 Consumer<Integer> callback =
1243 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1244 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001245 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001246 if (ar.exception instanceof CommandException) {
1247 CommandException.Error error =
1248 ((CommandException) (ar.exception)).getCommandError();
1249 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1250 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1251 } else {
1252 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1253 }
1254 } else {
1255 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1256 }
1257 } else {
1258 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1259 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001260 }
Shuo Qian4a594052020-01-23 11:59:30 -08001261 break;
Hall Liu27d24262020-09-18 19:04:59 -07001262 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001263 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1264 ar = (AsyncResult) msg.obj;
1265 request = (MainThreadRequest) ar.userObj;
1266 CellNetworkScanResult cellScanResult;
1267 if (ar.exception == null && ar.result != null) {
1268 cellScanResult = new CellNetworkScanResult(
1269 CellNetworkScanResult.STATUS_SUCCESS,
1270 (List<OperatorInfo>) ar.result);
1271 } else {
1272 if (ar.result == null) {
1273 loge("getCellNetworkScanResults: Empty response");
1274 }
1275 if (ar.exception != null) {
1276 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1277 }
1278 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1279 if (ar.exception instanceof CommandException) {
1280 CommandException.Error error =
1281 ((CommandException) (ar.exception)).getCommandError();
1282 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1283 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1284 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1285 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1286 }
1287 }
1288 cellScanResult = new CellNetworkScanResult(errorCode, null);
1289 }
1290 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001291 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001292 break;
1293
1294 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1295 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001296 ManualNetworkSelectionArgument selArg =
1297 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001298 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1299 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001300 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1301 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001302 break;
1303
1304 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001305 ar = (AsyncResult) msg.obj;
1306 request = (MainThreadRequest) ar.userObj;
1307 if (ar.exception == null) {
1308 request.result = true;
1309 } else {
1310 request.result = false;
1311 loge("setNetworkSelectionModeManual " + ar.exception);
1312 }
1313 notifyRequester(request);
1314 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001315 break;
1316
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001317 case CMD_GET_MODEM_ACTIVITY_INFO:
1318 request = (MainThreadRequest) msg.obj;
1319 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001320 if (defaultPhone != null) {
1321 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001322 } else {
1323 ResultReceiver result = (ResultReceiver) request.argument;
1324 Bundle bundle = new Bundle();
1325 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001326 new ModemActivityInfo(0, 0, 0,
1327 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001328 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001329 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001330 break;
1331
Hall Liud0f208c2020-10-14 16:54:44 -07001332 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001333 ar = (AsyncResult) msg.obj;
1334 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001335 ResultReceiver result = (ResultReceiver) request.argument;
1336
Hall Liud0f208c2020-10-14 16:54:44 -07001337 ModemActivityInfo ret = null;
1338 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001339 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001340 // Update the last modem activity info and the result of the request.
1341 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1342 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001343 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001344 int[] txTimeMs = info.getTransmitTimeMillis();
1345 int[] lastModemTxTimeMs = mLastModemActivityInfo
1346 .getTransmitTimeMillis();
1347 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1348 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1349 }
Hall Liu49656c02020-10-09 19:00:11 -07001350 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001351 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1352 + mLastModemActivityInfo.getSleepTimeMillis());
1353 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1354 + mLastModemActivityInfo.getIdleTimeMillis());
1355 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1356 mLastModemActivityInfo.setReceiveTimeMillis(
1357 info.getReceiveTimeMillis()
1358 + mLastModemActivityInfo.getReceiveTimeMillis());
1359 }
Hall Liu49656c02020-10-09 19:00:11 -07001360 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001361 mLastModemActivityInfo.getSleepTimeMillis(),
1362 mLastModemActivityInfo.getIdleTimeMillis(),
1363 mLastModemActivityInfo.getTransmitTimeMillis(),
1364 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001365 } else {
1366 if (ar.result == null) {
1367 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001368 error = TelephonyManager.ModemActivityInfoException
1369 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001370 } else if (ar.exception instanceof CommandException) {
1371 loge("queryModemActivityInfo: CommandException: " +
1372 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001373 error = TelephonyManager.ModemActivityInfoException
1374 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001375 } else {
1376 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001377 error = TelephonyManager.ModemActivityInfoException
1378 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001379 }
1380 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001381 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001382 if (ret != null) {
1383 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1384 } else {
1385 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1386 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001387 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001388 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001390 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001391
Meng Wang1a7c35a2016-05-05 20:56:15 -07001392 case CMD_SET_ALLOWED_CARRIERS:
1393 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001394 CarrierRestrictionRules argument =
1395 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001396 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001397 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001398 break;
1399
1400 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 if (ar.exception == null && ar.result != null) {
1404 request.result = ar.result;
1405 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001406 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1407 if (ar.exception instanceof CommandException) {
1408 loge("setAllowedCarriers: CommandException: " + ar.exception);
1409 CommandException.Error error =
1410 ((CommandException) (ar.exception)).getCommandError();
1411 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1412 request.result =
1413 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1414 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001415 } else {
1416 loge("setAllowedCarriers: Unknown exception");
1417 }
1418 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001419 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001420 break;
1421
1422 case CMD_GET_ALLOWED_CARRIERS:
1423 request = (MainThreadRequest) msg.obj;
1424 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001425 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001426 break;
1427
1428 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1429 ar = (AsyncResult) msg.obj;
1430 request = (MainThreadRequest) ar.userObj;
1431 if (ar.exception == null && ar.result != null) {
1432 request.result = ar.result;
1433 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001434 request.result = new IllegalStateException(
1435 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001436 if (ar.result == null) {
1437 loge("getAllowedCarriers: Empty response");
1438 } else if (ar.exception instanceof CommandException) {
1439 loge("getAllowedCarriers: CommandException: " +
1440 ar.exception);
1441 } else {
1442 loge("getAllowedCarriers: Unknown exception");
1443 }
1444 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001445 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001446 break;
1447
Nathan Haroldb3014052017-01-25 15:57:32 -08001448 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 if (ar.exception == null && ar.result != null) {
1452 request.result = ar.result;
1453 } else {
1454 request.result = new IllegalArgumentException(
1455 "Failed to retrieve Forbidden Plmns");
1456 if (ar.result == null) {
1457 loge("getForbiddenPlmns: Empty response");
1458 } else {
1459 loge("getForbiddenPlmns: Unknown exception");
1460 }
1461 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001462 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001463 break;
1464
1465 case CMD_GET_FORBIDDEN_PLMNS:
1466 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001467 uiccPort = getUiccPortFromRequest(request);
1468 if (uiccPort == null) {
1469 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001470 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001471 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001472 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001473 break;
1474 }
1475 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001476 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001477 if (uiccApp == null) {
1478 loge("getForbiddenPlmns() no app with specified type -- "
1479 + appType);
1480 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001481 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001482 break;
1483 } else {
1484 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1485 + " specified type -- " + appType);
1486 }
1487 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1488 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1489 onCompleted);
1490 break;
1491
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001492 case CMD_SWITCH_SLOTS:
1493 request = (MainThreadRequest) msg.obj;
1494 int[] physicalSlots = (int[]) request.argument;
1495 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1496 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1497 break;
1498
1499 case EVENT_SWITCH_SLOTS_DONE:
1500 ar = (AsyncResult) msg.obj;
1501 request = (MainThreadRequest) ar.userObj;
1502 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001503 notifyRequester(request);
1504 break;
1505 case CMD_GET_NETWORK_SELECTION_MODE:
1506 request = (MainThreadRequest) msg.obj;
1507 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1508 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1509 break;
1510
1511 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1512 ar = (AsyncResult) msg.obj;
1513 request = (MainThreadRequest) ar.userObj;
1514 if (ar.exception != null) {
1515 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1516 } else {
1517 int mode = ((int[]) ar.result)[0];
1518 if (mode == 0) {
1519 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1520 } else {
1521 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1522 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001523 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001524 notifyRequester(request);
1525 break;
1526 case CMD_GET_CDMA_ROAMING_MODE:
1527 request = (MainThreadRequest) msg.obj;
1528 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1529 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1530 break;
1531 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1532 ar = (AsyncResult) msg.obj;
1533 request = (MainThreadRequest) ar.userObj;
1534 if (ar.exception != null) {
1535 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1536 } else {
1537 request.result = ((int[]) ar.result)[0];
1538 }
1539 notifyRequester(request);
1540 break;
1541 case CMD_SET_CDMA_ROAMING_MODE:
1542 request = (MainThreadRequest) msg.obj;
1543 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1544 int mode = (int) request.argument;
1545 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1546 break;
1547 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 request.result = ar.exception == null;
1551 notifyRequester(request);
1552 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001553 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1554 request = (MainThreadRequest) msg.obj;
1555 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1556 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1557 break;
1558 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1559 ar = (AsyncResult) msg.obj;
1560 request = (MainThreadRequest) ar.userObj;
1561 if (ar.exception != null) {
1562 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1563 } else {
1564 request.result = ((int[]) ar.result)[0];
1565 }
1566 notifyRequester(request);
1567 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001568 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1569 request = (MainThreadRequest) msg.obj;
1570 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1571 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001572 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1573 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001574 break;
1575 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1576 ar = (AsyncResult) msg.obj;
1577 request = (MainThreadRequest) ar.userObj;
1578 request.result = ar.exception == null;
1579 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001580 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001581 case CMD_GET_ALL_CELL_INFO:
1582 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001583 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001584 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001585 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001586 case EVENT_GET_ALL_CELL_INFO_DONE:
1587 ar = (AsyncResult) msg.obj;
1588 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001589 // If a timeout occurs, the response will be null
1590 request.result = (ar.exception == null && ar.result != null)
1591 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001592 synchronized (request) {
1593 request.notifyAll();
1594 }
1595 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001596 case CMD_REQUEST_CELL_INFO_UPDATE:
1597 request = (MainThreadRequest) msg.obj;
1598 request.phone.requestCellInfoUpdate(request.workSource,
1599 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1600 break;
1601 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1605 try {
1606 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001607 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001608 cb.onError(
1609 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1610 ar.exception.getClass().getName(),
1611 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001613 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001614 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001615 } else {
1616 // use the result as returned
1617 cb.onCellInfo((List<CellInfo>) ar.result);
1618 }
1619 } catch (RemoteException re) {
1620 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1621 }
1622 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001623 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001624 request = (MainThreadRequest) msg.obj;
1625 WorkSource ws = (WorkSource) request.argument;
1626 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001627 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001628 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001629 }
1630 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception == null) {
1634 request.result = ar.result;
1635 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001636 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001637 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001638 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001639 }
1640
1641 synchronized (request) {
1642 request.notifyAll();
1643 }
1644 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001645 }
chen xu6dac5ab2018-10-26 17:39:23 -07001646 case CMD_MODEM_REBOOT:
1647 request = (MainThreadRequest) msg.obj;
1648 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001649 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001650 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001651 case EVENT_CMD_MODEM_REBOOT_DONE:
1652 handleNullReturnEvent(msg, "rebootModem");
1653 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001654 case CMD_REQUEST_ENABLE_MODEM:
1655 request = (MainThreadRequest) msg.obj;
1656 boolean enable = (boolean) request.argument;
1657 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001658 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001659 PhoneConfigurationManager.getInstance()
1660 .enablePhone(request.phone, enable, onCompleted);
1661 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001662 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001663 ar = (AsyncResult) msg.obj;
1664 request = (MainThreadRequest) ar.userObj;
1665 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001666 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001667 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001668 if ((boolean) request.result) {
1669 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1670 updateModemStateMetrics();
1671 } else {
1672 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1673 + ar.exception);
1674 }
1675 notifyRequester(request);
1676 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001677 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001678 case CMD_GET_MODEM_STATUS:
1679 request = (MainThreadRequest) msg.obj;
1680 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1681 PhoneConfigurationManager.getInstance()
1682 .getPhoneStatusFromModem(request.phone, onCompleted);
1683 break;
1684 case EVENT_GET_MODEM_STATUS_DONE:
1685 ar = (AsyncResult) msg.obj;
1686 request = (MainThreadRequest) ar.userObj;
1687 int id = request.phone.getPhoneId();
1688 if (ar.exception == null && ar.result != null) {
1689 request.result = ar.result;
1690 //update the cache as modem status has changed
1691 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1692 (boolean) request.result);
1693 } else {
1694 // Return true if modem status cannot be retrieved. For most cases,
1695 // modem status is on. And for older version modems, GET_MODEM_STATUS
1696 // and disable modem are not supported. Modem is always on.
1697 // TODO: this should be fixed in R to support a third
1698 // status UNKNOWN b/131631629
1699 request.result = true;
1700 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1701 + ar.exception);
1702 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001703 notifyRequester(request);
1704 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001705 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1708 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1709 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1710 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1711 break;
1712 }
1713 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1717 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1718 args.second.accept(ar.exception == null);
1719 notifyRequester(request);
1720 break;
1721 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001722 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1725 Phone phone = getPhoneFromRequest(request);
1726 if (phone != null) {
1727 phone.getSystemSelectionChannels(onCompleted);
1728 } else {
1729 loge("getSystemSelectionChannels: No phone object");
1730 request.result = new ArrayList<RadioAccessSpecifier>();
1731 notifyRequester(request);
1732 }
1733 break;
1734 }
1735 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1736 ar = (AsyncResult) msg.obj;
1737 request = (MainThreadRequest) ar.userObj;
1738 if (ar.exception == null && ar.result != null) {
1739 request.result = ar.result;
1740 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001741 request.result = new IllegalStateException(
1742 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001743 if (ar.result == null) {
1744 loge("getSystemSelectionChannels: Empty response");
1745 } else {
1746 loge("getSystemSelectionChannels: Unknown exception");
1747 }
1748 }
1749 notifyRequester(request);
1750 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001751 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1752 ar = (AsyncResult) msg.obj;
1753 request = (MainThreadRequest) ar.userObj;
1754 if (ar.exception == null && ar.result != null) {
1755 request.result = ar.result;
1756 } else {
1757 request.result = -1;
1758 loge("Failed to set Forbidden Plmns");
1759 if (ar.result == null) {
1760 loge("setForbidenPlmns: Empty response");
1761 } else if (ar.exception != null) {
1762 loge("setForbiddenPlmns: Exception: " + ar.exception);
1763 request.result = -1;
1764 } else {
1765 loge("setForbiddenPlmns: Unknown exception");
1766 }
1767 }
1768 notifyRequester(request);
1769 break;
1770 case CMD_SET_FORBIDDEN_PLMNS:
1771 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001772 uiccPort = getUiccPortFromRequest(request);
1773 if (uiccPort == null) {
1774 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001775 request.result = -1;
1776 notifyRequester(request);
1777 break;
1778 }
1779 Pair<Integer, List<String>> setFplmnsArgs =
1780 (Pair<Integer, List<String>>) request.argument;
1781 appType = setFplmnsArgs.first;
1782 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001783 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001784 if (uiccApp == null) {
1785 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1786 request.result = -1;
1787 loge("Failed to get UICC App");
1788 notifyRequester(request);
1789 } else {
1790 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1791 ((SIMRecords) uiccApp.getIccRecords())
1792 .setForbiddenPlmns(onCompleted, fplmns);
1793 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001794 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001795 case CMD_ERASE_MODEM_CONFIG:
1796 request = (MainThreadRequest) msg.obj;
1797 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1798 defaultPhone.eraseModemConfig(onCompleted);
1799 break;
1800 case EVENT_ERASE_MODEM_CONFIG_DONE:
1801 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001802 break;
zoey chene02881a2019-12-30 16:11:23 +08001803
Kai Shif70f46f2021-03-03 13:59:46 -08001804 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1805 request = (MainThreadRequest) msg.obj;
1806 request.result = defaultPhone.eraseDataInSharedPreferences();
1807 notifyRequester(request);
1808 break;
1809
zoey chene02881a2019-12-30 16:11:23 +08001810 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1811 request = (MainThreadRequest) msg.obj;
1812 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1813 Pair<String, String> changed = (Pair<String, String>) request.argument;
1814 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1815 changed.first, changed.second, onCompleted);
1816 break;
1817 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1818 ar = (AsyncResult) msg.obj;
1819 request = (MainThreadRequest) ar.userObj;
1820 if (ar.exception == null) {
1821 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001822 // If the operation is successful, update the PIN storage
1823 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1824 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001825 UiccController.getInstance().getPinStorage()
1826 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001827 } else {
1828 request.result = msg.arg1;
1829 }
1830 notifyRequester(request);
1831 break;
1832
Michele Berionne5e411512020-11-13 02:36:59 +00001833 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001834 request = (MainThreadRequest) msg.obj;
1835 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1836 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1837 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1838 enabled.first, enabled.second, onCompleted);
1839 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001840 }
zoey chene02881a2019-12-30 16:11:23 +08001841 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1842 ar = (AsyncResult) msg.obj;
1843 request = (MainThreadRequest) ar.userObj;
1844 if (ar.exception == null) {
1845 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001846 // If the operation is successful, update the PIN storage
1847 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1848 int phoneId = getPhoneFromRequest(request).getPhoneId();
1849 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001850 UiccController.getInstance().getPinStorage()
1851 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001852 } else {
1853 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1854 }
zoey chene02881a2019-12-30 16:11:23 +08001855 } else {
1856 request.result = msg.arg1;
1857 }
Michele Berionne5e411512020-11-13 02:36:59 +00001858
1859
zoey chene02881a2019-12-30 16:11:23 +08001860 notifyRequester(request);
1861 break;
1862
Peter Wangdafb9ac2020-01-15 14:13:38 -08001863 case MSG_NOTIFY_USER_ACTIVITY:
1864 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001865 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001866 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1867 getDefaultPhone().getContext().sendBroadcastAsUser(
1868 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1869 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001870
1871 case CMD_SET_DATA_THROTTLING: {
1872 request = (MainThreadRequest) msg.obj;
1873 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1874 DataThrottlingRequest dataThrottlingRequest =
1875 (DataThrottlingRequest) request.argument;
1876 Phone phone = getPhoneFromRequest(request);
1877 if (phone != null) {
1878 phone.setDataThrottling(onCompleted,
1879 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1880 dataThrottlingRequest.getCompletionDurationMillis());
1881 } else {
1882 loge("setDataThrottling: No phone object");
1883 request.result =
1884 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1885 notifyRequester(request);
1886 }
1887
1888 break;
1889 }
1890 case EVENT_SET_DATA_THROTTLING_DONE:
1891 ar = (AsyncResult) msg.obj;
1892 request = (MainThreadRequest) ar.userObj;
1893
1894 if (ar.exception == null) {
1895 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1896 } else if (ar.exception instanceof CommandException) {
1897 loge("setDataThrottling: CommandException: " + ar.exception);
1898 CommandException.Error error =
1899 ((CommandException) (ar.exception)).getCommandError();
1900
1901 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1902 request.result = TelephonyManager
1903 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1904 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1905 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001906 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1907 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001908 } else {
1909 request.result =
1910 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1911 }
1912 } else {
1913 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1914 }
1915 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1916 notifyRequester(request);
1917 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001918
1919 case CMD_SET_SIM_POWER: {
1920 request = (MainThreadRequest) msg.obj;
1921 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1922 request = (MainThreadRequest) msg.obj;
1923 int stateToSet =
1924 ((Pair<Integer, IIntegerConsumer>)
1925 request.argument).first;
1926 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1927 break;
1928 }
1929 case EVENT_SET_SIM_POWER_DONE: {
1930 ar = (AsyncResult) msg.obj;
1931 request = (MainThreadRequest) ar.userObj;
1932 IIntegerConsumer callback =
1933 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1934 if (ar.exception != null) {
1935 loge("setSimPower exception: " + ar.exception);
1936 int errorCode = TelephonyManager.CallForwardingInfoCallback
1937 .RESULT_ERROR_UNKNOWN;
1938 if (ar.exception instanceof CommandException) {
1939 CommandException.Error error =
1940 ((CommandException) (ar.exception)).getCommandError();
1941 if (error == CommandException.Error.SIM_ERR) {
1942 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1943 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1944 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1945 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1946 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1947 } else {
1948 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1949 }
1950 }
1951 try {
1952 callback.accept(errorCode);
1953 } catch (RemoteException e) {
1954 // Ignore if the remote process is no longer available to call back.
1955 Log.w(LOG_TAG, "setSimPower: callback not available.");
1956 }
1957 } else {
1958 try {
1959 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1960 } catch (RemoteException e) {
1961 // Ignore if the remote process is no longer available to call back.
1962 Log.w(LOG_TAG, "setSimPower: callback not available.");
1963 }
1964 }
1965 break;
1966 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001967 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1968 request = (MainThreadRequest) msg.obj;
1969
1970 final Phone phone = getPhoneFromRequest(request);
1971 if (phone == null || phone.getServiceStateTracker() == null) {
1972 request.result = new IllegalStateException("Phone or SST is null");
1973 notifyRequester(request);
1974 break;
1975 }
1976
1977 Pair<Integer, SignalStrengthUpdateRequest> pair =
1978 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1979 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1980 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001981 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001982 request.subId, pair.first /*callingUid*/,
1983 pair.second /*request*/, onCompleted);
1984 break;
1985 }
1986 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1987 ar = (AsyncResult) msg.obj;
1988 request = (MainThreadRequest) ar.userObj;
1989 // request.result will be the exception of ar if present, true otherwise.
1990 // Be cautious not to leave result null which will wait() forever
1991 request.result = ar.exception != null ? ar.exception : true;
1992 notifyRequester(request);
1993 break;
1994 }
1995 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1996 request = (MainThreadRequest) msg.obj;
1997
1998 Phone phone = getPhoneFromRequest(request);
1999 if (phone == null || phone.getServiceStateTracker() == null) {
2000 request.result = new IllegalStateException("Phone or SST is null");
2001 notifyRequester(request);
2002 break;
2003 }
2004
2005 Pair<Integer, SignalStrengthUpdateRequest> pair =
2006 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2007 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2008 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002009 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002010 request.subId, pair.first /*callingUid*/,
2011 pair.second /*request*/, onCompleted);
2012 break;
2013 }
2014 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2015 ar = (AsyncResult) msg.obj;
2016 request = (MainThreadRequest) ar.userObj;
2017 request.result = ar.exception != null ? ar.exception : true;
2018 notifyRequester(request);
2019 break;
2020 }
Jordan Liu109698e2020-11-24 14:50:34 -08002021
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002022 case CMD_GET_SLICING_CONFIG: {
2023 request = (MainThreadRequest) msg.obj;
2024 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2025 request.phone.getSlicingConfig(onCompleted);
2026 break;
2027 }
2028 case EVENT_GET_SLICING_CONFIG_DONE: {
2029 ar = (AsyncResult) msg.obj;
2030 request = (MainThreadRequest) ar.userObj;
2031 ResultReceiver result = (ResultReceiver) request.argument;
2032
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002033 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002034 Bundle bundle = new Bundle();
2035 int resultCode = 0;
2036 if (ar.exception != null) {
2037 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2038 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002039 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002040 } else if (ar.result == null) {
2041 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002042 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002043 } else {
2044 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002045 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2046 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002047 }
2048
2049 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002050 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002051 }
2052 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2053 result.send(resultCode, bundle);
2054 notifyRequester(request);
2055 break;
2056 }
2057
Michele Berionne5e411512020-11-13 02:36:59 +00002058 case CMD_PREPARE_UNATTENDED_REBOOT:
2059 request = (MainThreadRequest) msg.obj;
2060 request.result =
2061 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2062 notifyRequester(request);
2063 break;
2064
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 default:
2066 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2067 break;
2068 }
2069 }
Jake Hambye994d462014-02-03 13:10:13 -08002070
Pengquan Menga1bb6272018-09-06 09:59:22 -07002071 private void notifyRequester(MainThreadRequest request) {
2072 synchronized (request) {
2073 request.notifyAll();
2074 }
2075 }
2076
Jake Hambye994d462014-02-03 13:10:13 -08002077 private void handleNullReturnEvent(Message msg, String command) {
2078 AsyncResult ar = (AsyncResult) msg.obj;
2079 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2080 if (ar.exception == null) {
2081 request.result = true;
2082 } else {
2083 request.result = false;
2084 if (ar.exception instanceof CommandException) {
2085 loge(command + ": CommandException: " + ar.exception);
2086 } else {
2087 loge(command + ": Unknown exception");
2088 }
2089 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002090 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 }
2093
2094 /**
2095 * Posts the specified command to be executed on the main thread,
2096 * waits for the request to complete, and returns the result.
2097 * @see #sendRequestAsync
2098 */
2099 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002100 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2101 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002102 }
2103
2104 /**
2105 * Posts the specified command to be executed on the main thread,
2106 * waits for the request to complete, and returns the result.
2107 * @see #sendRequestAsync
2108 */
2109 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2110 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002111 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002112 }
2113
2114 /**
2115 * Posts the specified command to be executed on the main thread,
2116 * waits for the request to complete, and returns the result.
2117 * @see #sendRequestAsync
2118 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002119 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002120 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2121 }
2122
2123 /**
2124 * Posts the specified command to be executed on the main thread,
2125 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2126 * if not timeout or null otherwise.
2127 * @see #sendRequestAsync
2128 */
2129 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2130 long timeoutInMs) {
2131 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002132 }
2133
2134 /**
2135 * Posts the specified command to be executed on the main thread,
2136 * waits for the request to complete, and returns the result.
2137 * @see #sendRequestAsync
2138 */
Nathan Harold92bed182018-10-12 18:16:49 -07002139 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002140 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002141 }
2142
2143 /**
2144 * Posts the specified command to be executed on the main thread,
2145 * waits for the request to complete, and returns the result.
2146 * @see #sendRequestAsync
2147 */
2148 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002149 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2150 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002151 }
2152
2153 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002154 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2155 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2156 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002157 * @see #sendRequestAsync
2158 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002159 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2160 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2162 throw new RuntimeException("This method will deadlock if called from the main thread.");
2163 }
2164
Nathan Harold92bed182018-10-12 18:16:49 -07002165 MainThreadRequest request = null;
2166 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2167 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2168 } else if (phone != null) {
2169 request = new MainThreadRequest(argument, phone, workSource);
2170 } else {
2171 request = new MainThreadRequest(argument, subId, workSource);
2172 }
2173
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 Message msg = mMainThreadHandler.obtainMessage(command, request);
2175 msg.sendToTarget();
2176
Rambo Wang0f050d82021-02-12 11:43:36 -08002177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 if (timeoutInMs >= 0) {
2180 // Wait for at least timeoutInMs before returning null request result
2181 long now = SystemClock.elapsedRealtime();
2182 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002183 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002184 try {
2185 request.wait(deadline - now);
2186 } catch (InterruptedException e) {
2187 // Do nothing, go back and check if request is completed or timeout
2188 } finally {
2189 now = SystemClock.elapsedRealtime();
2190 }
2191 }
2192 } else {
2193 // Wait for the request to complete
2194 while (request.result == null) {
2195 try {
2196 request.wait();
2197 } catch (InterruptedException e) {
2198 // Do nothing, go back and wait until the request is complete
2199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201 }
2202 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002203 if (request.result == null) {
2204 Log.wtf(LOG_TAG,
2205 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 return request.result;
2208 }
2209
2210 /**
2211 * Asynchronous ("fire and forget") version of sendRequest():
2212 * Posts the specified command to be executed on the main thread, and
2213 * returns immediately.
2214 * @see #sendRequest
2215 */
2216 private void sendRequestAsync(int command) {
2217 mMainThreadHandler.sendEmptyMessage(command);
2218 }
2219
2220 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002221 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002222 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 */
2224 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 sendRequestAsync(command, argument, null, null);
2226 }
2227
2228 /**
2229 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2230 * @see {@link #sendRequest(int,Object)}
2231 */
2232 private void sendRequestAsync(
2233 int command, Object argument, Phone phone, WorkSource workSource) {
2234 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002235 Message msg = mMainThreadHandler.obtainMessage(command, request);
2236 msg.sendToTarget();
2237 }
2238
2239 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 * Initialize the singleton PhoneInterfaceManager instance.
2241 * This is only done once, at startup, from PhoneApp.onCreate().
2242 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002243 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 synchronized (PhoneInterfaceManager.class) {
2245 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002246 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 } else {
2248 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2249 }
2250 return sInstance;
2251 }
2252 }
2253
2254 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002255 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002258 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002259 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002261 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002263 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002264 mTelephonySharedPreferences =
2265 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002266 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002267 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002268 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002269 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002270
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 publish();
2272 }
2273
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002274 private Phone getDefaultPhone() {
2275 Phone thePhone = getPhone(getDefaultSubscription());
2276 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2277 }
2278
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 private void publish() {
2280 if (DBG) log("publish: " + this);
2281
Peter Wangc035ce42020-01-08 21:00:22 -08002282 TelephonyFrameworkInitializer
2283 .getTelephonyServiceManager()
2284 .getTelephonyServiceRegisterer()
2285 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 }
2287
Stuart Scott584921c2015-01-15 17:10:34 -08002288 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002289 if (request.phone != null) {
2290 return request.phone;
2291 } else {
2292 return getPhoneFromSubId(request.subId);
2293 }
2294 }
2295
2296 private Phone getPhoneFromSubId(int subId) {
2297 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2298 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002299 }
2300
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002301 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002302 Phone phone = getPhoneFromRequest(request);
2303 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002304 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002305 }
2306
Wink Saville36469e72014-06-11 15:17:00 -07002307 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002308 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002309 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311
Kai Shif70f46f2021-03-03 13:59:46 -08002312 private void sendEraseModemConfig(@NonNull Phone phone) {
2313 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2314 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2315 }
2316
2317 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2318 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2319 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002320 }
2321
Peter Wang44b186e2020-01-13 23:33:09 -08002322 private boolean isImsAvailableOnDevice() {
2323 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2324 if (pm == null) {
2325 // For some reason package manger is not available.. This will fail internally anyway,
2326 // so do not throw error and allow.
2327 return true;
2328 }
2329 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2330 }
2331
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002333 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002334 }
2335
Wink Savilleb564aae2014-10-23 10:18:09 -07002336 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 if (DBG) log("dial: " + number);
2338 // No permission check needed here: This is just a wrapper around the
2339 // ACTION_DIAL intent, which is available to any app since it puts up
2340 // the UI before it does anything.
2341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 String url = createTelUrl(number);
2345 if (url == null) {
2346 return;
2347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349 // PENDING: should we just silently fail if phone is offhook or ringing?
2350 PhoneConstants.State state = mCM.getState(subId);
2351 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2352 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2353 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2354 mApp.startActivity(intent);
2355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 }
2359 }
2360
2361 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002362 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002363 }
2364
Wink Savilleb564aae2014-10-23 10:18:09 -07002365 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 if (DBG) log("call: " + number);
2367
2368 // This is just a wrapper around the ACTION_CALL intent, but we still
2369 // need to do a permission check since we're calling startActivity()
2370 // from the context of the phone app.
2371 enforceCallPermission();
2372
Jordan Liu1617b712019-07-10 15:06:26 -07002373 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 != AppOpsManager.MODE_ALLOWED) {
2375 return;
2376 }
2377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 String url = createTelUrl(number);
2381 if (url == null) {
2382 return;
2383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002385 boolean isValid = false;
2386 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2387 if (slist != null) {
2388 for (SubscriptionInfo subInfoRecord : slist) {
2389 if (subInfoRecord.getSubscriptionId() == subId) {
2390 isValid = true;
2391 break;
2392 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002393 }
Wink Saville08874612014-08-31 19:19:58 -07002394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002395 if (!isValid) {
2396 return;
2397 }
Wink Saville08874612014-08-31 19:19:58 -07002398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2400 intent.putExtra(SUBSCRIPTION_KEY, subId);
2401 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2402 mApp.startActivity(intent);
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
2405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 }
2407
Wink Savilleb564aae2014-10-23 10:18:09 -07002408 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002409 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002410 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2411 }
2412
Wink Savilleb564aae2014-10-23 10:18:09 -07002413 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002414 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002415 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2416 }
2417
Wink Savilleb564aae2014-10-23 10:18:09 -07002418 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420
2421 final long identity = Binder.clearCallingIdentity();
2422 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002423 Phone phone = getPhone(subId);
2424 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425 checkSimPin.start();
2426 return checkSimPin.unlockSim(null, pin);
2427 } finally {
2428 Binder.restoreCallingIdentity(identity);
2429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 }
2431
Wink Savilleb564aae2014-10-23 10:18:09 -07002432 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434
2435 final long identity = Binder.clearCallingIdentity();
2436 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002437 Phone phone = getPhone(subId);
2438 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002439 checkSimPuk.start();
2440 return checkSimPuk.unlockSim(puk, pin);
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
2443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
2446 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002447 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 * a synchronous one.
2449 */
2450 private static class UnlockSim extends Thread {
2451
2452 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002453 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454
2455 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002456 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2457 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458
2459 // For replies from SimCard interface
2460 private Handler mHandler;
2461
2462 // For async handler to identify request type
2463 private static final int SUPPLY_PIN_COMPLETE = 100;
2464
Michele Berionne5e411512020-11-13 02:36:59 +00002465 UnlockSim(int phoneId, IccCard simCard) {
2466 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 mSimCard = simCard;
2468 }
2469
2470 @Override
2471 public void run() {
2472 Looper.prepare();
2473 synchronized (UnlockSim.this) {
2474 mHandler = new Handler() {
2475 @Override
2476 public void handleMessage(Message msg) {
2477 AsyncResult ar = (AsyncResult) msg.obj;
2478 switch (msg.what) {
2479 case SUPPLY_PIN_COMPLETE:
2480 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2481 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002482 mRetryCount = msg.arg1;
2483 if (ar.exception != null) {
2484 if (ar.exception instanceof CommandException &&
2485 ((CommandException)(ar.exception)).getCommandError()
2486 == CommandException.Error.PASSWORD_INCORRECT) {
2487 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002488 } //When UiccCardApp dispose,handle message and return exception
2489 else if (ar.exception instanceof CommandException &&
2490 ((CommandException) (ar.exception)).getCommandError()
2491 == CommandException.Error.ABORTED) {
2492 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002493 } else {
2494 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2495 }
2496 } else {
2497 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 mDone = true;
2500 UnlockSim.this.notifyAll();
2501 }
2502 break;
2503 }
2504 }
2505 };
2506 UnlockSim.this.notifyAll();
2507 }
2508 Looper.loop();
2509 }
2510
2511 /*
2512 * Use PIN or PUK to unlock SIM card
2513 *
2514 * If PUK is null, unlock SIM card with PIN
2515 *
2516 * If PUK is not null, unlock SIM card with PUK and set PIN code
2517 */
Wink Saville9de0f752013-10-22 19:04:03 -07002518 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519
2520 while (mHandler == null) {
2521 try {
2522 wait();
2523 } catch (InterruptedException e) {
2524 Thread.currentThread().interrupt();
2525 }
2526 }
2527 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2528
2529 if (puk == null) {
2530 mSimCard.supplyPin(pin, callback);
2531 } else {
2532 mSimCard.supplyPuk(puk, pin, callback);
2533 }
2534
2535 while (!mDone) {
2536 try {
2537 Log.d(LOG_TAG, "wait for done");
2538 wait();
2539 } catch (InterruptedException e) {
2540 // Restore the interrupted status
2541 Thread.currentThread().interrupt();
2542 }
2543 }
2544 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002545 int[] resultArray = new int[2];
2546 resultArray[0] = mResult;
2547 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002548
2549 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002550 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002551 }
2552
Wink Saville9de0f752013-10-22 19:04:03 -07002553 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 }
2555 }
2556
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002557 /**
2558 * This method has been removed due to privacy and stability concerns.
2559 */
2560 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002562 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2563 return;
Wink Saville36469e72014-06-11 15:17:00 -07002564 }
2565
Nathan Harold1f889d82020-06-04 17:05:26 -07002566 @Override
2567 public void updateServiceLocationWithPackageName(String callingPackage) {
2568 mApp.getSystemService(AppOpsManager.class)
2569 .checkPackage(Binder.getCallingUid(), callingPackage);
2570
Nathan Haroldf096d982020-11-18 17:18:06 -08002571 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002572 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2573 // Callers targeting S have no business invoking this method.
2574 return;
2575 }
2576
2577 LocationAccessPolicy.LocationPermissionResult locationResult =
2578 LocationAccessPolicy.checkLocationPermission(mApp,
2579 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2580 .setCallingPackage(callingPackage)
2581 .setCallingFeatureId(null)
2582 .setCallingPid(Binder.getCallingPid())
2583 .setCallingUid(Binder.getCallingUid())
2584 .setMethod("updateServiceLocation")
2585 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2586 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2587 .build());
2588 // Apps that lack location permission have no business calling this method;
2589 // however, because no permission was declared in the public API, denials must
2590 // all be "soft".
2591 switch (locationResult) {
2592 case DENIED_HARD: /* fall through */
2593 case DENIED_SOFT:
2594 return;
2595 }
2596
2597 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002600 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002602 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 }
2604 } finally {
2605 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 }
2608
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002609 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002610 @Override
2611 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002612 return isRadioOnWithFeature(callingPackage, null);
2613 }
2614
2615
2616 @Override
2617 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2618 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2619 callingFeatureId);
2620 }
2621
2622 @Deprecated
2623 @Override
2624 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2625 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002626 }
2627
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002629 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2630 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002633 return false;
2634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 return isRadioOnForSubscriber(subId);
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
2641 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002642 }
2643
2644 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 final Phone phone = getPhone(subId);
2648 if (phone != null) {
2649 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2650 } else {
2651 return false;
2652 }
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 }
2657
2658 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002659 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 }
Wink Saville36469e72014-06-11 15:17:00 -07002661
Wink Savilleb564aae2014-10-23 10:18:09 -07002662 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664
2665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 if (phone != null) {
2669 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Wink Saville36469e72014-06-11 15:17:00 -07002674 }
2675
2676 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002678 }
2679
Wink Savilleb564aae2014-10-23 10:18:09 -07002680 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002681 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 final Phone phone = getPhone(subId);
2686 if (phone == null) {
2687 return false;
2688 }
2689 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2690 toggleRadioOnOffForSubscriber(subId);
2691 }
2692 return true;
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 }
Wink Saville36469e72014-06-11 15:17:00 -07002697
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002698 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002699 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002700 /*
2701 * If any of the Radios are available, it will need to be
2702 * shutdown. So return true if any Radio is available.
2703 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2707 Phone phone = PhoneFactory.getPhone(i);
2708 if (phone != null && phone.isRadioAvailable()) return true;
2709 }
2710 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2711 return false;
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002714 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002715 }
2716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 enforceModifyPermission();
2720
2721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2724 logv("Shutting down Phone " + i);
2725 shutdownRadioUsingPhoneId(i);
2726 }
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002729 }
2730 }
2731
2732 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002733 Phone phone = PhoneFactory.getPhone(phoneId);
2734 if (phone != null && phone.isRadioAvailable()) {
2735 phone.shutdownRadio();
2736 }
2737 }
2738
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002740 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741
2742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2745 if (defaultPhone != null) {
2746 defaultPhone.setRadioPower(turnOn);
2747 return true;
2748 } else {
2749 loge("There's no default phone.");
2750 return false;
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002754 }
Wink Saville36469e72014-06-11 15:17:00 -07002755 }
2756
Wink Savilleb564aae2014-10-23 10:18:09 -07002757 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759
2760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 final Phone phone = getPhone(subId);
2763 if (phone != null) {
2764 phone.setRadioPower(turnOn);
2765 return true;
2766 } else {
2767 return false;
2768 }
2769 } finally {
2770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 }
2773
Wink Saville36469e72014-06-11 15:17:00 -07002774 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002775 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 public boolean enableDataConnectivity() {
2777 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778
2779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 int subId = mSubscriptionController.getDefaultDataSubId();
2782 final Phone phone = getPhone(subId);
2783 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002784 phone.getDataEnabledSettings().setDataEnabled(
2785 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 return true;
2787 } else {
2788 return false;
2789 }
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002793 }
2794
Wink Saville36469e72014-06-11 15:17:00 -07002795 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 public boolean disableDataConnectivity() {
2798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 int subId = mSubscriptionController.getDefaultDataSubId();
2803 final Phone phone = getPhone(subId);
2804 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002805 phone.getDataEnabledSettings().setDataEnabled(
2806 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 return true;
2808 } else {
2809 return false;
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
2815
Sanket Padawe356d7632015-06-22 14:03:32 -07002816 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002817 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 final Phone phone = getPhone(subId);
2821 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002822 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823 } else {
2824 return false;
2825 }
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 }
2830
2831 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002832 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002833 }
2834
pkanwarae03a6b2016-11-06 20:37:09 -08002835 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 enforceCallPermission();
2837
2838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2841 return;
2842 }
2843 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2844 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
pkanwar32d516d2016-10-14 19:37:38 -07002848 };
2849
Wink Savilleb564aae2014-10-23 10:18:09 -07002850 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2856 return false;
2857 }
2858 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
2863
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002864 /**
2865 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2866 * tag on getCallState Binder call.
2867 */
2868 @Deprecated
2869 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002871 if (CompatChanges.isChangeEnabled(
2872 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2873 Binder.getCallingUid())) {
2874 // Do not allow this API to be called on API version 31+, it should only be
2875 // called on old apps using this Binder call directly.
2876 throw new SecurityException("This method can only be used for applications "
2877 + "targeting API version 30 or less.");
2878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 final long identity = Binder.clearCallingIdentity();
2880 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002881 Phone phone = getPhone(getDefaultSubscription());
2882 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2883 PhoneConstantConversions.convertCallState(phone.getState());
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
2886 }
2887 }
2888
2889 @Override
2890 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2891 if (CompatChanges.isChangeEnabled(
2892 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2893 Binder.getCallingUid())) {
2894 // Check READ_PHONE_STATE for API version 31+
2895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2896 featureId, "getCallStateForSubscription")) {
2897 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2898 + "targeting API level 31+.");
2899 }
2900 }
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2905 PhoneConstantConversions.convertCallState(phone.getState());
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002909 }
2910
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002912 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002913 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2914 }
2915
2916 @Override
2917 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 final long identity = Binder.clearCallingIdentity();
2919 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002920 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 if (phone != null) {
2922 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2923 } else {
2924 return PhoneConstantConversions.convertDataState(
2925 PhoneConstants.DataState.DISCONNECTED);
2926 }
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002933 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002934 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2935 }
2936
2937 @Override
2938 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 final long identity = Binder.clearCallingIdentity();
2940 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002941 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 if (phone != null) {
2943 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2944 } else {
2945 return TelephonyManager.DATA_ACTIVITY_NONE;
2946 }
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002950 }
2951
2952 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002953 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002954 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002955 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002956
2957 LocationAccessPolicy.LocationPermissionResult locationResult =
2958 LocationAccessPolicy.checkLocationPermission(mApp,
2959 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2960 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002961 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002962 .setCallingPid(Binder.getCallingPid())
2963 .setCallingUid(Binder.getCallingUid())
2964 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002965 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002966 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2967 .build());
2968 switch (locationResult) {
2969 case DENIED_HARD:
2970 throw new SecurityException("Not allowed to access cell location");
2971 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002972 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2973 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 }
2975
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002980 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002981 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982 } finally {
2983 Binder.restoreCallingIdentity(identity);
2984 }
Svetoslav64fad262015-04-14 14:35:21 -07002985 }
2986
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002987 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002988 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002989 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2990 // registered cell info, so return a NULL country instead.
2991 final long identity = Binder.clearCallingIdentity();
2992 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002993 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2994 // Get default phone in this case.
2995 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2996 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002997 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002999 if (phone == null) return "";
3000 ServiceStateTracker sst = phone.getServiceStateTracker();
3001 if (sst == null) return "";
3002 LocaleTracker lt = sst.getLocaleTracker();
3003 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003004 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003008 }
3009
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003010 /**
3011 * This method was removed due to potential issues caused by performing partial
3012 * updates of service state, and lack of a credible use case.
3013 *
3014 * This has the ability to break the telephony implementation by disabling notification of
3015 * changes in device connectivity. DO NOT USE THIS!
3016 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003017 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003018 public void enableLocationUpdates() {
3019 mApp.enforceCallingOrSelfPermission(
3020 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 }
3022
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003023 /**
3024 * This method was removed due to potential issues caused by performing partial
3025 * updates of service state, and lack of a credible use case.
3026 *
3027 * This has the ability to break the telephony implementation by disabling notification of
3028 * changes in device connectivity. DO NOT USE THIS!
3029 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003030 @Override
3031 public void disableLocationUpdates() {
3032 mApp.enforceCallingOrSelfPermission(
3033 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003034 }
3035
3036 @Override
3037 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003038 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3039 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08003040 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003041 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3042 throw new SecurityException(
3043 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3044 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003045
Jordan Liu1617b712019-07-10 15:06:26 -07003046 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003047 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3048 return null;
3049 }
Svetoslav64fad262015-04-14 14:35:21 -07003050
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003051 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003053 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003054 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055
Nathan Haroldf180aac2018-06-01 18:43:55 -07003056 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3057 for (CellInfo ci : info) {
3058 if (ci instanceof CellInfoGsm) {
3059 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3060 } else if (ci instanceof CellInfoWcdma) {
3061 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3062 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003064 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003065 }
3066
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003067 private List<CellInfo> getCachedCellInfo() {
3068 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3069 for (Phone phone : PhoneFactory.getPhones()) {
3070 List<CellInfo> info = phone.getAllCellInfo();
3071 if (info != null) cellInfos.addAll(info);
3072 }
3073 return cellInfos;
3074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075
3076 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003077 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003078 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003079 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003080
3081 LocationAccessPolicy.LocationPermissionResult locationResult =
3082 LocationAccessPolicy.checkLocationPermission(mApp,
3083 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3084 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003085 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003086 .setCallingPid(Binder.getCallingPid())
3087 .setCallingUid(Binder.getCallingUid())
3088 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003089 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003090 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3091 .build());
3092 switch (locationResult) {
3093 case DENIED_HARD:
3094 throw new SecurityException("Not allowed to access cell info");
3095 case DENIED_SOFT:
3096 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 }
3098
Nathan Haroldf096d982020-11-18 17:18:06 -08003099 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003100 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3101 return getCachedCellInfo();
3102 }
3103
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003104 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003105 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3109 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003110 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003111 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112 if (info != null) cellInfos.addAll(info);
3113 }
3114 return cellInfos;
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 }
3118 }
3119
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003120 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003121 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3122 String callingFeatureId) {
3123 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3124 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003125 }
3126
3127 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003128 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3129 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003130 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003131 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003132 }
3133
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003134 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3135 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003136 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003137 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003138
3139 LocationAccessPolicy.LocationPermissionResult locationResult =
3140 LocationAccessPolicy.checkLocationPermission(mApp,
3141 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3142 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003143 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003144 .setCallingPid(Binder.getCallingPid())
3145 .setCallingUid(Binder.getCallingUid())
3146 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003147 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3148 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003149 .build());
3150 switch (locationResult) {
3151 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003152 if (TelephonyPermissions
3153 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003154 // Safetynet logging for b/154934934
3155 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3156 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003157 throw new SecurityException("Not allowed to access cell info");
3158 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003159 if (TelephonyPermissions
3160 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003161 // Safetynet logging for b/154934934
3162 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3163 }
Nathan Harold5320c422019-05-09 10:26:08 -07003164 try {
3165 cb.onCellInfo(new ArrayList<CellInfo>());
3166 } catch (RemoteException re) {
3167 // Drop without consequences
3168 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003169 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003170 }
3171
Nathan Harolda939a962019-05-09 10:13:47 -07003172
3173 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003174 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3175
3176 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3177 }
3178
3179 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003180 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003181 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003182 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183
3184 final long identity = Binder.clearCallingIdentity();
3185 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003186 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 }
3191
Shishir Agrawala9f32182016-04-12 12:00:16 -07003192 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003193 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003194 Phone phone = PhoneFactory.getPhone(slotIndex);
3195 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003196 return null;
3197 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003198 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003199 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003200 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003201 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003202 return null;
3203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204
3205 final long identity = Binder.clearCallingIdentity();
3206 try {
3207 return phone.getImei();
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
3210 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003211 }
3212
3213 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003214 public String getTypeAllocationCodeForSlot(int slotIndex) {
3215 Phone phone = PhoneFactory.getPhone(slotIndex);
3216 String tac = null;
3217 if (phone != null) {
3218 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003219 try {
3220 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3221 } catch (IndexOutOfBoundsException e) {
3222 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3223 return null;
3224 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003225 }
3226 return tac;
3227 }
3228
3229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003230 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003231 Phone phone = PhoneFactory.getPhone(slotIndex);
3232 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003233 return null;
3234 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003235
Jeff Davidson913390f2018-02-23 17:11:49 -08003236 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003237 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003238 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003239 return null;
3240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241
3242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 return phone.getMeid();
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
Jack Yu2af8d712017-03-15 17:14:14 -07003248 }
3249
3250 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003251 public String getManufacturerCodeForSlot(int slotIndex) {
3252 Phone phone = PhoneFactory.getPhone(slotIndex);
3253 String manufacturerCode = null;
3254 if (phone != null) {
3255 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003256 try {
3257 manufacturerCode =
3258 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3259 } catch (IndexOutOfBoundsException e) {
3260 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3261 return null;
3262 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003263 }
3264 return manufacturerCode;
3265 }
3266
3267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003268 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3269 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003270 Phone phone = PhoneFactory.getPhone(slotIndex);
3271 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003272 return null;
3273 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003274 int subId = phone.getSubId();
3275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003276 mApp, subId, callingPackage, callingFeatureId,
3277 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003278 return null;
3279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
3281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 return phone.getDeviceSvn();
3284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003287 }
3288
fionaxu43304da2017-11-27 22:51:16 -08003289 @Override
3290 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 final Phone phone = getPhone(subId);
3294 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3295 } finally {
3296 Binder.restoreCallingIdentity(identity);
3297 }
fionaxu43304da2017-11-27 22:51:16 -08003298 }
3299
3300 @Override
3301 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003302 final long identity = Binder.clearCallingIdentity();
3303 try {
3304 final Phone phone = getPhone(subId);
3305 return phone == null ? null : phone.getCarrierName();
3306 } finally {
3307 Binder.restoreCallingIdentity(identity);
3308 }
fionaxu43304da2017-11-27 22:51:16 -08003309 }
3310
calvinpanffe225e2018-11-01 19:43:06 +08003311 @Override
chen xu0026ca62019-03-06 15:28:50 -08003312 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 final Phone phone = getPhone(subId);
3316 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003317 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
3321 }
3322
3323 @Override
chen xu0026ca62019-03-06 15:28:50 -08003324 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003328 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003329 } finally {
3330 Binder.restoreCallingIdentity(identity);
3331 }
3332 }
3333
chen xu651eec72018-11-11 19:03:44 -08003334 @Override
chen xu864e11c2018-12-06 22:10:03 -08003335 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3336 if (!isSubscriptionMccMnc) {
3337 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3338 }
chen xu651eec72018-11-11 19:03:44 -08003339 final Phone phone = PhoneFactory.getPhone(slotIndex);
3340 if (phone == null) {
3341 return TelephonyManager.UNKNOWN_CARRIER_ID;
3342 }
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
3349 }
3350
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003351 //
3352 // Internal helper methods.
3353 //
3354
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003355 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003356 * Make sure the caller is the calling package itself
3357 *
3358 * @throws SecurityException if the caller is not the calling package
3359 */
3360 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3361 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003362 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3363 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003364 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003365 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003366 } catch (PackageManager.NameNotFoundException e) {
3367 // packageUid is -1
3368 }
3369 if (packageUid != callingUid) {
3370 throw new SecurityException(message + ": Package " + callingPackage
3371 + " does not belong to " + callingUid);
3372 }
3373 }
3374
3375 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003376 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3377 *
3378 * @throws SecurityException if the caller does not have the required permission
3379 */
3380 private void enforceModifyPermission() {
3381 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3382 }
3383
Shuo Qian3b6ee772019-11-13 17:43:31 -08003384 private void enforceActiveEmergencySessionPermission() {
3385 mApp.enforceCallingOrSelfPermission(
3386 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3387 }
3388
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 /**
3390 * Make sure the caller has the CALL_PHONE permission.
3391 *
3392 * @throws SecurityException if the caller does not have the required permission
3393 */
3394 private void enforceCallPermission() {
3395 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3396 }
3397
paulhu5a773602019-08-23 19:17:33 +08003398 private void enforceSettingsPermission() {
3399 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003400 }
3401
Michele Berionne5e411512020-11-13 02:36:59 +00003402 private void enforceRebootPermission() {
3403 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3404 }
3405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003406 private String createTelUrl(String number) {
3407 if (TextUtils.isEmpty(number)) {
3408 return null;
3409 }
3410
Jake Hambye994d462014-02-03 13:10:13 -08003411 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003412 }
3413
Ihab Awadf9e92732013-12-05 18:02:52 -08003414 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3416 }
3417
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003418 private static void logv(String msg) {
3419 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3420 }
3421
Ihab Awadf9e92732013-12-05 18:02:52 -08003422 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003423 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3424 }
3425
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003426 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003428 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003429 }
3430
Sanket Padawe356d7632015-06-22 14:03:32 -07003431 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003432 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003433 final long identity = Binder.clearCallingIdentity();
3434 try {
3435 final Phone phone = PhoneFactory.getPhone(slotIndex);
3436 if (phone == null) {
3437 return PhoneConstants.PHONE_TYPE_NONE;
3438 } else {
3439 return phone.getPhoneType();
3440 }
3441 } finally {
3442 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003444 }
3445
3446 /**
3447 * Returns the CDMA ERI icon index to display
3448 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003449 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003450 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3451 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3452 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003453 }
3454
Sanket Padawe356d7632015-06-22 14:03:32 -07003455 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003456 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3457 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003459 mApp, subId, callingPackage, callingFeatureId,
3460 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003461 return -1;
3462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463
3464 final long identity = Binder.clearCallingIdentity();
3465 try {
3466 final Phone phone = getPhone(subId);
3467 if (phone != null) {
3468 return phone.getCdmaEriIconIndex();
3469 } else {
3470 return -1;
3471 }
3472 } finally {
3473 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003475 }
3476
3477 /**
3478 * Returns the CDMA ERI icon mode,
3479 * 0 - ON
3480 * 1 - FLASHING
3481 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003482 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003483 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3484 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3485 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003486 }
3487
Sanket Padawe356d7632015-06-22 14:03:32 -07003488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003489 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3490 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003492 mApp, subId, callingPackage, callingFeatureId,
3493 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003494 return -1;
3495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496
3497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 final Phone phone = getPhone(subId);
3500 if (phone != null) {
3501 return phone.getCdmaEriIconMode();
3502 } else {
3503 return -1;
3504 }
3505 } finally {
3506 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 }
3509
3510 /**
3511 * Returns the CDMA ERI text,
3512 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003513 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003514 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3515 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3516 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003517 }
3518
Sanket Padawe356d7632015-06-22 14:03:32 -07003519 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003520 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3521 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003523 mApp, subId, callingPackage, callingFeatureId,
3524 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003525 return null;
3526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527
3528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 final Phone phone = getPhone(subId);
3531 if (phone != null) {
3532 return phone.getCdmaEriText();
3533 } else {
3534 return null;
3535 }
3536 } finally {
3537 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 }
3540
3541 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003542 * Returns the CDMA MDN.
3543 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003544 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003545 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3547 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003548
3549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003552 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003553 return phone.getLine1Number();
3554 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003555 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556 return null;
3557 }
3558 } finally {
3559 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003560 }
3561 }
3562
3563 /**
3564 * Returns the CDMA MIN.
3565 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003566 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003567 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3569 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003570
3571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 final Phone phone = getPhone(subId);
3574 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3575 return phone.getCdmaMin();
3576 } else {
3577 return null;
3578 }
3579 } finally {
3580 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003581 }
3582 }
3583
Hall Liud892bec2018-11-30 14:51:45 -08003584 @Override
3585 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3586 INumberVerificationCallback callback, String callingPackage) {
3587 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3588 != PERMISSION_GRANTED) {
3589 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3590 }
3591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3592
3593 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3594 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003595 throw new SecurityException("Calling package must be configured in the device config: "
3596 + "calling package: " + callingPackage
3597 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003598 }
3599
3600 if (range == null) {
3601 throw new NullPointerException("Range must be non-null");
3602 }
3603
3604 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003605 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003606
3607 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3608 }
3609
Junda Liuca05d5d2014-08-14 22:36:34 -07003610 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003611 * Returns true if CDMA provisioning needs to run.
3612 */
3613 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614 final long identity = Binder.clearCallingIdentity();
3615 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003616 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003617 } finally {
3618 Binder.restoreCallingIdentity(identity);
3619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003620 }
3621
3622 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003623 * Sets the voice mail number of a given subId.
3624 */
3625 @Override
3626 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003627 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3628 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629
3630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3633 new Pair<String, String>(alphaTag, number), new Integer(subId));
3634 return success;
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003638 }
3639
Ta-wei Yen87c49842016-05-13 21:19:52 -07003640 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003641 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3642 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003643 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3644 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003645 if (!TextUtils.equals(callingPackage, systemDialer)) {
3646 throw new SecurityException("caller must be system dialer");
3647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3652 if (phoneAccountHandle == null) {
3653 return null;
3654 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003655 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656 } finally {
3657 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003658 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003659 }
3660
3661 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003662 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3663 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003664 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003666 mApp, subId, callingPackage, callingFeatureId,
3667 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003668 return null;
3669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003670
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003671 final long identity = Binder.clearCallingIdentity();
3672 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003673 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003677 }
3678
3679 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003680 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3681 VisualVoicemailSmsFilterSettings settings) {
3682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003687 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003691 }
3692
3693 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003694 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003700 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003704 }
3705
3706 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003707 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3708 String callingPackage, int subId) {
3709 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710
3711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003714 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715 } finally {
3716 Binder.restoreCallingIdentity(identity);
3717 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003718 }
3719
3720 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003721 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003722 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003727 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728 } finally {
3729 Binder.restoreCallingIdentity(identity);
3730 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003731 }
3732
3733 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003734 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3735 String callingAttributionTag, int subId, String number, int port, String text,
3736 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003738 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003739 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003740 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003741 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3742 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003743 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003744
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003745 /**
fionaxu0152e512016-11-14 13:36:14 -08003746 * Sets the voice activation state of a given subId.
3747 */
3748 @Override
3749 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3751 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752
3753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 final Phone phone = getPhone(subId);
3756 if (phone != null) {
3757 phone.setVoiceActivationState(activationState);
3758 } else {
3759 loge("setVoiceActivationState fails with invalid subId: " + subId);
3760 }
3761 } finally {
3762 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003763 }
3764 }
3765
3766 /**
3767 * Sets the data activation state of a given subId.
3768 */
3769 @Override
3770 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3772 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003773
3774 final long identity = Binder.clearCallingIdentity();
3775 try {
3776 final Phone phone = getPhone(subId);
3777 if (phone != null) {
3778 phone.setDataActivationState(activationState);
3779 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003780 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781 }
3782 } finally {
3783 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003784 }
3785 }
3786
3787 /**
3788 * Returns the voice activation state of a given subId.
3789 */
3790 @Override
3791 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003792 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793
fionaxu0152e512016-11-14 13:36:14 -08003794 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 if (phone != null) {
3798 return phone.getVoiceActivationState();
3799 } else {
3800 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3801 }
3802 } finally {
3803 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003804 }
3805 }
3806
3807 /**
3808 * Returns the data activation state of a given subId.
3809 */
3810 @Override
3811 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003812 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813
fionaxu0152e512016-11-14 13:36:14 -08003814 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003815 final long identity = Binder.clearCallingIdentity();
3816 try {
3817 if (phone != null) {
3818 return phone.getDataActivationState();
3819 } else {
3820 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3821 }
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003824 }
3825 }
3826
3827 /**
Wink Saville36469e72014-06-11 15:17:00 -07003828 * Returns the unread count of voicemails for a subId
3829 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003830 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003831 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3832 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003834 mApp, subId, callingPackage, callingFeatureId,
3835 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003836 return 0;
3837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 final Phone phone = getPhone(subId);
3841 if (phone != null) {
3842 return phone.getVoiceMessageCount();
3843 } else {
3844 return 0;
3845 }
3846 } finally {
3847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003849 }
3850
3851 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003852 * returns true, if the device is in a state where both voice and data
3853 * are supported simultaneously. This can change based on location or network condition.
3854 */
3855 @Override
3856 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 final Phone phone = getPhone(subId);
3860 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3861 } finally {
3862 Binder.restoreCallingIdentity(identity);
3863 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003864 }
3865
3866 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003867 * Send the dialer code if called from the current default dialer or the caller has
3868 * carrier privilege.
3869 * @param inputCode The dialer code to send
3870 */
3871 @Override
3872 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003873 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003874 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003875 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3876 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003877 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003878 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003879 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003881
3882 final long identity = Binder.clearCallingIdentity();
3883 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003884 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885 } finally {
3886 Binder.restoreCallingIdentity(identity);
3887 }
fionaxu235cc5e2017-03-06 22:25:57 -08003888 }
3889
Pengquan Menga1bb6272018-09-06 09:59:22 -07003890 @Override
3891 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003892 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003893 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003894 mApp, subId, "getNetworkSelectionMode");
3895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 if (!isActiveSubscription(subId)) {
3898 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3899 }
3900 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003903 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003904 }
3905
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003907 public boolean isInEmergencySmsMode() {
3908 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3909 final long identity = Binder.clearCallingIdentity();
3910 try {
3911 for (Phone phone : PhoneFactory.getPhones()) {
3912 if (phone.isInEmergencySmsMode()) {
3913 return true;
3914 }
3915 }
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
3918 }
3919 return false;
3920 }
3921
shilu366312e2019-12-17 09:28:10 -08003922 /**
3923 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3924 * @param subId The subscription to use to check the configuration.
3925 * @param c The callback that will be used to send the result.
3926 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003927 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003928 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3929 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003930 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003931 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003932
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003933 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3934 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3935 "IMS not available on device.");
3936 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003937 final long token = Binder.clearCallingIdentity();
3938 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003939 int slotId = getSlotIndexOrException(subId);
3940 verifyImsMmTelConfiguredOrThrow(slotId);
3941 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003942 } catch (ImsException e) {
3943 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003944 } finally {
3945 Binder.restoreCallingIdentity(token);
3946 }
3947 }
3948
shilu366312e2019-12-17 09:28:10 -08003949 /**
3950 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3951 * @param subId The subscription to use to check the configuration.
3952 * @param c The callback that will be used to send the result.
3953 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003955 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003956 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003957 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003958 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3959 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3960 }
Meng Wangafbc5852019-09-19 17:37:13 -07003961 final long token = Binder.clearCallingIdentity();
3962 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003963 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3964 .removeRegistrationCallbackForSubscription(c, subId);
3965 } catch (ImsException e) {
3966 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3967 + "is inactive, ignoring unregister.");
3968 // If the subscription is no longer active, just return, since the callback
3969 // will already have been removed internally.
3970 } finally {
3971 Binder.restoreCallingIdentity(token);
3972 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 }
3974
Brad Ebingera34a6c22019-10-22 17:36:18 -07003975 /**
3976 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3977 */
3978 @Override
3979 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3980 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3981 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3982 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3983 "IMS not available on device.");
3984 }
3985 final long token = Binder.clearCallingIdentity();
3986 try {
3987 Phone phone = getPhone(subId);
3988 if (phone == null) {
3989 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3990 + subId + "'");
3991 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3992 }
3993 phone.getImsRegistrationState(regState -> {
3994 try {
3995 consumer.accept((regState == null)
3996 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3997 } catch (RemoteException e) {
3998 // Ignore if the remote process is no longer available to call back.
3999 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4000 }
4001 });
4002 } finally {
4003 Binder.restoreCallingIdentity(token);
4004 }
4005 }
4006
4007 /**
4008 * Get the transport type for the IMS service registration state.
4009 */
4010 @Override
4011 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004012 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004013 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004014 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4015 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4016 "IMS not available on device.");
4017 }
4018 final long token = Binder.clearCallingIdentity();
4019 try {
4020 Phone phone = getPhone(subId);
4021 if (phone == null) {
4022 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4023 + subId + "'");
4024 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4025 }
4026 phone.getImsRegistrationTech(regTech -> {
4027 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4028 int regTechConverted = (regTech == null)
4029 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4030 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4031 regTechConverted);
4032 try {
4033 consumer.accept(regTechConverted);
4034 } catch (RemoteException e) {
4035 // Ignore if the remote process is no longer available to call back.
4036 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4037 }
4038 });
4039 } finally {
4040 Binder.restoreCallingIdentity(token);
4041 }
4042 }
4043
shilu366312e2019-12-17 09:28:10 -08004044 /**
4045 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4046 * @param subId The subscription to use to check the configuration.
4047 * @param c The callback that will be used to send the result.
4048 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004050 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4051 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004052 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004053 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004054 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4055 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4056 "IMS not available on device.");
4057 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 final long token = Binder.clearCallingIdentity();
4059 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004060 int slotId = getSlotIndexOrException(subId);
4061 verifyImsMmTelConfiguredOrThrow(slotId);
4062 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004063 } catch (ImsException e) {
4064 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 } finally {
4066 Binder.restoreCallingIdentity(token);
4067 }
4068 }
4069
shilu366312e2019-12-17 09:28:10 -08004070 /**
4071 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4072 * @param subId The subscription to use to check the configuration.
4073 * @param c The callback that will be used to send the result.
4074 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004076 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004077 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004078 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004079 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4080 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4081 }
Meng Wangafbc5852019-09-19 17:37:13 -07004082
4083 final long token = Binder.clearCallingIdentity();
4084 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004085 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004086 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004087 } catch (ImsException e) {
4088 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4089 + "is inactive, ignoring unregister.");
4090 // If the subscription is no longer active, just return, since the callback
4091 // will already have been removed internally.
4092 } finally {
4093 Binder.restoreCallingIdentity(token);
4094 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004095 }
4096
4097 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004098 public boolean isCapable(int subId, int capability, int regTech) {
4099 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 final long token = Binder.clearCallingIdentity();
4101 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004102 int slotId = getSlotIndexOrException(subId);
4103 verifyImsMmTelConfiguredOrThrow(slotId);
4104 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004105 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4107 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004108 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004109 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4110 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 } finally {
4112 Binder.restoreCallingIdentity(token);
4113 }
4114 }
4115
4116 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004117 public boolean isAvailable(int subId, int capability, int regTech) {
4118 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 final long token = Binder.clearCallingIdentity();
4120 try {
4121 Phone phone = getPhone(subId);
4122 if (phone == null) return false;
4123 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004124 } catch (com.android.ims.ImsException e) {
4125 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4126 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 } finally {
4128 Binder.restoreCallingIdentity(token);
4129 }
4130 }
4131
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004132 /**
4133 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4134 * subscription.
4135 * @param subId The subscription to use to check the configuration.
4136 * @param callback The callback that will be used to send the result.
4137 * @param capability The MmTelFeature capability that will be used to send the result.
4138 * @param transportType The transport type of the MmTelFeature capability.
4139 */
4140 @Override
4141 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4142 int transportType) {
4143 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4144 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4145 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4146 "IMS not available on device.");
4147 }
4148 final long token = Binder.clearCallingIdentity();
4149 try {
4150 int slotId = getSlotIndex(subId);
4151 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4152 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4153 + subId + "'");
4154 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4155 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004156 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004157 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4158 transportType, aBoolean -> {
4159 try {
4160 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4161 } catch (RemoteException e) {
4162 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4163 + "running. Ignore");
4164 }
4165 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004168 } finally {
4169 Binder.restoreCallingIdentity(token);
4170 }
4171 }
4172
shilu366312e2019-12-17 09:28:10 -08004173 /**
4174 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4175 * @param subId The subscription to use to check the configuration.
4176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 @Override
4178 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004179 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004180 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004181
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 final long token = Binder.clearCallingIdentity();
4183 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004184 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004185 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004186 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004187 } catch (ImsException e) {
4188 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004189 } finally {
4190 Binder.restoreCallingIdentity(token);
4191 }
4192 }
4193
4194 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004195 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004197 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 final long identity = Binder.clearCallingIdentity();
4199 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004200 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004201 // This setting doesn't require an active ImsService connection, so do not verify. The
4202 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004203 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004204 } catch (ImsException e) {
4205 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 } finally {
4207 Binder.restoreCallingIdentity(identity);
4208 }
4209 }
4210
shilu366312e2019-12-17 09:28:10 -08004211 /**
4212 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4213 * @param subId The subscription to use to check the configuration.
4214 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004216 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004217 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004218 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 final long identity = Binder.clearCallingIdentity();
4220 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004221 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004222 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004223 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004224 } catch (ImsException e) {
4225 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004226 } finally {
4227 Binder.restoreCallingIdentity(identity);
4228 }
4229 }
4230
4231 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004232 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004234 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 final long identity = Binder.clearCallingIdentity();
4236 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004237 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004238 // This setting doesn't require an active ImsService connection, so do not verify. The
4239 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004240 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004241 } catch (ImsException e) {
4242 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 } finally {
4244 Binder.restoreCallingIdentity(identity);
4245 }
4246 }
4247
shilu366312e2019-12-17 09:28:10 -08004248 /**
4249 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4250 * @param subId The subscription to use to check the configuration.
4251 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 @Override
4253 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004254 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004255 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004256 final long identity = Binder.clearCallingIdentity();
4257 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004258 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004259 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004260 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004261 } catch (ImsException e) {
4262 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004263 } finally {
4264 Binder.restoreCallingIdentity(identity);
4265 }
4266 }
4267
4268 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004269 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004271 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 final long identity = Binder.clearCallingIdentity();
4273 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004274 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004275 // This setting doesn't require an active ImsService connection, so do not verify. The
4276 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004277 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004278 } catch (ImsException e) {
4279 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
4283 }
4284
shilu366312e2019-12-17 09:28:10 -08004285 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004286 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4288 * @param subId The subscription to use to check the configuration.
4289 */
4290 @Override
4291 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004292 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004293 mApp, subId, "isCrossSimCallingEnabledByUser");
4294 final long identity = Binder.clearCallingIdentity();
4295 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004297 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004299 } catch (ImsException e) {
4300 throw new ServiceSpecificException(e.getCode());
4301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
4304 }
4305
4306 /**
4307 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4308 * Requires MODIFY_PHONE_STATE permission.
4309 * @param subId The subscription to use to check the configuration.
4310 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4311 * false otherwise
4312 */
4313 @Override
4314 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4316 "setCrossSimCallingEnabled");
4317 final long identity = Binder.clearCallingIdentity();
4318 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004319 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004320 // This setting doesn't require an active ImsService connection, so do not verify. The
4321 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004322 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004323 } catch (ImsException e) {
4324 throw new ServiceSpecificException(e.getCode());
4325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
4328 }
4329
4330 /**
shilu366312e2019-12-17 09:28:10 -08004331 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4332 * @param subId The subscription to use to check the configuration.
4333 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004335
Brad Ebinger35c841c2018-10-01 10:40:55 -07004336 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004337 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004338 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 final long identity = Binder.clearCallingIdentity();
4340 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004341 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004342 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004343 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004344 } catch (ImsException e) {
4345 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
4349 }
4350
4351 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004352 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004354 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 final long identity = Binder.clearCallingIdentity();
4356 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004358 // This setting doesn't require an active ImsService connection, so do not verify. The
4359 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004361 } catch (ImsException e) {
4362 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004363 } finally {
4364 Binder.restoreCallingIdentity(identity);
4365 }
4366 }
4367
4368 @Override
4369 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4371 "setVoWiFiNonPersistent");
4372 final long identity = Binder.clearCallingIdentity();
4373 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004375 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004377 } catch (ImsException e) {
4378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
4382 }
4383
shilu366312e2019-12-17 09:28:10 -08004384 /**
4385 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4386 * @param subId The subscription to use to check the configuration.
4387 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004388 @Override
4389 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004390 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004391 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004392 final long identity = Binder.clearCallingIdentity();
4393 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004394 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004395 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004396 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004397 } catch (ImsException e) {
4398 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004399 } finally {
4400 Binder.restoreCallingIdentity(identity);
4401 }
4402 }
4403
4404 @Override
4405 public void setVoWiFiModeSetting(int subId, int mode) {
4406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4407 "setVoWiFiModeSetting");
4408 final long identity = Binder.clearCallingIdentity();
4409 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004410 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004411 // This setting doesn't require an active ImsService connection, so do not verify. The
4412 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004413 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004414 } catch (ImsException e) {
4415 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004416 } finally {
4417 Binder.restoreCallingIdentity(identity);
4418 }
4419 }
4420
4421 @Override
4422 public int getVoWiFiRoamingModeSetting(int subId) {
4423 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4424 final long identity = Binder.clearCallingIdentity();
4425 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004426 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004427 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004428 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004429 } catch (ImsException e) {
4430 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 } finally {
4432 Binder.restoreCallingIdentity(identity);
4433 }
4434 }
4435
4436 @Override
4437 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4439 "setVoWiFiRoamingModeSetting");
4440 final long identity = Binder.clearCallingIdentity();
4441 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004443 // This setting doesn't require an active ImsService connection, so do not verify. The
4444 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004446 } catch (ImsException e) {
4447 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
4451 }
4452
4453 @Override
4454 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4456 "setRttCapabilityEnabled");
4457 final long identity = Binder.clearCallingIdentity();
4458 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004460 // This setting doesn't require an active ImsService connection, so do not verify. The
4461 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004462 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004463 } catch (ImsException e) {
4464 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
4468 }
4469
shilu366312e2019-12-17 09:28:10 -08004470 /**
4471 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4472 * @param subId The subscription to use to check the configuration.
4473 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004474 @Override
4475 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004476 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004477 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004478 final long identity = Binder.clearCallingIdentity();
4479 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004481 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004482 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004483 } catch (ImsException e) {
4484 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
4488 }
4489
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004490 @Override
4491 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4492 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4493 final long identity = Binder.clearCallingIdentity();
4494 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004495 if (!isImsAvailableOnDevice()) {
4496 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4497 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004498 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004499 int slotId = getSlotIndexOrException(subId);
4500 verifyImsMmTelConfiguredOrThrow(slotId);
4501 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004502 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004503 } catch (ImsException e) {
4504 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
4508 }
4509
4510 @Override
4511 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4512 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4513 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004514 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4515 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4516 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004517 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004518 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004519 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004520 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004521 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4522 + "is inactive, ignoring unregister.");
4523 // If the subscription is no longer active, just return, since the callback will already
4524 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004525 } finally {
4526 Binder.restoreCallingIdentity(identity);
4527 }
4528 }
4529
allenwtsu99c623b2020-01-03 18:24:23 +08004530
4531 private void checkModifyPhoneStatePermission(int subId, String message) {
4532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4533 message);
4534 }
4535
4536 private boolean isImsProvisioningRequired(int subId, int capability,
4537 boolean isMmtelCapability) {
4538 Phone phone = getPhone(subId);
4539 if (phone == null) {
4540 loge("phone instance null for subid " + subId);
4541 return false;
4542 }
4543 if (isMmtelCapability) {
4544 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4545 return false;
4546 }
4547 } else {
4548 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4549 return false;
4550 }
4551 }
4552 return true;
4553 }
4554
4555 @Override
4556 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4557 boolean isProvisioned) {
4558 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4559
4560 final long identity = Binder.clearCallingIdentity();
4561 try {
4562 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4563 if (!isImsProvisioningRequired(subId, capability, false)) {
4564 return;
4565 }
4566
4567 // this capability requires provisioning, route to the correct API.
4568 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4569 switch (capability) {
4570 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4571 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4572 ims.setEabProvisioned(isProvisioned);
4573 break;
4574 default: {
4575 throw new IllegalArgumentException("Tried to set provisioning for "
4576 + "rcs capability '" + capability + "', which does not require "
4577 + "provisioning.");
4578 }
4579 }
4580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
4583
4584 }
4585
4586
4587 @Override
4588 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4589 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4593 if (!isImsProvisioningRequired(subId, capability, false)) {
4594 return true;
4595 }
4596
4597 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4598 switch (capability) {
4599 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4600 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4601 return ims.isEabProvisionedOnDevice();
4602
4603 default: {
4604 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4605 + "capability '" + capability + "', which does not require "
4606 + "provisioning.");
4607 }
4608 }
4609
4610 } finally {
4611 Binder.restoreCallingIdentity(identity);
4612 }
4613 }
4614
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004615 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004616 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4617 boolean isProvisioned) {
4618 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004619 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4620 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4621 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004622 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4623 }
allenwtsu99c623b2020-01-03 18:24:23 +08004624 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004625 final long identity = Binder.clearCallingIdentity();
4626 try {
4627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004628 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004629 return;
4630 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004631 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4632 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4633 loge("setImsProvisioningStatusForCapability: called for technology that does "
4634 + "not support provisioning - " + tech);
4635 return;
4636 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004637
4638 // this capability requires provisioning, route to the correct API.
4639 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4640 switch (capability) {
4641 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4642 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4643 ims.setVolteProvisioned(isProvisioned);
4644 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4645 ims.setWfcProvisioned(isProvisioned);
4646 }
4647 break;
4648 }
4649 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4650 // There is currently no difference in VT provisioning type.
4651 ims.setVtProvisioned(isProvisioned);
4652 break;
4653 }
4654 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4655 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4656 // change the capability of the feature instead if needed.
4657 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4658 == isProvisioned) {
4659 // No change in provisioning.
4660 return;
4661 }
4662 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4663 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004664 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004665 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004666 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4667 + ", Exception" + e.getMessage());
4668 }
4669 break;
4670 }
4671 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004672 throw new IllegalArgumentException("Tried to set provisioning for "
4673 + "MmTel capability '" + capability + "', which does not require "
4674 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675 }
4676 }
4677
4678 } finally {
4679 Binder.restoreCallingIdentity(identity);
4680 }
4681 }
4682
4683 @Override
4684 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4685 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004686 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4687 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4688 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004689 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4690 }
4691 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4692 final long identity = Binder.clearCallingIdentity();
4693 try {
4694 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004695 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004696 return true;
4697 }
4698
Brad Ebinger0d79c572021-04-17 15:20:49 -07004699 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4700 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4701 loge("getImsProvisioningStatusForCapability: called for technology that does "
4702 + "not support provisioning - " + tech);
4703 return true;
4704 }
4705
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004706 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4707 switch (capability) {
4708 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4709 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4710 return ims.isVolteProvisionedOnDevice();
4711 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4712 return ims.isWfcProvisionedOnDevice();
4713 }
4714 // This should never happen, since we are checking tech above to make sure it
4715 // is either LTE or IWLAN.
4716 throw new IllegalArgumentException("Invalid radio technology for voice "
4717 + "capability.");
4718 }
4719 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4720 // There is currently no difference in VT provisioning type.
4721 return ims.isVtProvisionedOnDevice();
4722 }
4723 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4724 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4725 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4726 }
4727 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004728 throw new IllegalArgumentException(
4729 "Tried to get provisioning for MmTel capability '" + capability
4730 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004731 }
4732 }
4733
4734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
4737 }
4738
4739 @Override
4740 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4741 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4742 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4743 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4744 }
4745 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4746 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4747 return (provisionedBits & capability) > 0;
4748 }
4749
4750 @Override
4751 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4752 boolean isProvisioned) {
4753 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4754 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4755 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4756 }
4757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4758 "setProvisioningStatusForCapability");
4759 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4760 // If the current provisioning status for capability already matches isProvisioned,
4761 // do nothing.
4762 if (((provisionedBits & capability) > 0) == isProvisioned) {
4763 return;
4764 }
4765 if (isProvisioned) {
4766 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4767 } else {
4768 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4769 }
4770 }
4771
4772 /**
4773 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4774 * technology. The bitfield should mirror the bitfield defined by
4775 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4776 */
4777 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4778 String key = getMmTelProvisioningKey(subId, tech);
4779 // Default is no capabilities are provisioned.
4780 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4781 }
4782
4783 /**
4784 * Sets the MmTel capability provisioning bitfield (defined by
4785 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4786 * technology specified.
4787 *
4788 * Note: This is a synchronous command and should not be called on UI thread.
4789 */
4790 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4791 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4792 String key = getMmTelProvisioningKey(subId, tech);
4793 editor.putInt(key, newField);
4794 editor.commit();
4795 }
4796
4797 private static String getMmTelProvisioningKey(int subId, int tech) {
4798 // resulting key is provision_ims_mmtel_{subId}_{tech}
4799 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4800 }
4801
4802 /**
4803 * Query CarrierConfig to see if the specified capability requires provisioning for the
4804 * carrier associated with the subscription id.
4805 */
4806 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4807 int capability) {
4808 CarrierConfigManager configManager = new CarrierConfigManager(context);
4809 PersistableBundle c = configManager.getConfigForSubId(subId);
4810 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004811 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004812 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4813 false);
4814 boolean requireVoiceVtProvisioning = c.getBoolean(
4815 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4816
4817 // First check to make sure that the capability requires provisioning.
4818 switch (capability) {
4819 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4820 // intentional fallthrough
4821 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4822 if (requireVoiceVtProvisioning) {
4823 // Voice and Video requires provisioning
4824 return true;
4825 }
4826 break;
4827 }
4828 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4829 if (requireUtProvisioning) {
4830 // UT requires provisioning
4831 return true;
4832 }
4833 break;
4834 }
4835 }
4836 return false;
4837 }
4838
allenwtsu99c623b2020-01-03 18:24:23 +08004839 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4840 int capability) {
4841 CarrierConfigManager configManager = new CarrierConfigManager(context);
4842 PersistableBundle c = configManager.getConfigForSubId(subId);
4843
4844 boolean requireRcsProvisioning = c.getBoolean(
4845 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4846
4847 // First check to make sure that the capability requires provisioning.
4848 switch (capability) {
4849 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4850 // intentional fallthrough
4851 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4852 if (requireRcsProvisioning) {
4853 // OPTION or PRESENCE requires provisioning
4854 return true;
4855 }
4856 break;
4857 }
4858 }
4859 return false;
4860 }
4861
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004862 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004863 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004864 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4865 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4866 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004867 enforceReadPrivilegedPermission("getImsProvisioningInt");
4868 final long identity = Binder.clearCallingIdentity();
4869 try {
4870 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004871 int slotId = getSlotIndex(subId);
4872 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4873 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4874 + subId + "' for key:" + key);
4875 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4876 }
calvinpanb5a34062021-02-08 19:59:36 +08004877 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004878 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004879 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4880 + subId + "' for key:" + key);
4881 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886
4887 @Override
4888 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4890 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4891 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004892 enforceReadPrivilegedPermission("getImsProvisioningString");
4893 final long identity = Binder.clearCallingIdentity();
4894 try {
4895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004896 int slotId = getSlotIndex(subId);
4897 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4898 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4899 + subId + "' for key:" + key);
4900 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4901 }
calvinpanb5a34062021-02-08 19:59:36 +08004902 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004903 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004904 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4905 + subId + "' for key:" + key);
4906 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
4910 }
4911
4912 @Override
4913 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004914 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4915 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4916 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4918 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004919 final long identity = Binder.clearCallingIdentity();
4920 try {
4921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004922 int slotId = getSlotIndex(subId);
4923 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4924 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4925 + subId + "' for key:" + key);
4926 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4927 }
calvinpanb5a34062021-02-08 19:59:36 +08004928 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4929 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004930 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004931 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004932 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
4936 }
4937
4938 @Override
4939 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004940 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4941 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4942 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4944 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004948 int slotId = getSlotIndex(subId);
4949 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4950 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4951 + subId + "' for key:" + key);
4952 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4953 }
calvinpanb5a34062021-02-08 19:59:36 +08004954 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4955 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004956 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004957 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004958 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
4962 }
4963
Brad Ebinger919631e2021-06-02 17:46:35 -07004964 /**
4965 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4966 * for the given slot ID or no ImsResolver instance has been created.
4967 * @param slotId The slot ID that the IMS service is created for.
4968 * @throws ImsException If there is no ImsService configured for this slot.
4969 */
4970 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4971 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4972 ImsFeature.FEATURE_MMTEL)) {
4973 throw new ImsException("This subscription does not support MMTEL over IMS",
4974 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4975 }
4976 }
4977
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004978 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004979 int slotId = SubscriptionManager.getSlotIndex(subId);
4980 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004981 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4982 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004983 }
4984 return slotId;
4985 }
4986
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004987 private int getSlotIndex(int subId) {
4988 int slotId = SubscriptionManager.getSlotIndex(subId);
4989 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4990 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4991 }
4992 return slotId;
4993 }
4994
Wink Saville36469e72014-06-11 15:17:00 -07004995 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004996 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004997 */
4998 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004999 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5000 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08005001 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005002 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005003 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005004 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005005 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005006 mApp, subId, callingPackage, callingFeatureId,
5007 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005008 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5009 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 final long identity = Binder.clearCallingIdentity();
5012 try {
5013 final Phone phone = getPhone(subId);
5014 if (phone != null) {
5015 return phone.getServiceState().getDataNetworkType();
5016 } else {
5017 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5018 }
5019 } finally {
5020 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005021 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005022 }
5023
5024 /**
5025 * Returns the data network type
5026 */
5027 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005028 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005029 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5030 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005031 }
5032
5033 /**
5034 * Returns the data network type for a subId
5035 */
5036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005037 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5038 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005040 mApp, subId, callingPackage, callingFeatureId,
5041 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005042 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5043 }
5044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 final long identity = Binder.clearCallingIdentity();
5046 try {
5047 final Phone phone = getPhone(subId);
5048 if (phone != null) {
5049 return phone.getServiceState().getDataNetworkType();
5050 } else {
5051 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5052 }
5053 } finally {
5054 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005055 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005056 }
5057
5058 /**
Wink Saville36469e72014-06-11 15:17:00 -07005059 * Returns the Voice network type for a subId
5060 */
5061 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005062 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5063 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005065 mApp, subId, callingPackage, callingFeatureId,
5066 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005067 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5068 }
5069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 final Phone phone = getPhone(subId);
5073 if (phone != null) {
5074 return phone.getServiceState().getVoiceNetworkType();
5075 } else {
5076 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5077 }
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005081 }
5082
5083 /**
5084 * @return true if a ICC card is present
5085 */
5086 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005087 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005088 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5089 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005090 }
5091
5092 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005093 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005094 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005095 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005096 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 final long identity = Binder.clearCallingIdentity();
5098 try {
5099 final Phone phone = PhoneFactory.getPhone(slotIndex);
5100 if (phone != null) {
5101 return phone.getIccCard().hasIccCard();
5102 } else {
5103 return false;
5104 }
5105 } finally {
5106 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005108 }
5109
5110 /**
5111 * Return if the current radio is LTE on CDMA. This
5112 * is a tri-state return value as for a period of time
5113 * the mode may be unknown.
5114 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005115 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005116 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005117 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005118 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005119 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005120 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5121 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5122 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005123 }
5124
Sanket Padawe356d7632015-06-22 14:03:32 -07005125 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005126 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5127 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005128 try {
5129 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5130 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005131 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5132 }
5133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 final long identity = Binder.clearCallingIdentity();
5135 try {
5136 final Phone phone = getPhone(subId);
5137 if (phone == null) {
5138 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5139 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005140 return TelephonyProperties.lte_on_cdma_device()
5141 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 }
5143 } finally {
5144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005145 }
Wink Saville36469e72014-06-11 15:17:00 -07005146 }
5147
Wink Saville36469e72014-06-11 15:17:00 -07005148 /**
5149 * {@hide}
5150 * Returns Default subId, 0 in the case of single standby.
5151 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005152 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005153 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005154 }
5155
Shishir Agrawala9f32182016-04-12 12:00:16 -07005156 private int getSlotForDefaultSubscription() {
5157 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5158 }
5159
Wink Savilleb564aae2014-10-23 10:18:09 -07005160 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005161 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005162 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005163
Pengquan Menge92a50d2018-09-21 15:54:48 -07005164 private boolean isActiveSubscription(int subId) {
5165 return mSubscriptionController.isActiveSubId(subId);
5166 }
5167
Ihab Awadf2177b72013-11-25 13:33:23 -08005168 /**
5169 * @see android.telephony.TelephonyManager.WifiCallingChoices
5170 */
5171 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 final long identity = Binder.clearCallingIdentity();
5173 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005174 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5176 getWhenToMakeWifiCallsDefaultPreference());
5177 } finally {
5178 Binder.restoreCallingIdentity(identity);
5179 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005180 }
5181
5182 /**
5183 * @see android.telephony.TelephonyManager.WifiCallingChoices
5184 */
5185 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 final long identity = Binder.clearCallingIdentity();
5187 try {
5188 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005189 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005194 }
5195
Sailesh Nepald1e68152013-12-12 19:08:02 -08005196 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005197 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005198 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005199 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005200
Jordan Liu4c733742019-02-28 12:03:40 -08005201 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5202 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5203 if (phoneId == -1) {
5204 throw new IllegalArgumentException("Given slot index: " + slotIndex
5205 + " does not correspond to an active phone");
5206 }
5207 return PhoneFactory.getPhone(phoneId);
5208 }
5209
Shishir Agrawal566b7612013-10-28 14:41:00 -07005210 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005211 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5212 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5214 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005216 if (DBG) {
5217 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5218 }
5219 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5220 p2);
5221 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005222
Jordan Liu4c733742019-02-28 12:03:40 -08005223
5224 @Override
5225 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5226 int slotIndex, String callingPackage, String aid, int p2) {
5227 enforceModifyPermission();
5228 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5229 if (DBG) {
5230 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5231 }
5232 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5233 callingPackage, aid, p2);
5234 }
5235
5236 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5237 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 final long identity = Binder.clearCallingIdentity();
5239 try {
5240 if (TextUtils.equals(ISDR_AID, aid)) {
5241 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005242 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5243 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 if (bestComponent == null
5245 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5246 loge("The calling package is not allowed to access ISD-R.");
5247 throw new SecurityException(
5248 "The calling package is not allowed to access ISD-R.");
5249 }
Derek Tan740e1672017-06-27 14:56:27 -07005250 }
Derek Tan740e1672017-06-27 14:56:27 -07005251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005253 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5254 null /* workSource */);
5255 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 return response;
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005260 }
5261
5262 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005263 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5265 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005266 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5267 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5268 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005269
Jordan Liu4c733742019-02-28 12:03:40 -08005270 @Override
5271 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5272 enforceModifyPermission();
5273 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5274 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5275 channel);
5276 }
5277
5278 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 final long identity = Binder.clearCallingIdentity();
5280 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 if (channel < 0) {
5282 return false;
5283 }
Jordan Liu4c733742019-02-28 12:03:40 -08005284 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5285 null /* workSource */);
5286 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 return success;
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005290 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005291 }
5292
5293 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005294 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005295 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5297 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005298 if (DBG) {
5299 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5300 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5301 + p3 + " data=" + data);
5302 }
5303 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5304 command, p1, p2, p3, data);
5305 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005306
Jordan Liu4c733742019-02-28 12:03:40 -08005307 @Override
5308 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5309 int command, int p1, int p2, int p3, String data) {
5310 enforceModifyPermission();
5311 if (DBG) {
5312 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5313 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5314 + p3 + " data=" + data);
5315 }
5316 return iccTransmitApduLogicalChannelWithPermission(
5317 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5318 data);
5319 }
5320
5321 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5322 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 final long identity = Binder.clearCallingIdentity();
5324 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005325 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 return "";
5327 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005330 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5331 null /* workSource */);
5332 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 // Append the returned status code to the end of the response payload.
5335 String s = Integer.toHexString(
5336 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5337 if (response.payload != null) {
5338 s = IccUtils.bytesToHexString(response.payload) + s;
5339 }
5340 return s;
5341 } finally {
5342 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005343 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005344 }
Jake Hambye994d462014-02-03 13:10:13 -08005345
Evan Charltonc66da362014-05-16 14:06:40 -07005346 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005347 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5348 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5350 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005352 if (DBG) {
5353 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5354 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5355 }
5356 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5357 cla, command, p1, p2, p3, data);
5358 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005359
Jordan Liu4c733742019-02-28 12:03:40 -08005360 @Override
5361 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5362 int command, int p1, int p2, int p3, String data) {
5363 enforceModifyPermission();
5364 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5365 if (DBG) {
5366 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5367 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5368 + " data=" + data);
5369 }
5370
5371 return iccTransmitApduBasicChannelWithPermission(
5372 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5373 p2, p3, data);
5374 }
5375
5376 // open APDU basic channel assuming the caller has sufficient permissions
5377 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5378 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5382 && TextUtils.equals(ISDR_AID, data)) {
5383 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005384 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5385 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 if (bestComponent == null
5387 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5388 loge("The calling package is not allowed to select ISD-R.");
5389 throw new SecurityException(
5390 "The calling package is not allowed to select ISD-R.");
5391 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005392 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005395 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5396 null /* workSource */);
5397 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 // Append the returned status code to the end of the response payload.
5400 String s = Integer.toHexString(
5401 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5402 if (response.payload != null) {
5403 s = IccUtils.bytesToHexString(response.payload) + s;
5404 }
5405 return s;
5406 } finally {
5407 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005408 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005409 }
5410
5411 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005412 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005413 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5415 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 final long identity = Binder.clearCallingIdentity();
5418 try {
5419 if (DBG) {
5420 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5421 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5422 }
5423
5424 IccIoResult response =
5425 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5426 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5427 subId);
5428
5429 if (DBG) {
5430 log("Exchange SIM_IO [R]" + response);
5431 }
5432
5433 byte[] result = null;
5434 int length = 2;
5435 if (response.payload != null) {
5436 length = 2 + response.payload.length;
5437 result = new byte[length];
5438 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5439 } else {
5440 result = new byte[length];
5441 }
5442
5443 result[length - 1] = (byte) response.sw2;
5444 result[length - 2] = (byte) response.sw1;
5445 return result;
5446 } finally {
5447 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005448 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005449 }
5450
Nathan Haroldb3014052017-01-25 15:57:32 -08005451 /**
5452 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5453 * on a particular subscription
5454 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005455 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5456 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005458 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005459 return null;
5460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461
5462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 if (appType != TelephonyManager.APPTYPE_USIM
5465 && appType != TelephonyManager.APPTYPE_SIM) {
5466 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5467 return null;
5468 }
5469 Object response = sendRequest(
5470 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5471 if (response instanceof String[]) {
5472 return (String[]) response;
5473 }
yincheng zhao2737e882019-09-06 17:06:54 -07005474 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005476 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 } finally {
5478 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005479 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005480 }
5481
yincheng zhao2737e882019-09-06 17:06:54 -07005482 /**
5483 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5484 * subscription.
5485 *
5486 * @param subId the id of the subscription.
5487 * @param appType the uicc app type, must be USIM or SIM.
5488 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5489 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005490 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005491 * @return number of fplmns that is successfully written to the SIM.
5492 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005493 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5494 String callingFeatureId) {
5495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5496 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005497 if (DBG) logv("no permissions for setForbiddenplmns");
5498 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5499 }
5500 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5501 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5502 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5503 }
5504 if (fplmns == null) {
5505 throw new IllegalArgumentException("Fplmn List provided is null");
5506 }
5507 for (String fplmn : fplmns) {
5508 if (!CellIdentity.isValidPlmn(fplmn)) {
5509 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5510 }
5511 }
5512 final long identity = Binder.clearCallingIdentity();
5513 try {
5514 Object response = sendRequest(
5515 CMD_SET_FORBIDDEN_PLMNS,
5516 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5517 subId);
5518 return (int) response;
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
5521 }
5522 }
5523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005524 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005525 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5527 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 final long identity = Binder.clearCallingIdentity();
5530 try {
5531 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5532 if (response.payload == null) {
5533 return "";
5534 }
Evan Charltonc66da362014-05-16 14:06:40 -07005535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 // Append the returned status code to the end of the response payload.
5537 String s = Integer.toHexString(
5538 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5539 s = IccUtils.bytesToHexString(response.payload) + s;
5540 return s;
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
Evan Charltonc66da362014-05-16 14:06:40 -07005544 }
5545
Jake Hambye994d462014-02-03 13:10:13 -08005546 /**
5547 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5548 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5549 *
5550 * @param itemID the ID of the item to read
5551 * @return the NV item as a String, or null on error.
5552 */
5553 @Override
5554 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005555 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5557 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558
5559 final long identity = Binder.clearCallingIdentity();
5560 try {
5561 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005562 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5564 return value;
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
Jake Hambye994d462014-02-03 13:10:13 -08005568 }
5569
5570 /**
5571 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5572 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5573 *
5574 * @param itemID the ID of the item to read
5575 * @param itemValue the value to write, as a String
5576 * @return true on success; false on any failure
5577 */
5578 @Override
5579 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005580 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5582 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583
5584 final long identity = Binder.clearCallingIdentity();
5585 try {
5586 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5587 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005588 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5590 return success;
5591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
Jake Hambye994d462014-02-03 13:10:13 -08005594 }
5595
5596 /**
5597 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5598 * Used for device configuration by some CDMA operators.
5599 *
5600 * @param preferredRoamingList byte array containing the new PRL
5601 * @return true on success; false on any failure
5602 */
5603 @Override
5604 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5606 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607
5608 final long identity = Binder.clearCallingIdentity();
5609 try {
5610 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5611 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5612 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5613 return success;
5614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
Jake Hambye994d462014-02-03 13:10:13 -08005617 }
5618
5619 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005620 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005621 * Used for device configuration by some CDMA operators.
5622 *
chen xu6dac5ab2018-10-26 17:39:23 -07005623 * @param slotIndex - device slot.
5624 *
Jake Hambye994d462014-02-03 13:10:13 -08005625 * @return true on success; false on any failure
5626 */
5627 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005628 public boolean resetModemConfig(int slotIndex) {
5629 Phone phone = PhoneFactory.getPhone(slotIndex);
5630 if (phone != null) {
5631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5632 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633
chen xu6dac5ab2018-10-26 17:39:23 -07005634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5637 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5638 return success;
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 }
chen xu6dac5ab2018-10-26 17:39:23 -07005643 return false;
5644 }
5645
5646 /**
5647 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5648 *
5649 * @param slotIndex - device slot.
5650 *
5651 * @return true on success; false on any failure
5652 */
5653 @Override
5654 public boolean rebootModem(int slotIndex) {
5655 Phone phone = PhoneFactory.getPhone(slotIndex);
5656 if (phone != null) {
5657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5658 mApp, phone.getSubId(), "rebootModem");
5659
5660 final long identity = Binder.clearCallingIdentity();
5661 try {
5662 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5663 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5664 return success;
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
5668 }
5669 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005670 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005671
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005672 public String[] getPcscfAddress(String apnType, String callingPackage,
5673 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005674 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5676 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005677 return new String[0];
5678 }
5679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 final long identity = Binder.clearCallingIdentity();
5681 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005682 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Wink Saville36469e72014-06-11 15:17:00 -07005686 }
5687
Brad Ebinger51f743a2017-01-23 13:50:20 -08005688 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005689 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5690 * {@link #disableIms(int)}.
5691 * @param slotIndex device slot.
5692 */
5693 public void resetIms(int slotIndex) {
5694 enforceModifyPermission();
5695
5696 final long identity = Binder.clearCallingIdentity();
5697 try {
5698 if (mImsResolver == null) {
5699 // may happen if the does not support IMS.
5700 return;
5701 }
5702 mImsResolver.disableIms(slotIndex);
5703 mImsResolver.enableIms(slotIndex);
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
5707 }
5708
5709 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005710 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5711 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005712 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005713 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005718 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005719 // may happen if the device does not support IMS.
5720 return;
5721 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005722 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005726 }
5727
5728 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005729 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5730 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005731 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005732 public void disableIms(int slotId) {
5733 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005737 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005738 // may happen if the device does not support IMS.
5739 return;
5740 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005741 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005745 }
5746
5747 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005748 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5749 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005750 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005751 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005752 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005757 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005758 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5759 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005760 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005761 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005765 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005766 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005767 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5768 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005769 @Override
5770 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005771 enforceModifyPermission();
5772
5773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005776 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005777 } finally {
5778 Binder.restoreCallingIdentity(identity);
5779 }
5780 }
5781
5782 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005783 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005784 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005785 */
5786 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5787 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788
5789 final long identity = Binder.clearCallingIdentity();
5790 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005791 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005792 // may happen if the device does not support IMS.
5793 return null;
5794 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005795 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 } finally {
5797 Binder.restoreCallingIdentity(identity);
5798 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005799 }
5800
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005801 /**
5802 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005803 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005804 */
5805 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5806 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005810 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005811 // may happen if the device does not support IMS.
5812 return null;
5813 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005814 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005818 }
5819
Brad Ebinger884c07b2018-02-15 16:17:40 -08005820 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005821 * Sets the ImsService Package Name that Telephony will bind to.
5822 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005823 * @param slotIndex the slot ID that the ImsService should bind for.
5824 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005825 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 * @param featureTypes An integer array of feature types associated with a packageName.
5827 * @param packageName The name of the package that the current configuration will be replaced
5828 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005829 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005830 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005831 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5832 int[] featureTypes, String packageName) {
5833 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5836 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005837 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 final long identity = Binder.clearCallingIdentity();
5840 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005841 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005842 // may happen if the device does not support IMS.
5843 return false;
5844 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 Map<Integer, String> featureConfig = new HashMap<>();
5846 for (int featureType : featureTypes) {
5847 featureConfig.put(featureType, packageName);
5848 }
5849 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5850 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 } finally {
5852 Binder.restoreCallingIdentity(identity);
5853 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005854 }
5855
5856 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005857 * Clears any carrier ImsService overrides for the slot index specified that were previously
5858 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5859 *
5860 * This should only be used for testing.
5861 *
5862 * @param slotIndex the slot ID that the ImsService should bind for.
5863 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5864 */
5865 @Override
5866 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5867 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5868 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5869 "clearCarrierImsServiceOverride");
5870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5871 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5872 "clearCarrierImsServiceOverride");
5873
5874 final long identity = Binder.clearCallingIdentity();
5875 try {
5876 if (mImsResolver == null) {
5877 // may happen if the device does not support IMS.
5878 return false;
5879 }
5880 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
5884 }
5885
5886 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005887 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005888 *
5889 * @param slotId The slot that the ImsService is associated with.
5890 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5891 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005892 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005893 * @return the package name of the ImsService configuration.
5894 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005895 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5896 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005897 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005899 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005900 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5901 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 final long identity = Binder.clearCallingIdentity();
5904 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005905 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005906 // may happen if the device does not support IMS.
5907 return "";
5908 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005909 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005910 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5911 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 } finally {
5913 Binder.restoreCallingIdentity(identity);
5914 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005915 }
5916
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005917 /**
5918 * Get the MmTelFeature state associated with the requested subscription id.
5919 * @param subId The subscription that the MmTelFeature is associated with.
5920 * @param callback A callback with an integer containing the
5921 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5922 */
5923 @Override
5924 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5925 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5926 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5927 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5928 "IMS not available on device.");
5929 }
5930 final long token = Binder.clearCallingIdentity();
5931 try {
5932 int slotId = getSlotIndex(subId);
5933 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5934 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5935 + subId + "'");
5936 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5937 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005938 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005939 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5940 try {
5941 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5942 } catch (RemoteException e) {
5943 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5944 + "Ignore");
5945 }
5946 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005947 } catch (ImsException e) {
5948 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005949 } finally {
5950 Binder.restoreCallingIdentity(token);
5951 }
5952 }
5953
Daniel Brightbb5840b2021-01-12 15:48:18 -08005954 /**
5955 * Sets the ims registration state on all valid {@link Phone}s.
5956 */
5957 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005958 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959
5960 final long identity = Binder.clearCallingIdentity();
5961 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005962 // NOTE: Before S, this method only set the default phone.
5963 for (final Phone phone : PhoneFactory.getPhones()) {
5964 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5965 phone.setImsRegistrationState(registered);
5966 }
5967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 } finally {
5969 Binder.restoreCallingIdentity(identity);
5970 }
Wink Saville36469e72014-06-11 15:17:00 -07005971 }
5972
5973 /**
Stuart Scott54788802015-03-30 13:18:01 -07005974 * Set the network selection mode to automatic.
5975 *
5976 */
5977 @Override
5978 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5980 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981
5982 final long identity = Binder.clearCallingIdentity();
5983 try {
shilufc958392020-01-20 11:36:01 -08005984 if (!isActiveSubscription(subId)) {
5985 return;
5986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005988 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5989 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 } finally {
5991 Binder.restoreCallingIdentity(identity);
5992 }
Stuart Scott54788802015-03-30 13:18:01 -07005993 }
5994
Jack Yud10cdd42020-09-28 20:28:01 -07005995 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005996 * Ask the radio to connect to the input network and change selection mode to manual.
5997 *
5998 * @param subId the id of the subscription.
5999 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6000 * the operator to attach to.
6001 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6002 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6003 * normal network selection next time.
6004 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006005 */
6006 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006007 public boolean setNetworkSelectionModeManual(
6008 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6010 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006011
6012 if (!isActiveSubscription(subId)) {
6013 return false;
6014 }
6015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 final long identity = Binder.clearCallingIdentity();
6017 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006018 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006020 if (DBG) {
6021 log("setNetworkSelectionModeManual: subId: " + subId
6022 + " operator: " + operatorInfo);
6023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006024 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6025 } finally {
6026 Binder.restoreCallingIdentity(identity);
6027 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006028 }
shilu84f6e8b2019-12-19 13:58:01 -08006029 /**
6030 * Get the manual network selection
6031 *
6032 * @param subId the id of the subscription.
6033 *
6034 * @return the previously saved user selected PLMN
6035 */
6036 @Override
6037 public String getManualNetworkSelectionPlmn(int subId) {
6038 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006039 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006040 mApp, subId, "getManualNetworkSelectionPlmn");
6041
6042 final long identity = Binder.clearCallingIdentity();
6043 try {
6044 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006045 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006046 }
6047
6048 final Phone phone = getPhone(subId);
6049 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006050 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006051 }
6052 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6053 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6054 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6055 } finally {
6056 Binder.restoreCallingIdentity(identity);
6057 }
6058 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006059
6060 /**
6061 * Scans for available networks.
6062 */
6063 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006064 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6065 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6067 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006068 LocationAccessPolicy.LocationPermissionResult locationResult =
6069 LocationAccessPolicy.checkLocationPermission(mApp,
6070 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6071 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006072 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006073 .setCallingPid(Binder.getCallingPid())
6074 .setCallingUid(Binder.getCallingUid())
6075 .setMethod("getCellNetworkScanResults")
6076 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006077 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6078 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006079 .build());
6080 switch (locationResult) {
6081 case DENIED_HARD:
6082 throw new SecurityException("Not allowed to access scan results -- location");
6083 case DENIED_SOFT:
6084 return null;
6085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086
Pengquan Menga1bb6272018-09-06 09:59:22 -07006087 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 try {
6089 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006090 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 } finally {
6093 Binder.restoreCallingIdentity(identity);
6094 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006095 }
6096
6097 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006098 * Get the call forwarding info, given the call forwarding reason.
6099 */
6100 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006101 public void getCallForwarding(int subId, int callForwardingReason,
6102 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006103 enforceReadPrivilegedPermission("getCallForwarding");
6104 long identity = Binder.clearCallingIdentity();
6105 try {
6106 if (DBG) {
6107 log("getCallForwarding: subId " + subId
6108 + " callForwardingReason" + callForwardingReason);
6109 }
Hall Liu27d24262020-09-18 19:04:59 -07006110
6111 Phone phone = getPhone(subId);
6112 if (phone == null) {
6113 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006114 callback.onError(
6115 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006116 } catch (RemoteException e) {
6117 // ignore
6118 }
6119 return;
6120 }
6121
6122 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6123 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6124 @Override
6125 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6126 try {
6127 callback.onCallForwardingInfoAvailable(info);
6128 } catch (RemoteException e) {
6129 // ignore
6130 }
6131 }
6132
6133 @Override
6134 public void onError(int error) {
6135 try {
6136 callback.onError(error);
6137 } catch (RemoteException e) {
6138 // ignore
6139 }
6140 }
6141 });
6142 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006143 } finally {
6144 Binder.restoreCallingIdentity(identity);
6145 }
6146 }
6147
6148 /**
6149 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6150 * reason, the number to forward, and the timeout before the forwarding is attempted.
6151 */
6152 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006153 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6154 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006155 enforceModifyPermission();
6156 long identity = Binder.clearCallingIdentity();
6157 try {
6158 if (DBG) {
6159 log("setCallForwarding: subId " + subId
6160 + " callForwardingInfo" + callForwardingInfo);
6161 }
Hall Liu27d24262020-09-18 19:04:59 -07006162
6163 Phone phone = getPhone(subId);
6164 if (phone == null) {
6165 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006166 callback.accept(
6167 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006168 } catch (RemoteException e) {
6169 // ignore
6170 }
6171 return;
6172 }
6173
6174 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6175 FunctionalUtils.ignoreRemoteException(callback::accept));
6176
6177 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006178 } finally {
6179 Binder.restoreCallingIdentity(identity);
6180 }
6181 }
6182
6183 /**
Hall Liu27d24262020-09-18 19:04:59 -07006184 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006185 */
6186 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006187 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006188 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006189 long identity = Binder.clearCallingIdentity();
6190 try {
Hall Liu27d24262020-09-18 19:04:59 -07006191 Phone phone = getPhone(subId);
6192 if (phone == null) {
6193 try {
6194 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6195 } catch (RemoteException e) {
6196 // ignore
6197 }
6198 return;
6199 }
SongFerngWang0e767992021-03-31 22:08:45 +08006200 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6201 PersistableBundle c = configManager.getConfigForSubId(subId);
6202 boolean requireUssd = c.getBoolean(
6203 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006204
Shuo Qian4a594052020-01-23 11:59:30 -08006205 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006206 if (requireUssd) {
6207 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6208 getSubscriptionCarrierId(subId));
6209 String newUssdCommand = "";
6210 try {
6211 newUssdCommand = carrierXmlParser.getFeature(
6212 CarrierXmlParser.FEATURE_CALL_WAITING)
6213 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6214 } catch (NullPointerException e) {
6215 loge("Failed to generate USSD number" + e);
6216 }
6217 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6218 mMainThreadHandler, callback, carrierXmlParser,
6219 CarrierXmlParser.SsEntry.SSAction.QUERY);
6220 final String ussdCommand = newUssdCommand;
6221 Executors.newSingleThreadExecutor().execute(() -> {
6222 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6223 });
6224 } else {
6225 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6226 callback::accept);
6227 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6228 }
Shuo Qian4a594052020-01-23 11:59:30 -08006229 } finally {
6230 Binder.restoreCallingIdentity(identity);
6231 }
6232 }
6233
6234 /**
Hall Liu27d24262020-09-18 19:04:59 -07006235 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006236 */
6237 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006238 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006239 enforceModifyPermission();
6240 long identity = Binder.clearCallingIdentity();
6241 try {
Hall Liu27d24262020-09-18 19:04:59 -07006242 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6243
6244 Phone phone = getPhone(subId);
6245 if (phone == null) {
6246 try {
6247 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6248 } catch (RemoteException e) {
6249 // ignore
6250 }
6251 return;
6252 }
6253
SongFerngWang0e767992021-03-31 22:08:45 +08006254 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6255 PersistableBundle c = configManager.getConfigForSubId(subId);
6256 boolean requireUssd = c.getBoolean(
6257 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006258
SongFerngWang0e767992021-03-31 22:08:45 +08006259 if (DBG) log("getCallWaitingStatus: subId " + subId);
6260 if (requireUssd) {
6261 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6262 getSubscriptionCarrierId(subId));
6263 CarrierXmlParser.SsEntry.SSAction ssAction =
6264 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6265 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6266 String newUssdCommand = "";
6267 try {
6268 newUssdCommand = carrierXmlParser.getFeature(
6269 CarrierXmlParser.FEATURE_CALL_WAITING)
6270 .makeCommand(ssAction, null);
6271 } catch (NullPointerException e) {
6272 loge("Failed to generate USSD number" + e);
6273 }
6274 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6275 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6276 final String ussdCommand = newUssdCommand;
6277 Executors.newSingleThreadExecutor().execute(() -> {
6278 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6279 });
6280 } else {
6281 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6282 FunctionalUtils.ignoreRemoteException(callback::accept));
6283
6284 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6285 }
Shuo Qian4a594052020-01-23 11:59:30 -08006286 } finally {
6287 Binder.restoreCallingIdentity(identity);
6288 }
6289 }
6290
6291 /**
yinxub1bed742017-04-17 11:45:04 -07006292 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006293 *
yinxub1bed742017-04-17 11:45:04 -07006294 * @param subId id of the subscription
6295 * @param request contains the radio access networks with bands/channels to scan
6296 * @param messenger callback messenger for scan results or errors
6297 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006298 * @return the id of the requested scan which can be used to stop the scan.
6299 */
6300 @Override
6301 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006302 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6304 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006305 LocationAccessPolicy.LocationPermissionResult locationResult =
6306 LocationAccessPolicy.checkLocationPermission(mApp,
6307 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6308 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006309 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006310 .setCallingPid(Binder.getCallingPid())
6311 .setCallingUid(Binder.getCallingUid())
6312 .setMethod("requestNetworkScan")
6313 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006314 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6315 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006316 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006317 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006318 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6319 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006320 if (e != null) {
6321 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6322 throw e;
6323 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006324 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006325 return TelephonyScanManager.INVALID_SCAN_ID;
6326 }
6327 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 }
Hall Liu912dfd32019-04-25 14:02:26 -07006329 int callingUid = Binder.getCallingUid();
6330 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006331 final long identity = Binder.clearCallingIdentity();
6332 try {
6333 return mNetworkScanRequestTracker.startNetworkScan(
6334 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006335 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006336 } finally {
6337 Binder.restoreCallingIdentity(identity);
6338 }
yinxu504e1392017-04-12 16:03:22 -07006339 }
6340
Hall Liub2ac8ef2019-02-28 15:56:23 -08006341 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006342 NetworkScanRequest request, int subId, String callingPackage) {
6343 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006344 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6345 boolean hasNetworkScanPermission =
6346 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6347 == PERMISSION_GRANTED;
6348
6349 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6350 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6351 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006352 }
6353
6354 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6355 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006356 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6357 return new SecurityException("Specific channels must not be"
6358 + " scanned without location access.");
6359 }
6360 }
6361 }
6362
Hall Liub2ac8ef2019-02-28 15:56:23 -08006363 return null;
6364 }
6365
yinxu504e1392017-04-12 16:03:22 -07006366 /**
6367 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006368 *
6369 * @param subId id of the subscription
6370 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006371 */
6372 @Override
6373 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6375 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376
Hall Liu912dfd32019-04-25 14:02:26 -07006377 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 final long identity = Binder.clearCallingIdentity();
6379 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006380 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 } finally {
6382 Binder.restoreCallingIdentity(identity);
6383 }
yinxu504e1392017-04-12 16:03:22 -07006384 }
6385
6386 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006387 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006388 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006389 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006390 */
6391 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006392 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006393 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006394 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006395 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396
6397 final long identity = Binder.clearCallingIdentity();
6398 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006399 if (DBG) log("getAllowedNetworkTypesBitmask");
6400 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6401 int networkTypesBitmask = (result != null ? result[0] : -1);
6402 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6403 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404 } finally {
6405 Binder.restoreCallingIdentity(identity);
6406 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006407 }
6408
6409 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006410 * Get the allowed network types for certain reason.
6411 *
6412 * @param subId the id of the subscription.
6413 * @param reason the reason the allowed network type change is taking place
6414 * @return the allowed network types.
6415 */
6416 @Override
6417 public long getAllowedNetworkTypesForReason(int subId,
6418 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006419 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006420 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006421 final long identity = Binder.clearCallingIdentity();
6422 try {
6423 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
6427 }
6428
6429 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006430 * Enable/Disable E-UTRA-NR Dual Connectivity
6431 * @param subId subscription id of the sim card
6432 * @param nrDualConnectivityState expected NR dual connectivity state
6433 * This can be passed following states
6434 * <ol>
6435 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6436 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6437 * <li>Disable NR dual connectivity and force secondary cell to be released
6438 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6439 * </ol>
6440 * @return operation result.
6441 */
6442 @Override
6443 public int setNrDualConnectivityState(int subId,
6444 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6446 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006447 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006448 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6449 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6450 }
6451
Sooraj Sasindran37444802020-08-11 10:40:43 -07006452 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6453 final long identity = Binder.clearCallingIdentity();
6454 try {
6455 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6456 nrDualConnectivityState, subId,
6457 workSource);
6458 if (DBG) log("enableNRDualConnectivity result: " + result);
6459 return result;
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
6463 }
6464
6465 /**
6466 * Is E-UTRA-NR Dual Connectivity enabled
6467 * @return true if dual connectivity is enabled else false
6468 */
6469 @Override
6470 public boolean isNrDualConnectivityEnabled(int subId) {
6471 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006472 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006473 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006474 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006475 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6476 return false;
6477 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006478 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6479 final long identity = Binder.clearCallingIdentity();
6480 try {
6481 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6482 null, subId, workSource);
6483 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6484 return isEnabled;
6485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
6488 }
6489
6490 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006491 * Set the allowed network types of the device and
6492 * provide the reason triggering the allowed network change.
6493 *
6494 * @param subId the id of the subscription.
6495 * @param reason the reason the allowed network type change is taking place
6496 * @param allowedNetworkTypes the allowed network types.
6497 * @return true on success; false on any failure.
6498 */
6499 @Override
6500 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006501 @TelephonyManager.AllowedNetworkTypesReason int reason,
6502 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6504 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006505 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006506 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6507 return false;
6508 }
6509 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6510 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006511 return false;
6512 }
6513
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006514 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6515 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6516
6517
6518 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6519 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6520 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006521 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006522
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006523 final long identity = Binder.clearCallingIdentity();
6524 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006525 Boolean success = (Boolean) sendRequest(
6526 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6527 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6528
6529 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6530 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006531 } finally {
6532 Binder.restoreCallingIdentity(identity);
6533 }
6534 }
6535
6536 /**
Miaoa84611c2019-03-15 09:21:10 +08006537 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006538 *
Miaoa84611c2019-03-15 09:21:10 +08006539 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006540 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006541 * @hide
6542 */
6543 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006544 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006545 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006547 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 try {
Miaoa84611c2019-03-15 09:21:10 +08006549 if (phone != null) {
6550 return phone.hasMatchedTetherApnSetting();
6551 } else {
6552 return false;
6553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 } finally {
6555 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006556 }
Junda Liu475951f2014-11-07 16:45:03 -08006557 }
6558
6559 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006560 * Get the user enabled state of Mobile Data.
6561 *
6562 * TODO: remove and use isUserDataEnabled.
6563 * This can't be removed now because some vendor codes
6564 * calls through ITelephony directly while they should
6565 * use TelephonyManager.
6566 *
6567 * @return true on enabled
6568 */
6569 @Override
6570 public boolean getDataEnabled(int subId) {
6571 return isUserDataEnabled(subId);
6572 }
6573
6574 /**
6575 * Get whether mobile data is enabled per user setting.
6576 *
6577 * There are other factors deciding whether mobile data is actually enabled, but they are
6578 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006579 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006580 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006581 *
6582 * @return {@code true} if data is enabled else {@code false}
6583 */
6584 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006585 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006586 try {
6587 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6588 null);
6589 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6591 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 int phoneId = mSubscriptionController.getPhoneId(subId);
6597 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6598 Phone phone = PhoneFactory.getPhone(phoneId);
6599 if (phone != null) {
6600 boolean retVal = phone.isUserDataEnabled();
6601 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6602 return retVal;
6603 } else {
6604 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6605 return false;
6606 }
6607 } finally {
6608 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006609 }
6610 }
6611
6612 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006613 * Checks if the device is capable of mobile data by considering whether whether the
6614 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6615 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006616 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006617 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006618 */
6619 @Override
6620 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006621 try {
6622 try {
6623 mApp.enforceCallingOrSelfPermission(
6624 android.Manifest.permission.ACCESS_NETWORK_STATE,
6625 null);
6626 } catch (Exception e) {
6627 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6628 "isDataEnabled");
6629 }
6630 } catch (Exception e) {
6631 enforceReadPrivilegedPermission("isDataEnabled");
6632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633
6634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 int phoneId = mSubscriptionController.getPhoneId(subId);
6637 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6638 Phone phone = PhoneFactory.getPhone(phoneId);
6639 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006640 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006641 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6642 return retVal;
6643 } else {
6644 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6645 return false;
6646 }
6647 } finally {
6648 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006649 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006650 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006651
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006652 /**
6653 * Check if data is enabled for a specific reason
6654 * @param subId Subscription index
6655 * @param reason the reason the data enable change is taking place
6656 * @return {@code true} if the overall data is enabled; {@code false} if not.
6657 */
6658 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006659 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006660 @TelephonyManager.DataEnabledReason int reason) {
6661 try {
6662 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6663 null);
6664 } catch (Exception e) {
6665 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006666 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006667 }
6668
6669
6670 final long identity = Binder.clearCallingIdentity();
6671 try {
6672 int phoneId = mSubscriptionController.getPhoneId(subId);
6673 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006674 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006675 + " reason=" + reason);
6676 }
6677 Phone phone = PhoneFactory.getPhone(phoneId);
6678 if (phone != null) {
6679 boolean retVal;
6680 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6681 retVal = phone.isUserDataEnabled();
6682 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006683 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006684 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006685 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006686 return retVal;
6687 } else {
6688 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006689 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006690 + subId + " retVal=false");
6691 }
6692 return false;
6693 }
6694 } finally {
6695 Binder.restoreCallingIdentity(identity);
6696 }
6697 }
6698
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006699 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006700 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006701 if (uid == Process.PHONE_UID) {
6702 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6703 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006704 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6705 }
6706
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006707 //load access rules from carrier configs, and check those as well: b/139133814
6708 SubscriptionController subController = SubscriptionController.getInstance();
6709 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6710 || subController == null) return privilegeFromSim;
6711
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006712 PackageManager pkgMgr = phone.getContext().getPackageManager();
6713 String[] packages = pkgMgr.getPackagesForUid(uid);
6714
6715 final long identity = Binder.clearCallingIdentity();
6716 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006717 int subId = phone.getSubId();
6718 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6719 // A test override is in place for the privileges for this subId, so don't try to
6720 // read the subscription privileges.
6721 return privilegeFromSim;
6722 }
6723 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006724 SubscriptionManager subManager = (SubscriptionManager)
6725 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6726 for (String pkg : packages) {
6727 if (subManager.canManageSubscription(subInfo, pkg)) {
6728 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6729 }
6730 }
6731 return privilegeFromSim;
6732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
6735 }
6736
6737 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6738 String pkgName) {
6739 //load access rules from carrier configs, and check those as well: b/139133814
6740 SubscriptionController subController = SubscriptionController.getInstance();
6741 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6742 || subController == null) return privilegeFromSim;
6743
6744 final long identity = Binder.clearCallingIdentity();
6745 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006746 int subId = phone.getSubId();
6747 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6748 // A test override is in place for the privileges for this subId, so don't try to
6749 // read the subscription privileges.
6750 return privilegeFromSim;
6751 }
6752 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006753 SubscriptionManager subManager = (SubscriptionManager)
6754 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6755 return subManager.canManageSubscription(subInfo, pkgName)
6756 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6757 } finally {
6758 Binder.restoreCallingIdentity(identity);
6759 }
6760 }
6761
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006762 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006763 public int getCarrierPrivilegeStatus(int subId) {
6764 final Phone phone = getPhone(subId);
6765 if (phone == null) {
6766 loge("getCarrierPrivilegeStatus: Invalid subId");
6767 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6768 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006769 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6770 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006771 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006772 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6773 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006774
6775 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006776 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006777 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006778 }
Junda Liu29340342014-07-10 15:23:27 -07006779
6780 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006781 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006782 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006783 final Phone phone = getPhone(subId);
6784 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006785 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006786 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6787 }
6788 UiccProfile profile =
6789 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6790 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006791 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6793 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006794 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006795 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006796 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006797 }
6798
6799 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006800 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006801 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006802 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006803 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006804 }
6805
6806 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006807 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6808 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006809 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006810 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6811 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006812 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006813 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006814 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006815 }
6816
6817 @Override
6818 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006819 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006820 if (TextUtils.isEmpty(pkgName))
6821 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006822 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6823 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006824 UiccPort port = UiccController.getInstance().getUiccPort(i);
6825 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006826 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006827 continue;
6828 }
6829
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006830 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006831 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006832 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006833 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6834 break;
6835 }
6836 }
6837
6838 return result;
Junda Liu29340342014-07-10 15:23:27 -07006839 }
Derek Tan89e89d42014-07-08 17:00:10 -07006840
6841 @Override
Junda Liue64de782015-04-16 17:19:16 -07006842 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006843 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006844 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6845 loge("phoneId " + phoneId + " is not valid.");
6846 return null;
6847 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006848 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6849 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006850 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006851 return null ;
6852 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006853 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006854 }
6855
Amith Yamasani6e118872016-02-19 12:53:51 -08006856 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006857 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006858 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006859 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006860 List<String> privilegedPackages = new ArrayList<>();
6861 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006862 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006863 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006864 if (port != null) {
6865 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006866 if (packages == null) {
6867 // Only check packages in user 0 for now
6868 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006869 PackageManager.MATCH_DISABLED_COMPONENTS
6870 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006871 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006872 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006873 }
6874 for (int p = packages.size() - 1; p >= 0; p--) {
6875 PackageInfo pkgInfo = packages.get(p);
6876 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006877 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006878 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006879 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006880 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006881 privilegedPackages.add(pkgInfo.packageName);
6882 }
6883 }
6884 }
6885 }
6886 return privilegedPackages;
6887 }
6888
chen xuf7e9fe82019-05-09 19:31:02 -07006889 @Override
6890 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006891 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6892
6893 final long identity = Binder.clearCallingIdentity();
6894
chen xuf7e9fe82019-05-09 19:31:02 -07006895 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006896 try {
6897 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6898 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6899 }
6900 } finally {
6901 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006902 }
6903 return privilegedPackages;
6904 }
6905
Wink Savilleb564aae2014-10-23 10:18:09 -07006906 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006907 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006908 UiccPort port = phone == null ? null : phone.getUiccPort();
6909 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006910 return null;
6911 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006912 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006913 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006914 return null;
6915 }
6916 return iccId;
6917 }
6918
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006919 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006920 public void setCallComposerStatus(int subId, int status) {
6921 enforceModifyPermission();
6922
6923 final long identity = Binder.clearCallingIdentity();
6924 try {
6925 Phone phone = getPhone(subId);
6926 if (phone != null) {
6927 Phone defaultPhone = phone.getImsPhone();
6928 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6929 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6930 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006931 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6932 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006933 }
6934 }
Shuo Qian284ae752020-12-22 19:10:14 -08006935 } catch (ImsException e) {
6936 throw new ServiceSpecificException(e.getCode());
6937 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006938 Binder.restoreCallingIdentity(identity);
6939 }
6940 }
6941
6942 @Override
6943 public int getCallComposerStatus(int subId) {
6944 enforceReadPrivilegedPermission("getCallComposerStatus");
6945
6946 final long identity = Binder.clearCallingIdentity();
6947 try {
6948 Phone phone = getPhone(subId);
6949 if (phone != null) {
6950 Phone defaultPhone = phone.getImsPhone();
6951 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6952 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6953 return imsPhone.getCallComposerStatus();
6954 }
6955 }
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
6958 }
6959 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6960 }
6961
6962 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006963 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6964 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006965 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006966 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 final String iccId = getIccId(subId);
6971 final Phone phone = getPhone(subId);
6972 if (phone == null) {
6973 return false;
6974 }
6975 final String subscriberId = phone.getSubscriberId();
6976
6977 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006978 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979 + subscriberId + " to " + number);
6980 }
6981
6982 if (TextUtils.isEmpty(iccId)) {
6983 return false;
6984 }
6985
6986 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6987
6988 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6989 if (alphaTag == null) {
6990 editor.remove(alphaTagPrefKey);
6991 } else {
6992 editor.putString(alphaTagPrefKey, alphaTag);
6993 }
6994
6995 // Record both the line number and IMSI for this ICCID, since we need to
6996 // track all merged IMSIs based on line number
6997 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6998 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6999 if (number == null) {
7000 editor.remove(numberPrefKey);
7001 editor.remove(subscriberPrefKey);
7002 } else {
7003 editor.putString(numberPrefKey, number);
7004 editor.putString(subscriberPrefKey, subscriberId);
7005 }
7006
7007 editor.commit();
7008 return true;
7009 } finally {
7010 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007011 }
Derek Tan7226c842014-07-02 17:42:23 -07007012 }
7013
7014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007015 public String getLine1NumberForDisplay(int subId, String callingPackage,
7016 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007017 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007019 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007020 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007021 return null;
7022 }
Derek Tan97ebb422014-09-05 16:55:38 -07007023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 final long identity = Binder.clearCallingIdentity();
7025 try {
7026 String iccId = getIccId(subId);
7027 if (iccId != null) {
7028 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7029 if (DBG_MERGE) {
7030 log("getLine1NumberForDisplay returning "
7031 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7032 }
7033 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7036 return null;
7037 } finally {
7038 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007039 }
Derek Tan7226c842014-07-02 17:42:23 -07007040 }
7041
7042 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007043 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7044 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007046 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007047 return null;
7048 }
Derek Tan97ebb422014-09-05 16:55:38 -07007049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 final long identity = Binder.clearCallingIdentity();
7051 try {
7052 String iccId = getIccId(subId);
7053 if (iccId != null) {
7054 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7055 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7056 }
7057 return null;
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007060 }
Derek Tan7226c842014-07-02 17:42:23 -07007061 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007062
7063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007064 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7065 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007066 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7067 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007069 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007070 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007071 return null;
7072 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007073
Jordan Liub49b04b2019-05-06 14:45:15 -07007074 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7075 // the process, where TelephonyManager was instantiated.
7076 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007077 final long identity = Binder.clearCallingIdentity();
7078 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007079 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 final TelephonyManager tele = TelephonyManager.from(context);
7081 final SubscriptionManager sub = SubscriptionManager.from(context);
7082
7083 // Figure out what subscribers are currently active
7084 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085
Jordan Liub49b04b2019-05-06 14:45:15 -07007086 // Only consider subs which match the current subId
7087 // This logic can be simplified. See b/131189269 for progress.
7088 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007089 activeSubscriberIds.add(tele.getSubscriberId(subId));
7090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091
7092 // First pass, find a number override for an active subscriber
7093 String mergeNumber = null;
7094 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7095 for (String key : prefs.keySet()) {
7096 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7097 final String subscriberId = (String) prefs.get(key);
7098 if (activeSubscriberIds.contains(subscriberId)) {
7099 final String iccId = key.substring(
7100 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7101 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7102 mergeNumber = (String) prefs.get(numberKey);
7103 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007104 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 + " for active subscriber " + subscriberId);
7106 }
7107 if (!TextUtils.isEmpty(mergeNumber)) {
7108 break;
7109 }
7110 }
7111 }
7112 }
7113
7114 // Shortcut when no active merged subscribers
7115 if (TextUtils.isEmpty(mergeNumber)) {
7116 return null;
7117 }
7118
7119 // Second pass, find all subscribers under that line override
7120 final ArraySet<String> result = new ArraySet<>();
7121 for (String key : prefs.keySet()) {
7122 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7123 final String number = (String) prefs.get(key);
7124 if (mergeNumber.equals(number)) {
7125 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7126 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7127 final String subscriberId = (String) prefs.get(subscriberKey);
7128 if (!TextUtils.isEmpty(subscriberId)) {
7129 result.add(subscriberId);
7130 }
7131 }
7132 }
7133 }
7134
7135 final String[] resultArray = result.toArray(new String[result.size()]);
7136 Arrays.sort(resultArray);
7137 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007138 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7140 }
7141 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007142 } finally {
7143 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007144 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007145 }
7146
7147 @Override
zoey chen38003472019-12-13 17:16:31 +08007148 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7149 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007150
7151 final long identity = Binder.clearCallingIdentity();
7152 try {
7153 final TelephonyManager telephonyManager = mApp.getSystemService(
7154 TelephonyManager.class);
7155 String subscriberId = telephonyManager.getSubscriberId(subId);
7156 if (subscriberId == null) {
7157 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007158 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007159 + subId);
7160 }
7161 return null;
7162 }
7163
7164 final SubscriptionInfo info = SubscriptionController.getInstance()
7165 .getSubscriptionInfo(subId);
7166 final ParcelUuid groupUuid = info.getGroupUuid();
7167 // If it doesn't belong to any group, return just subscriberId of itself.
7168 if (groupUuid == null) {
7169 return new String[]{subscriberId};
7170 }
7171
7172 // Get all subscriberIds from the group.
7173 final List<String> mergedSubscriberIds = new ArrayList<>();
7174 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007175 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007176 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007177 for (SubscriptionInfo subInfo : groupInfos) {
7178 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7179 if (subscriberId != null) {
7180 mergedSubscriberIds.add(subscriberId);
7181 }
7182 }
7183
7184 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7185 } finally {
7186 Binder.restoreCallingIdentity(identity);
7187
7188 }
7189 }
7190
7191 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007192 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007193 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007194 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195
7196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 final Phone phone = getPhone(subId);
7199 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7200 } finally {
7201 Binder.restoreCallingIdentity(identity);
7202 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007203 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007204
7205 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007206 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007207 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7208 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007209 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7210 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211
7212 final long identity = Binder.clearCallingIdentity();
7213 try {
7214 final Phone phone = getPhone(subId);
7215 if (phone == null) {
7216 return false;
7217 }
7218 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7219 cdmaNonRoamingList);
7220 } finally {
7221 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007222 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007223 }
7224
7225 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007226 @Deprecated
7227 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7228 enforceModifyPermission();
7229
7230 int returnValue = 0;
7231 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007232 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007233 if(result.exception == null) {
7234 if (result.result != null) {
7235 byte[] responseData = (byte[])(result.result);
7236 if(responseData.length > oemResp.length) {
7237 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7238 responseData.length + "bytes. Buffer Size is " +
7239 oemResp.length + "bytes.");
7240 }
7241 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7242 returnValue = responseData.length;
7243 }
7244 } else {
7245 CommandException ex = (CommandException) result.exception;
7246 returnValue = ex.getCommandError().ordinal();
7247 if(returnValue > 0) returnValue *= -1;
7248 }
7249 } catch (RuntimeException e) {
7250 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7251 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7252 if(returnValue > 0) returnValue *= -1;
7253 }
7254
7255 return returnValue;
7256 }
7257
7258 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007259 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007260 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007261 try {
7262 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007263 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007264 mApp, phone.getSubId(), "getRadioAccessFamily");
7265 } catch (SecurityException e) {
7266 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7267 throw e;
7268 }
chen xub97461a2018-10-26 14:17:57 -07007269 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007270 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007271 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007273 final long identity = Binder.clearCallingIdentity();
7274 try {
chen xub97461a2018-10-26 14:17:57 -07007275 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007276 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007277 mApp, phone.getSubId(), "getRadioAccessFamily");
7278 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279 } finally {
7280 Binder.restoreCallingIdentity(identity);
7281 }
chen xub97461a2018-10-26 14:17:57 -07007282 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007283 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007284
7285 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007286 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007287 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007288 try {
7289 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7290 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007291 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007292 }
7293 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007294 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007295 }
7296 RoleManager rm = mApp.getSystemService(RoleManager.class);
7297 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7298 if (!dialerRoleHolders.contains(callingPackage)) {
7299 throw new SecurityException("App must be the dialer role holder to"
7300 + " upload a call composer pic");
7301 }
7302
7303 Executors.newSingleThreadExecutor().execute(() -> {
7304 ByteArrayOutputStream output = new ByteArrayOutputStream(
7305 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7306 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7307 boolean readUntilEnd = false;
7308 int totalBytesRead = 0;
7309 byte[] buffer = new byte[16 * 1024];
7310 while (true) {
7311 int numRead;
7312 try {
7313 numRead = input.read(buffer);
7314 } catch (IOException e) {
7315 try {
7316 fd.checkError();
7317 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7318 null);
7319 } catch (IOException e1) {
7320 // This means that the other side closed explicitly with an error. If this
7321 // happens, log and ignore.
7322 loge("Remote end of call composer picture pipe closed: " + e1);
7323 }
7324 break;
7325 }
7326 if (numRead == -1) {
7327 readUntilEnd = true;
7328 break;
7329 }
7330 totalBytesRead += numRead;
7331 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7332 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7333 try {
7334 input.close();
7335 } catch (IOException e) {
7336 // ignore
7337 }
7338 break;
7339 }
7340 output.write(buffer, 0, numRead);
7341 }
7342 // Generally, the remote end will close the file descriptors. The only case where we
7343 // close is above, where the picture size is too big.
7344
7345 try {
7346 fd.checkError();
7347 } catch (IOException e) {
7348 loge("Remote end for call composer closed with an error: " + e);
7349 return;
7350 }
7351
Hall Liuaa4211e2021-01-20 15:43:39 -08007352 if (!readUntilEnd) {
7353 loge("Did not finish reading entire image; aborting");
7354 return;
7355 }
Hall Liu82694d52020-12-11 18:22:04 -08007356
Hall Liuaa4211e2021-01-20 15:43:39 -08007357 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7358 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7359 new CallComposerPictureTransfer.Factory() {},
7360 imageData,
7361 (result) -> {
7362 if (result.first != null) {
7363 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7364 Bundle outputResult = new Bundle();
7365 outputResult.putParcelable(
7366 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7367 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7368 outputResult);
7369 } else {
7370 callback.send(result.second, null);
7371 }
7372 }
7373 );
Hall Liu82694d52020-12-11 18:22:04 -08007374 });
7375 }
7376
7377 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007378 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007379 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007380 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381
7382 final long identity = Binder.clearCallingIdentity();
7383 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007384 ImsManager.getInstance(defaultPhone.getContext(),
7385 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386 } finally {
7387 Binder.restoreCallingIdentity(identity);
7388 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007389 }
7390
7391 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007392 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007393 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7395 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007396 return false;
7397 }
Svet Ganovb320e182015-04-16 12:30:10 -07007398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007399 final long identity = Binder.clearCallingIdentity();
7400 try {
7401 // Check the user preference and the system-level IMS setting. Even if the user has
7402 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7403 // In the long run, we may instead need to check if there exists a connection service
7404 // which can support video calling.
7405 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007406 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 return imsManager.isVtEnabledByPlatform()
7408 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7409 && imsManager.isVtEnabledByUser();
7410 } finally {
7411 Binder.restoreCallingIdentity(identity);
7412 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007413 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007414
Andrew Leea1239f22015-03-02 17:44:07 -08007415 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007416 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7417 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007419 mApp, subId, callingPackage, callingFeatureId,
7420 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 return false;
7422 }
7423
7424 final long identity = Binder.clearCallingIdentity();
7425 try {
7426 CarrierConfigManager configManager =
7427 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007428 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7430 } finally {
7431 Binder.restoreCallingIdentity(identity);
7432 }
Andrew Leea1239f22015-03-02 17:44:07 -08007433 }
7434
7435 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007436 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007438 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 return false;
7440 }
7441
7442 final long identity = Binder.clearCallingIdentity();
7443 try {
7444 CarrierConfigManager configManager =
7445 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007446 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7448 } finally {
7449 Binder.restoreCallingIdentity(identity);
7450 }
Andrew Leea1239f22015-03-02 17:44:07 -08007451 }
7452
Andrew Lee9431b832015-03-09 18:46:45 -07007453 @Override
7454 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007455 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007456 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007457 }
7458
7459 @Override
7460 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 final long identity = Binder.clearCallingIdentity();
7462 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007463 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
Andrew Lee9431b832015-03-09 18:46:45 -07007467 }
7468
Hall Liuf6668912018-10-31 17:05:23 -07007469 /**
7470 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7471 * support for the feature and device firmware support.
7472 *
7473 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7474 */
7475 @Override
7476 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007478 final Phone phone = getPhone(subscriptionId);
7479 if (phone == null) {
7480 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7481 return false;
7482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007484 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7486 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007487 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 return isCarrierSupported && isDeviceSupported;
7489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
Hall Liu98187582018-01-22 19:15:32 -08007492 }
7493
Hall Liuf6668912018-10-31 17:05:23 -07007494 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007495 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7496 * RTT setting, will return true if the device and carrier both support RTT.
7497 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007498 */
7499 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 final long identity = Binder.clearCallingIdentity();
7501 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007502 boolean isRttSupported = isRttSupported(subscriptionId);
7503 boolean isUserRttSettingOn = Settings.Secure.getInt(
7504 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7505 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7506 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7507 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007511 }
7512
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007513 @Deprecated
7514 @Override
7515 public String getDeviceId(String callingPackage) {
7516 return getDeviceIdWithFeature(callingPackage, null);
7517 }
7518
Sanket Padawe7310cc72015-01-14 09:53:20 -08007519 /**
7520 * Returns the unique device ID of phone, for example, the IMEI for
7521 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7522 *
7523 * <p>Requires Permission:
7524 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7525 */
7526 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007527 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007528 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007529 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007530 return null;
7531 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007532 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007533 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007534 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007535 return null;
7536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537
7538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 return phone.getDeviceId();
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007544 }
7545
Ping Sunc67b7c22016-03-02 19:16:45 +08007546 /**
7547 * {@hide}
7548 * Returns the IMS Registration Status on a particular subid
7549 *
7550 * @param subId
7551 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007552 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007553 Phone phone = getPhone(subId);
7554 if (phone != null) {
7555 return phone.isImsRegistered();
7556 } else {
7557 return false;
7558 }
7559 }
7560
Santos Cordon7a1885b2015-02-03 11:15:19 -08007561 @Override
7562 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 final long identity = Binder.clearCallingIdentity();
7564 try {
7565 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7566 } finally {
7567 Binder.restoreCallingIdentity(identity);
7568 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007569 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007570
Tyler Gunnf70ed162019-04-03 15:28:53 -07007571 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007572 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007573 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007575 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007576 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7577 }
7578 final long identity = Binder.clearCallingIdentity();
7579 try {
7580 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7581 } finally {
7582 Binder.restoreCallingIdentity(identity);
7583 }
7584 }
7585
7586 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007587 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007588 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007589 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007590 mApp,
7591 subscriptionId,
7592 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007593 final long identity = Binder.clearCallingIdentity();
7594 try {
7595 Phone phone = getPhone(subscriptionId);
7596 if (phone == null) {
7597 return null;
7598 }
7599 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
7603 }
7604
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007605 /**
7606 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007607 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007608 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 final long identity = Binder.clearCallingIdentity();
7610 try {
7611 Phone phone = getPhone(subId);
7612 if (phone != null) {
7613 return phone.isWifiCallingEnabled();
7614 } else {
7615 return false;
7616 }
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007619 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007620 }
7621
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007622 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007623 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007624 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007625 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 Phone phone = getPhone(subId);
7629 if (phone != null) {
7630 return phone.isVideoEnabled();
7631 } else {
7632 return false;
7633 }
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007636 }
7637 }
7638
7639 /**
7640 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7641 * defined in {@link ImsRegistrationImplBase}.
7642 */
7643 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 Phone phone = getPhone(subId);
7647 if (phone != null) {
7648 return phone.getImsRegistrationTech();
7649 } else {
7650 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7651 }
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007654 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007655 }
7656
Stuart Scott8eef64f2015-04-08 15:13:54 -07007657 @Override
7658 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007659 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007660 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7661 return;
7662 }
Kai Shif70f46f2021-03-03 13:59:46 -08007663 Phone defaultPhone = getDefaultPhone();
7664 if (defaultPhone != null) {
7665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7666 mApp, getDefaultPhone().getSubId(), "factoryReset");
7667 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007668 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007669
Svet Ganovcc087f82015-05-12 20:35:54 -07007670 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007671 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7672 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007673 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007674 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007675 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007676 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007677 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007678 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007679 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007680 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007681 // There has been issues when Sms raw table somehow stores orphan
7682 // fragments. They lead to garbled message when new fragments come
7683 // in and combined with those stale ones. In case this happens again,
7684 // user can reset all network settings which will clean up this table.
7685 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007686 // Clean up IMS settings as well here.
7687 int slotId = getSlotIndex(subId);
7688 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7689 ImsManager.getInstance(mApp, slotId).factoryReset();
7690 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007691
Kai Shif70f46f2021-03-03 13:59:46 -08007692 if (defaultPhone == null) {
7693 return;
7694 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007695 // Erase modem config if erase modem on network setting is enabled.
7696 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7697 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7698 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007699 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007700 }
Kai Shif70f46f2021-03-03 13:59:46 -08007701
7702 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007703 } finally {
7704 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007705 }
7706 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007707
SongFerngWangfd89b102021-05-27 22:44:54 +08007708 @VisibleForTesting
7709 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7710 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7711 return;
7712 }
7713 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7714 RILConstants.PREFERRED_NETWORK_MODE);
7715 SubscriptionManager.setSubscriptionProperty(subId,
7716 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7717 "user=" + defaultNetworkType);
7718 phone.loadAllowedNetworksFromSubscriptionDatabase();
7719 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7720 defaultNetworkType, null);
7721 }
7722
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007723 private void cleanUpSmsRawTable(Context context) {
7724 ContentResolver resolver = context.getContentResolver();
7725 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7726 resolver.delete(uri, null, null);
7727 }
7728
Narayan Kamath1c496c22015-04-16 14:40:19 +01007729 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007730 public String getSimLocaleForSubscriber(int subId) {
7731 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7732 final Phone phone = getPhone(subId);
7733 if (phone == null) {
7734 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007735 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 final long identity = Binder.clearCallingIdentity();
7738 try {
chen xu5d3637b2019-01-21 23:31:38 -08007739 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007740 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007741 if (info == null) {
7742 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7743 return null;
7744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 // Try and fetch the locale from the carrier properties or from the SIM language
7746 // preferences (EF-PL and EF-LI)...
7747 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007749 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7750 if (localeFromDefaultSim != null) {
7751 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7752 if (DBG) log("Using locale from subId: " + subId + " locale: "
7753 + localeFromDefaultSim);
7754 return localeFromDefaultSim.toLanguageTag();
7755 } else {
7756 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 }
7758 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 // The SIM language preferences only store a language (e.g. fr = French), not an
7761 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7762 // the SIM and carrier preferences does not include a country we add the country
7763 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007764 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007766 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007767 return mccLocale.toLanguageTag();
7768 }
7769
7770 if (DBG) log("No locale found - returning null");
7771 return null;
7772 } finally {
7773 Binder.restoreCallingIdentity(identity);
7774 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007775 }
7776
7777 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007778 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007779 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007780 }
7781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782 /**
7783 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7784 */
7785 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007786 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007787 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007788 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007789
Chenjie Yu1ba97252018-01-11 18:16:20 -08007790 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007791 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007792
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007793 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007794 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7795 * representing the state of the modem.
7796 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007797 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7798 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007799 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007800 */
7801 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007802 public void requestModemActivityInfo(ResultReceiver result) {
7803 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007804 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805
7806 final long identity = Binder.clearCallingIdentity();
7807 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007808 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 } finally {
7810 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007811 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007812 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007813
Siddharth Rayb8114062018-06-17 15:02:38 -07007814 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7815 // less than total activity duration.
7816 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7817 if (info == null) {
7818 return false;
7819 }
7820 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007821 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7822 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7823
Siddharth Rayb8114062018-06-17 15:02:38 -07007824 return (info.isValid()
7825 && (info.getSleepTimeMillis() <= activityDurationMs)
7826 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007827 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007828 && (totalTxTimeMs <= activityDurationMs));
7829 }
7830
Jack Yu85bd38a2015-11-09 11:34:32 -08007831 /**
7832 * {@hide}
7833 * Returns the service state information on specified subscription.
7834 */
7835 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007836 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7837 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007839 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007840 return null;
7841 }
7842
Hall Liuf19c44f2018-11-27 14:38:17 -08007843 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7844 LocationAccessPolicy.checkLocationPermission(mApp,
7845 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7846 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007847 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007848 .setCallingPid(Binder.getCallingPid())
7849 .setCallingUid(Binder.getCallingUid())
7850 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007851 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007852 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007853 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7854 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007855 .build());
7856
7857 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7858 LocationAccessPolicy.checkLocationPermission(mApp,
7859 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7860 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007861 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007862 .setCallingPid(Binder.getCallingPid())
7863 .setCallingUid(Binder.getCallingUid())
7864 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007865 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007866 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007867 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7868 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007869 .build());
7870 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7871 boolean hasFinePermission =
7872 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7873 boolean hasCoarsePermission =
7874 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7875
Jack Yu479f40e2020-10-27 21:29:25 -07007876 final Phone phone = getPhone(subId);
7877 if (phone == null) {
7878 return null;
7879 }
7880
Jordan Liu0f2bc442020-11-18 16:47:37 -08007881 final long identity = Binder.clearCallingIdentity();
7882
Jack Yu479f40e2020-10-27 21:29:25 -07007883 boolean isCallingPackageDataService = phone.getDataServicePackages()
7884 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007886 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7887 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7888 Rlog.d(LOG_TAG,
7889 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7890 return null;
7891 }
7892
Hall Liuf19c44f2018-11-27 14:38:17 -08007893 ServiceState ss = phone.getServiceState();
7894
7895 // Scrub out the location info in ServiceState depending on what level of access
7896 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007897 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007898 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7899 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 } finally {
7901 Binder.restoreCallingIdentity(identity);
7902 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007903 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007904
7905 /**
7906 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7907 *
7908 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7909 * voicemail ringtone.
7910 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7911 * PhoneAccount.
7912 */
7913 @Override
7914 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 final long identity = Binder.clearCallingIdentity();
7916 try {
7917 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7918 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007919 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007922 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7923 } finally {
7924 Binder.restoreCallingIdentity(identity);
7925 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007926 }
7927
7928 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007929 * Sets the per-account voicemail ringtone.
7930 *
7931 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7932 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7933 *
7934 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7935 * voicemail ringtone.
7936 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7937 * PhoneAccount.
7938 */
7939 @Override
7940 public void setVoicemailRingtoneUri(String callingPackage,
7941 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007942 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007943 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007944 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7945 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7947 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7948 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007950
7951 final long identity = Binder.clearCallingIdentity();
7952 try {
7953 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7954 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007955 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956 }
7957 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7958 } finally {
7959 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007960 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007961 }
7962
7963 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007964 * Returns whether vibration is set for voicemail notification in Phone settings.
7965 *
7966 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7967 * voicemail vibration setting.
7968 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7969 */
7970 @Override
7971 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007972 final long identity = Binder.clearCallingIdentity();
7973 try {
7974 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7975 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007976 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007979 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7980 } finally {
7981 Binder.restoreCallingIdentity(identity);
7982 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007983 }
7984
Youhan Wange64578a2016-05-02 15:32:42 -07007985 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007986 * Sets the per-account voicemail vibration.
7987 *
7988 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7989 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7990 *
7991 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7992 * voicemail vibration setting.
7993 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7994 * specific PhoneAccount.
7995 */
7996 @Override
7997 public void setVoicemailVibrationEnabled(String callingPackage,
7998 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007999 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008000 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008001 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8002 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8004 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8005 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008006 }
8007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008 final long identity = Binder.clearCallingIdentity();
8009 try {
8010 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8011 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008012 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 }
8014 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8015 } finally {
8016 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008017 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008018 }
8019
8020 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008021 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8022 *
8023 * @throws SecurityException if the caller does not have the required permission
8024 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008025 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008026 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008027 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008028 }
8029
8030 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008031 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8032 * permission.
8033 *
8034 * @throws SecurityException if the caller does not have the required permission
8035 */
8036 private void enforceSendSmsPermission() {
8037 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8038 }
8039
8040 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008041 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008042 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008043 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008044 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008045 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008046 final long identity = Binder.clearCallingIdentity();
8047 try {
8048 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008049 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 if (componentName == null) {
8051 throw new SecurityException(
8052 "Caller not current active visual voicemail package[null]");
8053 }
8054 String vvmPackage = componentName.getPackageName();
8055 if (!callingPackage.equals(vvmPackage)) {
8056 throw new SecurityException("Caller not current active visual voicemail package["
8057 + vvmPackage + "]");
8058 }
8059 } finally {
8060 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008061 }
8062 }
8063
8064 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008065 * Return the application ID for the app type.
8066 *
8067 * @param subId the subscription ID that this request applies to.
8068 * @param appType the uicc app type.
8069 * @return Application ID for specificied app type, or null if no uicc.
8070 */
8071 @Override
8072 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008073 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008074 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075
8076 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008077 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078 if (phone == null) {
8079 return null;
8080 }
8081 String aid = null;
8082 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008083 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 .getApplicationByType(appType).getAid();
8085 } catch (Exception e) {
8086 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8087 }
8088 return aid;
8089 } finally {
8090 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008091 }
Youhan Wange64578a2016-05-02 15:32:42 -07008092 }
8093
Youhan Wang4001d252016-05-11 10:29:41 -07008094 /**
8095 * Return the Electronic Serial Number.
8096 *
8097 * @param subId the subscription ID that this request applies to.
8098 * @return ESN or null if error.
8099 */
8100 @Override
8101 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008102 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008103 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104
8105 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008106 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107 if (phone == null) {
8108 return null;
8109 }
8110 String esn = null;
8111 try {
8112 esn = phone.getEsn();
8113 } catch (Exception e) {
8114 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8115 }
8116 return esn;
8117 } finally {
8118 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008119 }
Youhan Wang4001d252016-05-11 10:29:41 -07008120 }
8121
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008122 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008123 * Return the Preferred Roaming List Version.
8124 *
8125 * @param subId the subscription ID that this request applies to.
8126 * @return PRLVersion or null if error.
8127 */
8128 @Override
8129 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008130 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008131 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132
8133 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008134 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135 if (phone == null) {
8136 return null;
8137 }
8138 String cdmaPrlVersion = null;
8139 try {
8140 cdmaPrlVersion = phone.getCdmaPrlVersion();
8141 } catch (Exception e) {
8142 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8143 }
8144 return cdmaPrlVersion;
8145 } finally {
8146 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008147 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008148 }
8149
8150 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008151 * Get snapshot of Telephony histograms
8152 * @return List of Telephony histograms
8153 * @hide
8154 */
8155 @Override
8156 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8158 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159
8160 final long identity = Binder.clearCallingIdentity();
8161 try {
8162 return RIL.getTelephonyRILTimingHistograms();
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
8165 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008166 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008167
8168 /**
8169 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008170 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8171 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008172 * Require system privileges. In the future we may add this to carrier APIs.
8173 *
Michele Berionne482f8202018-11-27 18:57:59 -08008174 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008175 */
8176 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008177 @TelephonyManager.SetCarrierRestrictionResult
8178 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008179 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008180 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008181
Michele Berionne482f8202018-11-27 18:57:59 -08008182 if (carrierRestrictionRules == null) {
8183 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008184 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186 final long identity = Binder.clearCallingIdentity();
8187 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008188 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008189 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190 } finally {
8191 Binder.restoreCallingIdentity(identity);
8192 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008193 }
8194
8195 /**
8196 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008197 * Get the allowed carrier list and the excluded carrier list, including the priority between
8198 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008199 * Require system privileges. In the future we may add this to carrier APIs.
8200 *
Michele Berionne482f8202018-11-27 18:57:59 -08008201 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008202 */
8203 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008204 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008205 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008206 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008207
8208 final long identity = Binder.clearCallingIdentity();
8209 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008210 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8211 if (response instanceof CarrierRestrictionRules) {
8212 return (CarrierRestrictionRules) response;
8213 }
8214 // Response is an Exception of some kind,
8215 // which is signalled to the user as a NULL retval
8216 return null;
8217 } catch (Exception e) {
8218 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8219 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008223 }
8224
fionaxu59545b42016-05-25 15:53:37 -07008225 /**
fionaxu59545b42016-05-25 15:53:37 -07008226 * Action set from carrier signalling broadcast receivers to enable/disable radio
8227 * @param subId the subscription ID that this action applies to.
8228 * @param enabled control enable or disable radio.
8229 * {@hide}
8230 */
8231 @Override
8232 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8233 enforceModifyPermission();
8234 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235
8236 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008237 if (phone == null) {
8238 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8239 return;
8240 }
8241 try {
8242 phone.carrierActionSetRadioEnabled(enabled);
8243 } catch (Exception e) {
8244 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245 } finally {
8246 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008247 }
8248 }
8249
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008250 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008251 * Enable or disable Voice over NR (VoNR)
8252 * @param subId the subscription ID that this action applies to.
8253 * @param enabled enable or disable VoNR.
8254 * @return operation result.
8255 */
8256 @Override
8257 public int setVoNrEnabled(int subId, boolean enabled) {
8258 enforceModifyPermission();
8259 final Phone phone = getPhone(subId);
8260
8261 final long identity = Binder.clearCallingIdentity();
8262 if (phone == null) {
8263 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8264 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8265 }
8266
8267 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8268 try {
8269 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8270 workSource);
8271 if (DBG) log("setVoNrEnabled result: " + result);
8272 return result;
8273 } finally {
8274 Binder.restoreCallingIdentity(identity);
8275 }
8276 }
8277
8278 /**
8279 * Is voice over NR enabled
8280 * @return true if VoNR is enabled else false
8281 */
8282 @Override
8283 public boolean isVoNrEnabled(int subId) {
8284 enforceReadPrivilegedPermission("isVoNrEnabled");
8285 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8286 final long identity = Binder.clearCallingIdentity();
8287 try {
8288 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8289 null, subId, workSource);
8290 if (DBG) log("isVoNrEnabled: " + isEnabled);
8291 return isEnabled;
8292 } finally {
8293 Binder.restoreCallingIdentity(identity);
8294 }
8295 }
8296
8297 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008298 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8299 * network status based on which carrier apps could apply actions accordingly,
8300 * enable/disable default url handler for example.
8301 *
8302 * @param subId the subscription ID that this action applies to.
8303 * @param report control start/stop reporting the default network status.
8304 * {@hide}
8305 */
8306 @Override
8307 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8308 enforceModifyPermission();
8309 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310
8311 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008312 if (phone == null) {
8313 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8314 return;
8315 }
8316 try {
8317 phone.carrierActionReportDefaultNetworkStatus(report);
8318 } catch (Exception e) {
8319 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008320 } finally {
8321 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008322 }
8323 }
8324
8325 /**
fionaxud9622282017-07-17 17:51:30 -07008326 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8327 * @param subId the subscription ID that this action applies to.
8328 * {@hide}
8329 */
8330 @Override
8331 public void carrierActionResetAll(int subId) {
8332 enforceModifyPermission();
8333 final Phone phone = getPhone(subId);
8334 if (phone == null) {
8335 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8336 return;
8337 }
8338 try {
8339 phone.carrierActionResetAll();
8340 } catch (Exception e) {
8341 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8342 }
8343 }
8344
8345 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008346 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8347 * bug report is being generated.
8348 */
8349 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008350 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008351 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8352 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008353 writer.println("Permission Denial: can't dump Phone from pid="
8354 + Binder.getCallingPid()
8355 + ", uid=" + Binder.getCallingUid()
8356 + "without permission "
8357 + android.Manifest.permission.DUMP);
8358 return;
8359 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008360 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008361 }
Jack Yueb89b242016-06-22 13:27:47 -07008362
Brad Ebingerdac2f002018-04-03 15:17:52 -07008363 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008364 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8365 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8366 @NonNull String[] args) {
8367 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8368 this, in.getFileDescriptor(), out.getFileDescriptor(),
8369 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008370 }
8371
Jack Yueb89b242016-06-22 13:27:47 -07008372 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008373 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008374 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008375 * @param reason the reason the data enable change is taking place
8376 * @param enabled True if enabling the data, otherwise disabling.
8377 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008378 */
8379 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008380 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008381 boolean enabled) {
8382 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8383 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8384 try {
8385 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008386 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008387 } catch (SecurityException se) {
8388 enforceModifyPermission();
8389 }
8390 } else {
8391 enforceModifyPermission();
8392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393
8394 final long identity = Binder.clearCallingIdentity();
8395 try {
8396 Phone phone = getPhone(subId);
8397 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008398 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8399 phone.carrierActionSetMeteredApnsEnabled(enabled);
8400 } else {
8401 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8402 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008403 }
8404 } finally {
8405 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008406 }
8407 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008408
8409 /**
8410 * Get Client request stats
8411 * @return List of Client Request Stats
8412 * @hide
8413 */
8414 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008415 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8416 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008418 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008419 return null;
8420 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008421 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 final long identity = Binder.clearCallingIdentity();
8424 try {
8425 if (phone != null) {
8426 return phone.getClientRequestStats();
8427 }
8428
8429 return null;
8430 } finally {
8431 Binder.restoreCallingIdentity(identity);
8432 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008433 }
8434
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008435 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008436 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008437 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008438 }
Jack Yueb4124c2017-02-16 15:32:43 -08008439
8440 /**
Grace Chen70990072017-03-24 17:21:30 -07008441 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008442 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008443 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008444 * @param state State of SIM (power down, power up, pass through)
8445 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8446 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8447 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008448 *
8449 **/
8450 @Override
Grace Chen70990072017-03-24 17:21:30 -07008451 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008452 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008453 Phone phone = PhoneFactory.getPhone(slotIndex);
8454
vagdeviaf9a5b92018-08-15 16:01:53 -07008455 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008457 final long identity = Binder.clearCallingIdentity();
8458 try {
8459 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008460 phone.setSimPowerState(state, null, workSource);
8461 }
8462 } finally {
8463 Binder.restoreCallingIdentity(identity);
8464 }
8465 }
8466
8467 /**
8468 * Set SIM card power state.
8469 *
8470 * @param slotIndex SIM slot id.
8471 * @param state State of SIM (power down, power up, pass through)
8472 * @param callback callback to trigger after success or failure
8473 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8474 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8475 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8476 *
8477 **/
8478 @Override
8479 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8480 IIntegerConsumer callback) {
8481 enforceModifyPermission();
8482 Phone phone = PhoneFactory.getPhone(slotIndex);
8483
8484 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8485
8486 final long identity = Binder.clearCallingIdentity();
8487 try {
8488 if (phone != null) {
8489 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8490 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008491 }
8492 } finally {
8493 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008494 }
8495 }
Shuo Qiandd210312017-04-12 22:11:33 +00008496
Tyler Gunn65d45c22017-06-05 11:22:26 -07008497 private boolean isUssdApiAllowed(int subId) {
8498 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008499 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008500 if (configManager == null) {
8501 return false;
8502 }
8503 PersistableBundle pb = configManager.getConfigForSubId(subId);
8504 if (pb == null) {
8505 return false;
8506 }
8507 return pb.getBoolean(
8508 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8509 }
8510
Shuo Qiandd210312017-04-12 22:11:33 +00008511 /**
8512 * Check if phone is in emergency callback mode
8513 * @return true if phone is in emergency callback mode
8514 * @param subId sub id
8515 */
goneil9c5f4872017-12-05 14:07:56 -08008516 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008517 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008518 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008519 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520
8521 final long identity = Binder.clearCallingIdentity();
8522 try {
8523 if (phone != null) {
8524 return phone.isInEcm();
8525 } else {
8526 return false;
8527 }
8528 } finally {
8529 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008530 }
8531 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008532
8533 /**
8534 * Get the current signal strength information for the given subscription.
8535 * Because this information is not updated when the device is in a low power state
8536 * it should not be relied-upon to be current.
8537 * @param subId Subscription index
8538 * @return the most recent cached signal strength info from the modem
8539 */
8540 @Override
8541 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008542 final long identity = Binder.clearCallingIdentity();
8543 try {
8544 Phone p = getPhone(subId);
8545 if (p == null) {
8546 return null;
8547 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008549 return p.getSignalStrength();
8550 } finally {
8551 Binder.restoreCallingIdentity(identity);
8552 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008553 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008554
Pengquan Meng77b7f132018-08-22 14:49:57 -07008555 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008556 * Get the current modem radio state for the given slot.
8557 * @param slotIndex slot index.
8558 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008559 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008560 * @return the current radio power state from the modem
8561 */
8562 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008563 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008564 Phone phone = PhoneFactory.getPhone(slotIndex);
8565 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8567 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008568 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8569 }
8570
8571 final long identity = Binder.clearCallingIdentity();
8572 try {
8573 return phone.getRadioPowerState();
8574 } finally {
8575 Binder.restoreCallingIdentity(identity);
8576 }
8577 }
8578 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8579 }
8580
8581 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008582 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8583 *
8584 * <p>Requires one of the following permissions:
8585 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8586 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8587 * privileges.
8588 *
8589 * @param subId subscription id
8590 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8591 * {@code false}.
8592 */
8593 @Override
8594 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008595 try {
8596 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8597 null);
8598 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008599 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008600 mApp, subId, "isDataRoamingEnabled");
8601 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008602
Pengquan Menga1bb6272018-09-06 09:59:22 -07008603 boolean isEnabled = false;
8604 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008605 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008606 Phone phone = getPhone(subId);
8607 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008608 } finally {
8609 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008610 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008611 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008612 }
8613
8614
8615 /**
8616 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8617 *
8618 * <p> Requires permission:
8619 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8620 * privileges.
8621 *
8622 * @param subId subscription id
8623 * @param isEnabled {@code true} means enable, {@code false} means disable.
8624 */
8625 @Override
8626 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8628 mApp, subId, "setDataRoamingEnabled");
8629
Pengquan Menga1bb6272018-09-06 09:59:22 -07008630 final long identity = Binder.clearCallingIdentity();
8631 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008632 Phone phone = getPhone(subId);
8633 if (phone != null) {
8634 phone.setDataRoamingEnabled(isEnabled);
8635 }
8636 } finally {
8637 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008638 }
8639 }
8640
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008641 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008642 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008643 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008644 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008645 mApp, subId, "isManualNetworkSelectionAllowed");
8646
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008647 boolean isAllowed = true;
8648 final long identity = Binder.clearCallingIdentity();
8649 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008650 Phone phone = getPhone(subId);
8651 if (phone != null) {
8652 isAllowed = phone.isCspPlmnEnabled();
8653 }
8654 } finally {
8655 Binder.restoreCallingIdentity(identity);
8656 }
8657 return isAllowed;
8658 }
8659
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008660 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8661 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8662 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8663 // Update each UiccPort object based on privilege access
8664 UiccPort[] uiccPorts = card.getUiccPortList();
8665 for (UiccPort port : uiccPorts) {
8666 UiccProfile profile = port.getUiccProfile();
8667 if (profile == null ||
8668 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8669 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8670 return false;
8671 }
8672 }
8673 return true;
8674 }
8675
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008676 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008677 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008678 // Verify that tha callingPackage belongs to the calling UID
8679 mApp.getSystemService(AppOpsManager.class)
8680 .checkPackage(Binder.getCallingUid(), callingPackage);
8681
Jordan Liu1e142fc2019-04-22 15:10:43 -07008682 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008683 try {
8684 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008685 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008686 } catch (SecurityException e) {
8687 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8688 // has carrier privileges on an active UICC
8689 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8690 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008691 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008692 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008693 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008694
8695 final long identity = Binder.clearCallingIdentity();
8696 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008697 UiccController uiccController = UiccController.getInstance();
8698 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008699 if (hasReadPermission) {
8700 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008701 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008702
8703 // Remove private info if the caller doesn't have access
8704 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8705 for (UiccCardInfo cardInfo : cardInfos) {
8706 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8707 // is available
8708 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008709 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8710 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8711 if (card == null || card.getUiccPortList().length == 0) {
8712 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008713 filteredInfos.add(cardInfo.getUnprivileged());
8714 continue;
8715 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008716
8717 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008718 filteredInfos.add(cardInfo);
8719 } else {
8720 filteredInfos.add(cardInfo.getUnprivileged());
8721 }
8722 }
8723 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008724 } finally {
8725 Binder.restoreCallingIdentity(identity);
8726 }
8727 }
8728
8729 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008730 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008731 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008733 final long identity = Binder.clearCallingIdentity();
8734 try {
8735 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8736 if (slots == null) {
8737 Rlog.i(LOG_TAG, "slots is null.");
8738 return null;
8739 }
8740
8741 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8742 for (int i = 0; i < slots.length; i++) {
8743 UiccSlot slot = slots[i];
8744 if (slot == null) {
8745 continue;
8746 }
8747
Jordan Liu7be7e652019-05-06 18:55:02 +00008748 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008749 UiccCard card = slot.getUiccCard();
8750 if (card != null) {
8751 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008752 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008753 cardId = slot.getEid();
8754 if (TextUtils.isEmpty(cardId)) {
8755 cardId = slot.getIccId();
8756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008757 }
8758
Jordan Liu857451f2019-05-09 16:35:35 -07008759 if (cardId != null) {
8760 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8761 // if cardId is an EID, it's all digits so this is fine
8762 cardId = IccUtils.stripTrailingFs(cardId);
8763 }
8764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008765 int cardState = 0;
8766 switch (slot.getCardState()) {
8767 case CARDSTATE_ABSENT:
8768 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8769 break;
8770 case CARDSTATE_PRESENT:
8771 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8772 break;
8773 case CARDSTATE_ERROR:
8774 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8775 break;
8776 case CARDSTATE_RESTRICTED:
8777 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8778 break;
8779 default:
8780 break;
8781
8782 }
8783
8784 infos[i] = new UiccSlotInfo(
8785 slot.isActive(),
8786 slot.isEuicc(),
8787 cardId,
8788 cardState,
8789 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008790 slot.isExtendedApduSupported(),
8791 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008792 }
8793 return infos;
8794 } finally {
8795 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008796 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008797 }
8798
8799 @Override
8800 public boolean switchSlots(int[] physicalSlots) {
8801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008802
8803 final long identity = Binder.clearCallingIdentity();
8804 try {
8805 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8806 } finally {
8807 Binder.restoreCallingIdentity(identity);
8808 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008809 }
Jack Yu4c988042018-02-27 15:30:01 -08008810
8811 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008812 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008813 final long identity = Binder.clearCallingIdentity();
8814 try {
8815 return UiccController.getInstance().getCardIdForDefaultEuicc();
8816 } finally {
8817 Binder.restoreCallingIdentity(identity);
8818 }
8819 }
8820
Pengquan Meng85728fb2018-03-12 16:31:21 -07008821 /**
goneil47ffb6e2018-04-06 15:40:58 -07008822 * A test API to reload the UICC profile.
8823 *
8824 * <p>Requires that the calling app has permission
8825 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8826 * @hide
8827 */
8828 @Override
8829 public void refreshUiccProfile(int subId) {
8830 enforceModifyPermission();
8831
8832 final long identity = Binder.clearCallingIdentity();
8833 try {
8834 Phone phone = getPhone(subId);
8835 if (phone == null) {
8836 return;
8837 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008838 UiccPort uiccPort = phone.getUiccPort();
8839 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008840 return;
8841 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008842 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008843 if (uiccProfile == null) {
8844 return;
8845 }
8846 uiccProfile.refresh();
8847 } finally {
8848 Binder.restoreCallingIdentity(identity);
8849 }
8850 }
8851
8852 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008853 * Returns false if the mobile data is disabled by default, otherwise return true.
8854 */
8855 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008856 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008857 }
8858
8859 /**
8860 * Returns true if the data roaming is enabled by default, i.e the system property
8861 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8862 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8863 */
8864 private boolean getDefaultDataRoamingEnabled(int subId) {
8865 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008866 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008867 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008868 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8869 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8870 return isDataRoamingEnabled;
8871 }
8872
8873 /**
8874 * Returns the default network type for the given {@code subId}, if the default network type is
8875 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8876 */
8877 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008878 List<Integer> list = TelephonyProperties.default_network();
8879 int phoneId = mSubscriptionController.getPhoneId(subId);
8880 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8881 return list.get(phoneId);
8882 }
8883 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008884 }
fionaxua13278b2018-03-21 00:08:13 -07008885
8886 @Override
8887 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008888 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008889 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008890
8891 final long identity = Binder.clearCallingIdentity();
8892 try {
8893 final Phone phone = getPhone(subId);
8894 if (phone == null) {
8895 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8896 return;
8897 }
chen xueaba88a2019-03-15 13:15:10 -07008898 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8899 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008900 if (carrierPrivilegeRules == null) {
8901 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8902 } else {
8903 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008905 } finally {
8906 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008907 }
fionaxua13278b2018-03-21 00:08:13 -07008908 }
8909
8910 @Override
8911 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008912 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008913
8914 final long identity = Binder.clearCallingIdentity();
8915 try {
8916 final Phone phone = getPhone(subId);
8917 if (phone == null) {
8918 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8919 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8920 }
8921 return phone.getCarrierIdListVersion();
8922 } finally {
8923 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008924 }
fionaxua13278b2018-03-21 00:08:13 -07008925 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008926
8927 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008928 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8929 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008931 mApp, subId, callingPackage, callingFeatureId,
8932 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008933 return -1;
8934 }
8935
8936 final long identity = Binder.clearCallingIdentity();
8937 try {
8938 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8939 } finally {
8940 Binder.restoreCallingIdentity(identity);
8941 }
8942 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008943
8944 @Override
8945 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008946 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008947 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008948 mApp, subId, "getCdmaRoamingMode");
8949
8950 final long identity = Binder.clearCallingIdentity();
8951 try {
8952 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8953 } finally {
8954 Binder.restoreCallingIdentity(identity);
8955 }
8956 }
8957
8958 @Override
8959 public boolean setCdmaRoamingMode(int subId, int mode) {
8960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8961 mApp, subId, "setCdmaRoamingMode");
8962
8963 final long identity = Binder.clearCallingIdentity();
8964 try {
8965 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8966 } finally {
8967 Binder.restoreCallingIdentity(identity);
8968 }
8969 }
8970
8971 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008972 public int getCdmaSubscriptionMode(int subId) {
8973 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008974 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008975 mApp, subId, "getCdmaSubscriptionMode");
8976
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
8983 }
8984
8985 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008986 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8988 mApp, subId, "setCdmaSubscriptionMode");
8989
8990 final long identity = Binder.clearCallingIdentity();
8991 try {
8992 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8993 } finally {
8994 Binder.restoreCallingIdentity(identity);
8995 }
8996 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008997
sqianc5eccab2018-10-19 18:46:41 -07008998 @Override
sqian8c685422019-02-22 15:55:18 -08008999 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009000 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009002 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9003 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009004 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9005 }
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
sqian854d44b2018-12-12 16:48:18 -08009008 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9009 for (Phone phone: PhoneFactory.getPhones()) {
9010 if (phone.getEmergencyNumberTracker() != null
9011 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9012 emergencyNumberListInternal.put(
9013 phone.getSubId(),
9014 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9015 }
sqian11b7a0e2018-12-05 18:48:28 -08009016 }
sqian854d44b2018-12-12 16:48:18 -08009017 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009018 } finally {
9019 Binder.restoreCallingIdentity(identity);
9020 }
sqianc5eccab2018-10-19 18:46:41 -07009021 }
9022
9023 @Override
sqian8c685422019-02-22 15:55:18 -08009024 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009025 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009026 if (!exactMatch) {
9027 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009028 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009029 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009030 }
9031 final long identity = Binder.clearCallingIdentity();
9032 try {
sqian854d44b2018-12-12 16:48:18 -08009033 for (Phone phone: PhoneFactory.getPhones()) {
9034 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009035 && phone.getEmergencyNumberTracker()
9036 .isEmergencyNumber(number, exactMatch)) {
9037 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009038 }
sqian11b7a0e2018-12-05 18:48:28 -08009039 }
9040 return false;
9041 } finally {
9042 Binder.restoreCallingIdentity(identity);
9043 }
9044 }
9045
sqianf4ca7ed2019-01-15 18:32:07 -08009046 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009047 * Start emergency callback mode for GsmCdmaPhone for testing.
9048 */
9049 @Override
9050 public void startEmergencyCallbackMode() {
9051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9052 "startEmergencyCallbackMode");
9053 enforceModifyPermission();
9054 final long identity = Binder.clearCallingIdentity();
9055 try {
9056 for (Phone phone : PhoneFactory.getPhones()) {
9057 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9058 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9059 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9060 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9061 gsmCdmaPhone.obtainMessage(
9062 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9063 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9064 }
9065 }
9066 } finally {
9067 Binder.restoreCallingIdentity(identity);
9068 }
9069 }
9070
9071 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009072 * Update emergency number list for test mode.
9073 */
9074 @Override
9075 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9076 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9077 "updateEmergencyNumberListTestMode");
9078
9079 final long identity = Binder.clearCallingIdentity();
9080 try {
9081 for (Phone phone: PhoneFactory.getPhones()) {
9082 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9083 if (tracker != null) {
9084 tracker.executeEmergencyNumberTestModeCommand(action, num);
9085 }
9086 }
9087 } finally {
9088 Binder.restoreCallingIdentity(identity);
9089 }
9090 }
9091
9092 /**
9093 * Get the full emergency number list for test mode.
9094 */
9095 @Override
9096 public List<String> getEmergencyNumberListTestMode() {
9097 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9098 "getEmergencyNumberListTestMode");
9099
9100 final long identity = Binder.clearCallingIdentity();
9101 try {
9102 Set<String> emergencyNumbers = new HashSet<>();
9103 for (Phone phone: PhoneFactory.getPhones()) {
9104 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9105 if (tracker != null) {
9106 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9107 emergencyNumbers.add(num.getNumber());
9108 }
9109 }
9110 }
9111 return new ArrayList<>(emergencyNumbers);
9112 } finally {
9113 Binder.restoreCallingIdentity(identity);
9114 }
9115 }
9116
chen xud6b45bd2018-10-30 22:27:10 -07009117 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009118 public int getEmergencyNumberDbVersion(int subId) {
9119 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9120
9121 final long identity = Binder.clearCallingIdentity();
9122 try {
9123 final Phone phone = getPhone(subId);
9124 if (phone == null) {
9125 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9126 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9127 }
9128 return phone.getEmergencyNumberDbVersion();
9129 } finally {
9130 Binder.restoreCallingIdentity(identity);
9131 }
9132 }
9133
9134 @Override
9135 public void notifyOtaEmergencyNumberDbInstalled() {
9136 enforceModifyPermission();
9137
9138 final long identity = Binder.clearCallingIdentity();
9139 try {
9140 for (Phone phone: PhoneFactory.getPhones()) {
9141 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9142 if (tracker != null) {
9143 tracker.updateOtaEmergencyNumberDatabase();
9144 }
9145 }
9146 } finally {
9147 Binder.restoreCallingIdentity(identity);
9148 }
9149 }
9150
9151 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009152 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009153 enforceActiveEmergencySessionPermission();
9154
9155 final long identity = Binder.clearCallingIdentity();
9156 try {
9157 for (Phone phone: PhoneFactory.getPhones()) {
9158 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9159 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009160 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9161 }
9162 }
9163 } finally {
9164 Binder.restoreCallingIdentity(identity);
9165 }
9166 }
9167
9168 @Override
9169 public void resetOtaEmergencyNumberDbFilePath() {
9170 enforceActiveEmergencySessionPermission();
9171
9172 final long identity = Binder.clearCallingIdentity();
9173 try {
9174 for (Phone phone: PhoneFactory.getPhones()) {
9175 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9176 if (tracker != null) {
9177 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009178 }
9179 }
9180 } finally {
9181 Binder.restoreCallingIdentity(identity);
9182 }
9183 }
9184
9185 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009186 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9187 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9188 Phone phone = getPhone(subId);
9189 if (phone == null) {
9190 return null;
9191 }
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
9194 UiccProfile profile = UiccController.getInstance()
9195 .getUiccProfileForPhone(phone.getPhoneId());
9196 if (profile != null) {
9197 return profile.getCertsFromCarrierPrivilegeAccessRules();
9198 }
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
9202 return null;
9203 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009204
9205 /**
9206 * Enable or disable a modem stack.
9207 */
9208 @Override
9209 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9210 enforceModifyPermission();
9211
9212 final long identity = Binder.clearCallingIdentity();
9213 try {
9214 Phone phone = PhoneFactory.getPhone(slotIndex);
9215 if (phone == null) {
9216 return false;
9217 } else {
9218 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9219 }
9220 } finally {
9221 Binder.restoreCallingIdentity(identity);
9222 }
9223 }
Michelecea4cf22018-12-21 15:00:11 -08009224
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009225 /**
9226 * Whether a modem stack is enabled or not.
9227 */
9228 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009229 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9230 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009231 Phone phone = PhoneFactory.getPhone(slotIndex);
9232 if (phone == null) return false;
9233
9234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009235 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9236 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009237 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9238 }
9239
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009242 try {
9243 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9244 } catch (NoSuchElementException ex) {
9245 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9246 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
9250 }
9251
Michelecea4cf22018-12-21 15:00:11 -08009252 @Override
Michele0ea7d782019-03-19 14:58:42 -07009253 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009254 enforceModifyPermission();
9255
9256 final long identity = Binder.clearCallingIdentity();
9257 try {
9258 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009259 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009260 .commit();
9261 } finally {
9262 Binder.restoreCallingIdentity(identity);
9263 }
9264 }
9265
9266 @Override
Michele0ea7d782019-03-19 14:58:42 -07009267 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009268 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009270 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9271 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009272 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009273 }
Michelecea4cf22018-12-21 15:00:11 -08009274
9275 final long identity = Binder.clearCallingIdentity();
9276 try {
Michele0ea7d782019-03-19 14:58:42 -07009277 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009278 } finally {
9279 Binder.restoreCallingIdentity(identity);
9280 }
9281 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009282
Michele0ea7d782019-03-19 14:58:42 -07009283 @TelephonyManager.IsMultiSimSupportedResult
9284 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009285 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9286 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9287 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009288 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9289 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009290 }
9291 // Check if the hardware supports multisim functionality. If usage of multisim is not
9292 // supported by the modem, indicate that it is restricted.
9293 PhoneCapability staticCapability =
9294 mPhoneConfigurationManager.getStaticPhoneCapability();
9295 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009296 loge("isMultiSimSupportedInternal: no static configuration available");
9297 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009298 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009299 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009300 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9301 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009302 }
9303 // Check if support of multiple SIMs is restricted by carrier
9304 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009305 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009306 }
9307
Michele0ea7d782019-03-19 14:58:42 -07009308 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009309 }
9310
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009311 /**
9312 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009313 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9314 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9315 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009316 * @param numOfSims number of active sims we want to switch to
9317 */
9318 @Override
9319 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009320 if (numOfSims == 1) {
9321 enforceModifyPermission();
9322 } else {
9323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9324 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9325 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009326 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009327
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009328 try {
Michele30b57b22019-03-01 12:01:14 -08009329 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009330 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009331 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9332 return;
9333 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009334 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9335 } finally {
9336 Binder.restoreCallingIdentity(identity);
9337 }
9338 }
9339
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009340 @Override
9341 public boolean isApplicationOnUicc(int subId, int appType) {
9342 enforceReadPrivilegedPermission("isApplicationOnUicc");
9343 Phone phone = getPhone(subId);
9344 if (phone == null) {
9345 return false;
9346 }
9347 final long identity = Binder.clearCallingIdentity();
9348 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009349 UiccPort uiccPort = phone.getUiccPort();
9350 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009351 return false;
9352 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009353 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009354 if (uiccProfile == null) {
9355 return false;
9356 }
9357 if (TelephonyManager.APPTYPE_SIM <= appType
9358 && appType <= TelephonyManager.APPTYPE_ISIM) {
9359 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9360 }
9361 return false;
9362 } finally {
9363 Binder.restoreCallingIdentity(identity);
9364 }
9365 }
9366
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009367 /**
chen xub4baa772019-04-03 10:23:41 -07009368 * Get whether making changes to modem configurations will trigger reboot.
9369 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009370 */
9371 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009372 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9373 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009375 mApp, subId, callingPackage, callingFeatureId,
9376 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009377 return false;
9378 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009379 final long identity = Binder.clearCallingIdentity();
9380 try {
9381 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9382 } finally {
9383 Binder.restoreCallingIdentity(identity);
9384 }
9385 }
9386
Nathan Harold29f5f052019-02-15 13:41:57 -08009387 private void updateModemStateMetrics() {
9388 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9389 // TODO: check the state for each modem if the api is ready.
9390 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9391 }
9392
Pengquan Meng3889a572019-01-23 11:16:29 -08009393 @Override
9394 public int[] getSlotsMapping() {
9395 enforceReadPrivilegedPermission("getSlotsMapping");
9396
9397 final long identity = Binder.clearCallingIdentity();
9398 try {
9399 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9400 // All logical slots should have a mapping to a physical slot.
9401 int[] logicalSlotsMapping = new int[phoneCount];
9402 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9403 for (int i = 0; i < slotInfos.length; i++) {
9404 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9405 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9406 }
9407 }
9408 return logicalSlotsMapping;
9409 } finally {
9410 Binder.restoreCallingIdentity(identity);
9411 }
9412 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009413
9414 /**
9415 * Get the IRadio HAL Version
9416 */
9417 @Override
9418 public int getRadioHalVersion() {
9419 Phone phone = getDefaultPhone();
9420 if (phone == null) return -1;
9421 HalVersion hv = phone.getHalVersion();
9422 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9423 return hv.major * 100 + hv.minor;
9424 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009425
9426 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009427 * Get the current calling package name.
9428 * @return the current calling package name
9429 */
9430 @Override
9431 public String getCurrentPackageName() {
9432 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9433 }
9434
9435 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009436 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9437 * corresponding network requests on a subId.
9438 *
9439 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009440 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009441 * 2) APN is un-metered for this subscription, or
9442 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009443 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009444 *
9445 * @return whether data is allowed for a apn type.
9446 *
9447 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009448 */
9449 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009450 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009451 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9452 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009453
9454 // Now that all security checks passes, perform the operation as ourselves.
9455 final long identity = Binder.clearCallingIdentity();
9456 try {
9457 Phone phone = getPhone(subId);
9458 if (phone == null) return false;
9459
Jack Yu41407ee2019-05-13 16:54:09 -07009460 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009461 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9462 } finally {
9463 Binder.restoreCallingIdentity(identity);
9464 }
9465 }
9466
9467 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009468 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009469 enforceReadPrivilegedPermission("isApnMetered");
9470
9471 // Now that all security checks passes, perform the operation as ourselves.
9472 final long identity = Binder.clearCallingIdentity();
9473 try {
9474 Phone phone = getPhone(subId);
9475 if (phone == null) return true; // By default return true.
9476
Jack Yu41407ee2019-05-13 16:54:09 -07009477 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009478 } finally {
9479 Binder.restoreCallingIdentity(identity);
9480 }
9481 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009482
9483 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009484 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9485 int subscriptionId, IBooleanConsumer resultCallback) {
9486 enforceModifyPermission();
9487 long token = Binder.clearCallingIdentity();
9488 try {
9489 Phone phone = getPhone(subscriptionId);
9490 if (phone == null) {
9491 try {
9492 if (resultCallback != null) {
9493 resultCallback.accept(false);
9494 }
9495 } catch (RemoteException e) {
9496 // ignore
9497 }
9498 return;
9499 }
9500 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9501 Pair.create(specifiers, (x) -> {
9502 try {
9503 if (resultCallback != null) {
9504 resultCallback.accept(x);
9505 }
9506 } catch (RemoteException e) {
9507 // ignore
9508 }
9509 });
9510 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9511 } finally {
9512 Binder.restoreCallingIdentity(token);
9513 }
9514 }
9515
9516 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009517 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9518 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009519 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009520 mApp, subId, "getSystemSelectionChannels");
9521 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9522 final long identity = Binder.clearCallingIdentity();
9523 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009524 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9525 if (result instanceof IllegalStateException) {
9526 throw (IllegalStateException) result;
9527 }
9528 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009529 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9530 return specifiers;
9531 } finally {
9532 Binder.restoreCallingIdentity(identity);
9533 }
9534 }
9535
9536 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009537 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009538 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009539 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9540 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9541 if (iccRecords == null) {
9542 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9543 return false;
9544 }
9545 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9546 }
9547
9548 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009549 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9550 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009551 if (callingPackage == null) {
9552 callingPackage = getCurrentPackageName();
9553 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009554 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9555 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009556 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9557 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009558 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9559 }
9560 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9561 Intent intent = new Intent();
9562 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9563 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9564 // Bring up choose default SMS subscription dialog right now
9565 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9566 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9567 mApp.startActivity(intent);
9568 }
chen xud5ca2d52019-05-28 15:20:57 -07009569
9570 @Override
9571 public String getMmsUAProfUrl(int subId) {
9572 //TODO investigate if this API should require proper permission check in R b/133791609
9573 final long identity = Binder.clearCallingIdentity();
9574 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009575 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9576 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9577 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9578 return carrierUAProfUrl;
9579 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009580 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9581 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009582 } finally {
9583 Binder.restoreCallingIdentity(identity);
9584 }
9585 }
9586
9587 @Override
9588 public String getMmsUserAgent(int subId) {
9589 //TODO investigate if this API should require proper permission check in R b/133791609
9590 final long identity = Binder.clearCallingIdentity();
9591 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009592 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9593 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9594 if (!TextUtils.isEmpty(carrierUserAgent)) {
9595 return carrierUserAgent;
9596 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009597 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9598 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602 }
Jack Yub07d4972019-05-28 16:12:25 -07009603
9604 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009605 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9606 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009607
Jack Yub07d4972019-05-28 16:12:25 -07009608 final long identity = Binder.clearCallingIdentity();
9609 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009610 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009611 if (phone == null) return false;
9612
Hall Liua62f5da2020-09-25 10:42:19 -07009613 switch (policy) {
9614 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9615 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9616 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9617 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9618 default:
9619 throw new IllegalArgumentException(policy + " is not a valid policy");
9620 }
Jack Yub07d4972019-05-28 16:12:25 -07009621 } finally {
9622 Binder.restoreCallingIdentity(identity);
9623 }
9624 }
9625
9626 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009627 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009628 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009629 enforceModifyPermission();
9630
changbettyd5c246e2019-12-24 15:40:37 +08009631 final long identity = Binder.clearCallingIdentity();
9632 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009633 Phone phone = getPhone(subscriptionId);
9634 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009635
Hall Liua62f5da2020-09-25 10:42:19 -07009636 switch (policy) {
9637 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9638 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9639 break;
9640 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9641 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9642 break;
9643 default:
9644 throw new IllegalArgumentException(policy + " is not a valid policy");
9645 }
changbettyd5c246e2019-12-24 15:40:37 +08009646 } finally {
9647 Binder.restoreCallingIdentity(identity);
9648 }
9649 }
9650
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009651 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009652 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009653 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9654 * otherwise.
9655 */
9656 @Override
9657 public void setCepEnabled(boolean isCepEnabled) {
9658 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9659
9660 final long identity = Binder.clearCallingIdentity();
9661 try {
9662 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9663 for (Phone phone : PhoneFactory.getPhones()) {
9664 Phone defaultPhone = phone.getImsPhone();
9665 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9666 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9667 ImsPhoneCallTracker imsPhoneCallTracker =
9668 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9669 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9670 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9671 + imsPhone.getMsisdn());
9672 }
9673 }
9674 } finally {
9675 Binder.restoreCallingIdentity(identity);
9676 }
9677 }
allenwtsu46dcc572020-01-08 18:24:03 +08009678
9679 /**
9680 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9681 *
9682 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9683 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9684 * before being read.
9685 */
9686 @Override
9687 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9688 isCompressed) {
9689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9690 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009691 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9692 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9693 }
9694 if (!isImsAvailableOnDevice()) {
9695 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9696 "IMS not available on device.");
9697 }
9698
9699 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009700 try {
Hui Wang761a6682020-10-31 05:12:53 +00009701 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9702 } finally {
9703 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009704 }
9705 }
zoey chene02881a2019-12-30 16:11:23 +08009706
9707 @Override
9708 public boolean isIccLockEnabled(int subId) {
9709 enforceReadPrivilegedPermission("isIccLockEnabled");
9710
9711 // Now that all security checks passes, perform the operation as ourselves.
9712 final long identity = Binder.clearCallingIdentity();
9713 try {
9714 Phone phone = getPhone(subId);
9715 if (phone != null && phone.getIccCard() != null) {
9716 return phone.getIccCard().getIccLockEnabled();
9717 } else {
9718 return false;
9719 }
9720 } finally {
9721 Binder.restoreCallingIdentity(identity);
9722 }
9723 }
9724
9725 /**
9726 * Set the ICC pin lock enabled or disabled.
9727 *
9728 * @return an integer representing the status of IccLock enabled or disabled in the following
9729 * three cases:
9730 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9731 * successfully.
9732 * - Positive number and zero for remaining password attempts.
9733 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9734 *
9735 */
9736 @Override
9737 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9738 enforceModifyPermission();
9739
9740 Phone phone = getPhone(subId);
9741 if (phone == null) {
9742 return 0;
9743 }
9744 // Now that all security checks passes, perform the operation as ourselves.
9745 final long identity = Binder.clearCallingIdentity();
9746 try {
9747 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9748 new Pair<Boolean, String>(enabled, password), phone, null);
9749 return attemptsRemaining;
9750
9751 } catch (Exception e) {
9752 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9753 } finally {
9754 Binder.restoreCallingIdentity(identity);
9755 }
9756 return 0;
9757 }
9758
9759 /**
9760 * Change the ICC password used in ICC pin lock.
9761 *
9762 * @return an integer representing the status of IccLock changed in the following three cases:
9763 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9764 * - Positive number and zero for remaining password attempts.
9765 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9766 *
9767 */
9768 @Override
9769 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9770 enforceModifyPermission();
9771
9772 Phone phone = getPhone(subId);
9773 if (phone == null) {
9774 return 0;
9775 }
9776 // Now that all security checks passes, perform the operation as ourselves.
9777 final long identity = Binder.clearCallingIdentity();
9778 try {
9779 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9780 new Pair<String, String>(oldPassword, newPassword), phone, null);
9781 return attemptsRemaining;
9782
9783 } catch (Exception e) {
9784 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9785 } finally {
9786 Binder.restoreCallingIdentity(identity);
9787 }
9788 return 0;
9789 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009790
9791 /**
9792 * Request for receiving user activity notification
9793 */
9794 @Override
9795 public void requestUserActivityNotification() {
9796 if (!mNotifyUserActivity.get()
9797 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9798 mNotifyUserActivity.set(true);
9799 }
9800 }
9801
9802 /**
9803 * Called when userActivity is signalled in the power manager.
9804 * This is safe to call from any thread, with any window manager locks held or not.
9805 */
9806 @Override
9807 public void userActivity() {
9808 // ***************************************
9809 // * Inherited from PhoneWindowManager *
9810 // ***************************************
9811 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9812 // WITH ITS LOCKS HELD.
9813 //
9814 // This code must be VERY careful about the locks
9815 // it acquires.
9816 // In fact, the current code acquires way too many,
9817 // and probably has lurking deadlocks.
9818
9819 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9820 throw new SecurityException("Only the OS may call notifyUserActivity()");
9821 }
9822
9823 if (mNotifyUserActivity.getAndSet(false)) {
9824 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9825 USER_ACTIVITY_NOTIFICATION_DELAY);
9826 }
9827 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009828
9829 @Override
9830 public boolean canConnectTo5GInDsdsMode() {
9831 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9832 }
Jack Yud10cdd42020-09-28 20:28:01 -07009833
9834 @Override
9835 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9836 String callingFeatureId) {
9837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9838 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9839 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9840 }
9841
9842 Phone phone = getPhone(subId);
9843 if (phone == null) {
9844 throw new RuntimeException("phone is not available");
9845 }
9846 // Now that all security checks passes, perform the operation as ourselves.
9847 final long identity = Binder.clearCallingIdentity();
9848 try {
9849 return phone.getEquivalentHomePlmns();
9850 } finally {
9851 Binder.restoreCallingIdentity(identity);
9852 }
9853 }
Daniel Bright59e67312020-11-13 11:49:37 -08009854
9855 @Override
9856 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009857 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9858 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009859 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009860 if (radioInterfaceCapabilities == null) {
9861 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009862 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009863 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009864 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009865
Hui Wang641e81c2020-10-12 12:14:23 -07009866 @Override
9867 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9868 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009869 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9870 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9871 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9872 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9873 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009874 if (DBG) {
9875 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9876 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9877 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9878 }
9879
9880 if (!SubscriptionManager.isValidSubscriptionId(subId)
9881 || appType < TelephonyManager.APPTYPE_UNKNOWN
9882 || appType > TelephonyManager.APPTYPE_ISIM
9883 || nafUrl == null || securityProtocol == null || callback == null) {
9884 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9885 if (callback != null) {
9886 try {
9887 callback.onAuthenticationFailure(
9888 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9889 } catch (RemoteException exception) {
9890 log("Fail to notify onAuthenticationFailure due to " + exception);
9891 }
9892 return;
9893 }
9894 }
9895
9896 final long token = Binder.clearCallingIdentity();
9897 try {
9898 getGbaManager(subId).bootstrapAuthenticationRequest(
9899 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9900 forceBootStrapping, callback));
9901 } finally {
9902 Binder.restoreCallingIdentity(token);
9903 }
9904 }
9905
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009906 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009907 * Attempts to set the radio power state for all phones for thermal reason.
9908 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009909 * requested radio power state will actually be set. See {@link
9910 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9911 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009912 * @param enable {@code true} if trying to turn radio on.
9913 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9914 * false}.
9915 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009916 private boolean setRadioPowerForThermal(boolean enable) {
9917 boolean isPhoneAvailable = false;
9918 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9919 Phone phone = PhoneFactory.getPhone(i);
9920 if (phone != null) {
9921 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9922 isPhoneAvailable = true;
9923 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009924 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009925
9926 // return true if successfully informed the phone object about the thermal radio power
9927 // request.
9928 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009929 }
9930
9931 private int handleDataThrottlingRequest(int subId,
9932 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009933 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9934 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9935 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9936 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9937 throw new IllegalArgumentException("modem does not support data throttling");
9938 }
9939
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009940 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9941 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009942 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009943 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9944 }
9945
9946 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9947
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009948 if (isDataThrottlingSupported) {
9949 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009950 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009951 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9952 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9953 } else if (thermalMitigationResult
9954 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009955 log("Modem likely does not support data throttling on secondary carrier. Data " +
9956 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9957 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009958 }
9959 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009960 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009961
9962 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009963 }
9964
Jack Nudelman644b91a2021-03-12 14:09:48 -08009965 private static List<String> getThermalMitigationAllowlist(Context context) {
9966 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9967 for (String pckg : context.getResources()
9968 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9969 sThermalMitigationAllowlistedPackages.add(pckg);
9970 }
9971 }
9972
9973 return sThermalMitigationAllowlistedPackages;
9974 }
9975
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009976 private boolean isAnyPhoneInEmergencyState() {
9977 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9978 if (tm.isInEmergencyCall()) {
9979 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9980 return true;
9981 }
9982 for (Phone phone : PhoneFactory.getPhones()) {
9983 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9984 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9985 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9986 + phone.isInEcm());
9987 return true;
9988 }
9989 }
9990
9991 return false;
9992 }
9993
Jack Nudelman644b91a2021-03-12 14:09:48 -08009994 /**
9995 * Used by shell commands to add an authorized package name for thermal mitigation.
9996 * @param packageName name of package to be allowlisted
9997 * @param context
9998 */
9999 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10000 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10001 sThermalMitigationAllowlistedPackages.add(packageName);
10002 }
10003
10004 /**
10005 * Used by shell commands to remove an authorized package name for thermal mitigation.
10006 * @param packageName name of package to remove from allowlist
10007 * @param context
10008 */
10009 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10010 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10011 sThermalMitigationAllowlistedPackages.remove(packageName);
10012 }
10013
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010014 /**
10015 * Thermal mitigation request to control functionalities at modem.
10016 *
10017 * @param subId the id of the subscription.
10018 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010019 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010020 *
10021 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10022 */
10023 @Override
10024 @ThermalMitigationResult
10025 public int sendThermalMitigationRequest(
10026 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010027 ThermalMitigationRequest thermalMitigationRequest,
10028 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010029 enforceModifyPermission();
10030
Jack Nudelman644b91a2021-03-12 14:09:48 -080010031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10032 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10033 .contains(callingPackage)) {
10034 throw new SecurityException("Calling package must be configured in the device config. "
10035 + "calling package: " + callingPackage);
10036 }
10037
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10039 final long identity = Binder.clearCallingIdentity();
10040
10041 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10042 try {
10043 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10044 switch (thermalMitigationAction) {
10045 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10046 thermalMitigationResult =
10047 handleDataThrottlingRequest(subId,
10048 thermalMitigationRequest.getDataThrottlingRequest());
10049 break;
10050 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10051 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10052 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10053 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10054 }
10055
10056 // Ensure that radio is on. If not able to power on due to phone being
10057 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010058 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010059 thermalMitigationResult =
10060 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10061 break;
10062 }
10063
10064 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10065 false);
10066 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10067 break;
10068 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10069 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10070 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10071 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10072 }
10073
10074 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10075 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010076 Phone phone = getPhone(subId);
10077 if (phone == null) {
10078 thermalMitigationResult =
10079 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10080 break;
10081 }
10082
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010083 TelephonyConnectionService service =
10084 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010085 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010086 Log.e(LOG_TAG, "An emergency call is pending");
10087 thermalMitigationResult =
10088 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10089 break;
10090 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010091 thermalMitigationResult =
10092 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10093 break;
10094 }
10095 } else {
10096 thermalMitigationResult =
10097 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10098 break;
10099 }
10100
10101 // Turn radio off. If not able to power off due to phone being unavailable,
10102 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010103 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010104 thermalMitigationResult =
10105 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10106 break;
10107 }
10108 thermalMitigationResult =
10109 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10110 break;
10111 default:
10112 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10113 + "not exist. Requested action: " + thermalMitigationAction);
10114 }
10115 } catch (IllegalArgumentException e) {
10116 throw e;
10117 } catch (Exception e) {
10118 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10119 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10120 } finally {
10121 Binder.restoreCallingIdentity(identity);
10122 }
10123
10124 if (DBG) {
10125 log("thermalMitigationRequest returning with thermalMitigationResult: "
10126 + thermalMitigationResult);
10127 }
10128
10129 return thermalMitigationResult;
10130 }
Hui Wang641e81c2020-10-12 12:14:23 -070010131
10132 /**
10133 * Set the GbaService Package Name that Telephony will bind to.
10134 *
10135 * @param subId The sim that the GbaService is associated with.
10136 * @param packageName The name of the package to be replaced with.
10137 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10138 */
10139 @Override
10140 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10141 enforceModifyPermission();
10142
10143 final long identity = Binder.clearCallingIdentity();
10144 try {
10145 return getGbaManager(subId).overrideServicePackage(packageName);
10146 } finally {
10147 Binder.restoreCallingIdentity(identity);
10148 }
10149 }
10150
10151 /**
10152 * Return the package name of the currently bound GbaService.
10153 *
10154 * @param subId The sim that the GbaService is associated with.
10155 * @return the package name of the GbaService configuration, null if GBA is not supported.
10156 */
10157 @Override
10158 public String getBoundGbaService(int subId) {
10159 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10160
10161 final long identity = Binder.clearCallingIdentity();
10162 try {
10163 return getGbaManager(subId).getServicePackage();
10164 } finally {
10165 Binder.restoreCallingIdentity(identity);
10166 }
10167 }
10168
10169 /**
10170 * Set the release time for telephony to unbind GbaService.
10171 *
10172 * @param subId The sim that the GbaService is associated with.
10173 * @param interval The release time to unbind GbaService by millisecond.
10174 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10175 */
10176 @Override
10177 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10178 enforceModifyPermission();
10179
10180 final long identity = Binder.clearCallingIdentity();
10181 try {
10182 return getGbaManager(subId).overrideReleaseTime(interval);
10183 } finally {
10184 Binder.restoreCallingIdentity(identity);
10185 }
10186 }
10187
10188 /**
10189 * Return the release time for telephony to unbind GbaService.
10190 *
10191 * @param subId The sim that the GbaService is associated with.
10192 * @return The release time to unbind GbaService by millisecond.
10193 */
10194 @Override
10195 public int getGbaReleaseTime(int subId) {
10196 enforceReadPrivilegedPermission("getGbaReleaseTime");
10197
10198 final long identity = Binder.clearCallingIdentity();
10199 try {
10200 return getGbaManager(subId).getReleaseTime();
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
10203 }
10204 }
10205
10206 private GbaManager getGbaManager(int subId) {
10207 GbaManager instance = GbaManager.getInstance(subId);
10208 if (instance == null) {
10209 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10210 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10211 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10212 }
10213 return instance;
10214 }
Hui Wang761a6682020-10-31 05:12:53 +000010215
10216 /**
10217 * indicate whether the device and the carrier can support
10218 * RCS VoLTE single registration.
10219 */
10220 @Override
10221 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010222 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10223 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10224 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10225 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010226
10227 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10228 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10229 }
10230
10231 final long identity = Binder.clearCallingIdentity();
10232 try {
10233 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10234 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010235 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10236 if (isCapable != null) {
10237 return isCapable;
10238 }
Hui Wang761a6682020-10-31 05:12:53 +000010239 }
Hui Wang67af90e2021-06-04 16:57:15 -070010240 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10241 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010242 } finally {
10243 Binder.restoreCallingIdentity(identity);
10244 }
10245 }
10246
10247 /**
10248 * Register RCS provisioning callback.
10249 */
10250 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010251 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010252 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010253 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010254 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010255 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10256 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010257
10258 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10259 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10260 }
10261 if (!isImsAvailableOnDevice()) {
10262 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10263 "IMS not available on device.");
10264 }
10265
10266 final long identity = Binder.clearCallingIdentity();
10267 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010268 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010269 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010270 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10271 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010272 }
Hui Wang761a6682020-10-31 05:12:53 +000010273 } finally {
10274 Binder.restoreCallingIdentity(identity);
10275 }
10276 }
10277
10278 /**
10279 * Unregister RCS provisioning callback.
10280 */
10281 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010282 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010283 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010284 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010285 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010286 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10287 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010288
10289 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10290 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10291 }
10292 if (!isImsAvailableOnDevice()) {
10293 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10294 "IMS not available on device.");
10295 }
10296
10297 final long identity = Binder.clearCallingIdentity();
10298 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010299 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010300 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010301 } finally {
10302 Binder.restoreCallingIdentity(identity);
10303 }
10304 }
10305
10306 /**
10307 * trigger RCS reconfiguration.
10308 */
10309 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010310 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10311 "triggerRcsReconfiguration",
10312 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010313
10314 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10315 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10316 }
10317 if (!isImsAvailableOnDevice()) {
10318 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10319 "IMS not available on device.");
10320 }
10321
10322 final long identity = Binder.clearCallingIdentity();
10323 try {
10324 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10325 } finally {
10326 Binder.restoreCallingIdentity(identity);
10327 }
10328 }
10329
10330 /**
10331 * Provide the client configuration parameters of the RCS application.
10332 */
10333 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010334 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10335 "setRcsClientConfiguration",
10336 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010337
10338 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10339 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10340 }
10341 if (!isImsAvailableOnDevice()) {
10342 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10343 "IMS not available on device.");
10344 }
10345
10346 final long identity = Binder.clearCallingIdentity();
10347
10348 try {
10349 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10350 if (configBinder == null) {
10351 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010352 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10353 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010354 } else {
10355 configBinder.setRcsClientConfiguration(rcc);
10356 }
10357 } catch (RemoteException e) {
10358 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010359 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10360 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010361 } finally {
10362 Binder.restoreCallingIdentity(identity);
10363 }
10364 }
10365
10366 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010367 * Enables or disables the test mode for RCS VoLTE single registration.
10368 */
10369 @Override
10370 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10371 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10372 "setRcsSingleRegistrationTestModeEnabled");
10373
10374 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10375 }
10376
10377 /**
10378 * Gets the test mode for RCS VoLTE single registration.
10379 */
10380 @Override
10381 public boolean getRcsSingleRegistrationTestModeEnabled() {
10382 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10383 "getRcsSingleRegistrationTestModeEnabled");
10384
10385 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10386 }
10387
10388 /**
Hui Wang761a6682020-10-31 05:12:53 +000010389 * Overrides the config of RCS VoLTE single registration enabled for the device.
10390 */
10391 @Override
10392 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10393 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10394 "setDeviceSingleRegistrationEnabledOverride");
10395 enforceModifyPermission();
10396
10397 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10398 : Boolean.parseBoolean(enabledStr);
10399 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010400 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010401 }
10402
10403 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010404 * Sends a device to device communication message. Only usable via shell.
10405 * @param message message to send.
10406 * @param value message value.
10407 */
10408 @Override
10409 public void sendDeviceToDeviceMessage(int message, int value) {
10410 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010411 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010412 enforceModifyPermission();
10413
10414 final long identity = Binder.clearCallingIdentity();
10415 try {
10416 TelephonyConnectionService service =
10417 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10418 if (service == null) {
10419 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10420 return;
10421 }
10422 service.sendTestDeviceToDeviceMessage(message, value);
10423 } finally {
10424 Binder.restoreCallingIdentity(identity);
10425 }
10426 }
10427
Tyler Gunnbabbda02021-02-10 11:05:02 -080010428 /**
10429 * Sets the specified device to device transport active.
10430 * @param transport The transport to set active.
10431 */
10432 @Override
10433 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10434 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10435 "setActiveDeviceToDeviceTransport");
10436 enforceModifyPermission();
10437
10438 final long identity = Binder.clearCallingIdentity();
10439 try {
10440 TelephonyConnectionService service =
10441 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10442 if (service == null) {
10443 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10444 return;
10445 }
10446 service.setActiveDeviceToDeviceTransport(transport);
10447 } finally {
10448 Binder.restoreCallingIdentity(identity);
10449 }
10450 }
Tyler Gunn92479152021-01-20 16:30:10 -080010451
Tyler Gunnd4575212021-05-03 14:46:49 -070010452 @Override
10453 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10454 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10455 "setDeviceToDeviceForceEnabled");
10456
10457 final long identity = Binder.clearCallingIdentity();
10458 try {
10459 Arrays.stream(PhoneFactory.getPhones()).forEach(
10460 p -> {
10461 Phone thePhone = p.getImsPhone();
10462 if (thePhone != null && thePhone instanceof ImsPhone) {
10463 ImsPhone imsPhone = (ImsPhone) thePhone;
10464 CallTracker tracker = imsPhone.getCallTracker();
10465 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10466 ImsPhoneCallTracker imsPhoneCallTracker =
10467 (ImsPhoneCallTracker) tracker;
10468 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10469 }
10470 }
10471 }
10472 );
10473 } finally {
10474 Binder.restoreCallingIdentity(identity);
10475 }
10476 }
10477
Tyler Gunn92479152021-01-20 16:30:10 -080010478 /**
Hui Wang761a6682020-10-31 05:12:53 +000010479 * Gets the config of RCS VoLTE single registration enabled for the device.
10480 */
10481 @Override
10482 public boolean getDeviceSingleRegistrationEnabled() {
10483 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10484 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10485 }
10486
10487 /**
10488 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10489 */
10490 @Override
10491 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10492 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10493 "setCarrierSingleRegistrationEnabledOverride");
10494 enforceModifyPermission();
10495
10496 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10497 : Boolean.parseBoolean(enabledStr);
10498 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10499 subId, enabled);
10500 }
10501
10502 /**
10503 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10504 */
10505 @Override
10506 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10507 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10508 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10509 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010510
10511 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010512 * Overrides the ims feature validation result
10513 */
10514 @Override
10515 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10516 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10517 "setImsFeatureValidationOverride");
10518
10519 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10520 : Boolean.parseBoolean(enabledStr);
10521 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10522 subId, enabled);
10523 }
10524
10525 /**
10526 * Gets the ims feature validation override value
10527 */
10528 @Override
10529 public boolean getImsFeatureValidationOverride(int subId) {
10530 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10531 "getImsFeatureValidationOverride");
10532 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10533 }
10534
10535 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010536 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10537 * their mobile plan.
10538 */
10539 @Override
10540 public String getMobileProvisioningUrl() {
10541 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10542 final long identity = Binder.clearCallingIdentity();
10543 try {
10544 return getDefaultPhone().getMobileProvisioningUrl();
10545 } finally {
10546 Binder.restoreCallingIdentity(identity);
10547 }
10548 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010549
James.cf Linbcdf8b32021-01-14 16:44:13 +080010550 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010551 * Get the EAB contact from the EAB database.
10552 */
10553 @Override
10554 public String getContactFromEab(String contact) {
10555 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10556 enforceModifyPermission();
10557 final long identity = Binder.clearCallingIdentity();
10558 try {
10559 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10560 } finally {
10561 Binder.restoreCallingIdentity(identity);
10562 }
10563 }
10564
10565 /**
Calvin Pana1434322021-07-01 19:27:01 +080010566 * Get the EAB capability from the EAB database.
10567 */
10568 @Override
10569 public String getCapabilityFromEab(String contact) {
10570 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10571 enforceModifyPermission();
10572 final long identity = Binder.clearCallingIdentity();
10573 try {
10574 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10575 } finally {
10576 Binder.restoreCallingIdentity(identity);
10577 }
10578 }
10579
10580 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010581 * Remove the EAB contacts from the EAB database.
10582 */
10583 @Override
10584 public int removeContactFromEab(int subId, String contacts) {
10585 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10586 enforceModifyPermission();
10587 final long identity = Binder.clearCallingIdentity();
10588 try {
10589 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10590 } finally {
10591 Binder.restoreCallingIdentity(identity);
10592 }
10593 }
10594
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010595 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010596 public boolean getDeviceUceEnabled() {
10597 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10598 final long identity = Binder.clearCallingIdentity();
10599 try {
10600 return mApp.getDeviceUceEnabled();
10601 } finally {
10602 Binder.restoreCallingIdentity(identity);
10603 }
10604 }
10605
10606 @Override
10607 public void setDeviceUceEnabled(boolean isEnabled) {
10608 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 mApp.setDeviceUceEnabled(isEnabled);
10612 } finally {
10613 Binder.restoreCallingIdentity(identity);
10614 }
10615 }
10616
Brad Ebinger14d467f2021-02-12 06:18:28 +000010617 /**
10618 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10619 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10620 */
10621 // Used for SHELL command only right now.
10622 @Override
10623 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10624 List<String> featureTags) {
10625 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10626 "addUceRegistrationOverrideShell");
10627 final long identity = Binder.clearCallingIdentity();
10628 try {
10629 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10630 new ArraySet<>(featureTags));
10631 } catch (ImsException e) {
10632 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10633 } finally {
10634 Binder.restoreCallingIdentity(identity);
10635 }
10636 }
10637
10638 /**
10639 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10640 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10641 */
10642 // Used for SHELL command only right now.
10643 @Override
10644 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10645 List<String> featureTags) {
10646 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10647 "removeUceRegistrationOverrideShell");
10648 final long identity = Binder.clearCallingIdentity();
10649 try {
10650 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10651 new ArraySet<>(featureTags));
10652 } catch (ImsException e) {
10653 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10654 } finally {
10655 Binder.restoreCallingIdentity(identity);
10656 }
10657 }
10658
10659 /**
10660 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
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 clearUceRegistrationOverrideShell(int subId) {
10666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10667 "clearUceRegistrationOverrideShell");
10668 final long identity = Binder.clearCallingIdentity();
10669 try {
10670 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10671 } catch (ImsException e) {
10672 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10673 } finally {
10674 Binder.restoreCallingIdentity(identity);
10675 }
10676 }
10677
10678 /**
10679 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10680 */
10681 // Used for SHELL command only right now.
10682 @Override
10683 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10685 "getLatestRcsContactUceCapabilityShell");
10686 final long identity = Binder.clearCallingIdentity();
10687 try {
10688 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10689 } catch (ImsException e) {
10690 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10691 } finally {
10692 Binder.restoreCallingIdentity(identity);
10693 }
10694 }
10695
10696 /**
10697 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10698 * device does not have an active PUBLISH.
10699 */
10700 // Used for SHELL command only right now.
10701 @Override
10702 public String getLastUcePidfXmlShell(int subId) {
10703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10704 final long identity = Binder.clearCallingIdentity();
10705 try {
10706 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10707 } catch (ImsException e) {
10708 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10709 } finally {
10710 Binder.restoreCallingIdentity(identity);
10711 }
10712 }
10713
James.cf Line8713a42021-04-29 16:04:26 +080010714 /**
10715 * Remove UCE requests cannot be sent to the network status.
10716 */
10717 // Used for SHELL command only right now.
10718 @Override
10719 public boolean removeUceRequestDisallowedStatus(int subId) {
10720 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10721 final long identity = Binder.clearCallingIdentity();
10722 try {
10723 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10724 } catch (ImsException e) {
10725 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10726 } finally {
10727 Binder.restoreCallingIdentity(identity);
10728 }
10729 }
10730
James.cf Lin0fc71b02021-05-25 01:37:38 +080010731 /**
10732 * Remove UCE requests cannot be sent to the network status.
10733 */
10734 // Used for SHELL command only.
10735 @Override
10736 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10737 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10738 final long identity = Binder.clearCallingIdentity();
10739 try {
10740 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10741 } catch (ImsException e) {
10742 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10743 } finally {
10744 Binder.restoreCallingIdentity(identity);
10745 }
10746 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010747
James.cf Lin4b784aa2021-01-31 03:25:15 +080010748 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010749 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10750 String callingPackage) {
10751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10752 mApp, subId, "setSignalStrengthUpdateRequest");
10753
10754 final int callingUid = Binder.getCallingUid();
10755 // Verify that tha callingPackage belongs to the calling UID
10756 mApp.getSystemService(AppOpsManager.class)
10757 .checkPackage(callingUid, callingPackage);
10758
Rambo Wang3607f502021-02-01 21:51:40 -080010759 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010760
10761 final long identity = Binder.clearCallingIdentity();
10762 try {
10763 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10764 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10765
10766 if (result instanceof IllegalStateException) {
10767 throw (IllegalStateException) result;
10768 }
10769 } finally {
10770 Binder.restoreCallingIdentity(identity);
10771 }
10772 }
10773
10774 @Override
10775 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10776 String callingPackage) {
10777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10778 mApp, subId, "clearSignalStrengthUpdateRequest");
10779
10780 final int callingUid = Binder.getCallingUid();
10781 // Verify that tha callingPackage belongs to the calling UID
10782 mApp.getSystemService(AppOpsManager.class)
10783 .checkPackage(callingUid, callingPackage);
10784
10785 final long identity = Binder.clearCallingIdentity();
10786 try {
10787 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10788 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10789
10790 if (result instanceof IllegalStateException) {
10791 throw (IllegalStateException) result;
10792 }
10793 } finally {
10794 Binder.restoreCallingIdentity(identity);
10795 }
10796 }
10797
Rambo Wang3607f502021-02-01 21:51:40 -080010798 private static void validateSignalStrengthUpdateRequest(Context context,
10799 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010800 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10801 // phone/system process do not have further restriction on request
10802 return;
10803 }
10804
10805 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010806 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010807 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010808 context.enforceCallingOrSelfPermission(
10809 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10810 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010811 }
10812
10813 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10814 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10815 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10816 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10817 || info.isEnabled()) {
10818 throw new IllegalArgumentException(
10819 "Only system can set hide fields in SignalThresholdInfo");
10820 }
10821
10822 // Thresholds length for each RAN need in range. This has been validated in
10823 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10824 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10825 final int[] thresholds = info.getThresholds();
10826 Objects.requireNonNull(thresholds);
10827 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10828 || thresholds.length
10829 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10830 throw new IllegalArgumentException(
10831 "thresholds length is out of range: " + thresholds.length);
10832 }
10833 }
10834 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010835
10836 /**
10837 * Gets the current phone capability.
10838 *
10839 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10840 * @return the PhoneCapability which describes the data connection capability of modem.
10841 * It's used to evaluate possible phone config change, for example from single
10842 * SIM device to multi-SIM device.
10843 */
10844 @Override
10845 public PhoneCapability getPhoneCapability() {
10846 enforceReadPrivilegedPermission("getPhoneCapability");
10847 final long identity = Binder.clearCallingIdentity();
10848 try {
10849 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10850 } finally {
10851 Binder.restoreCallingIdentity(identity);
10852 }
10853 }
Michele Berionne5e411512020-11-13 02:36:59 +000010854
10855 /**
10856 * Prepare TelephonyManager for an unattended reboot. The reboot is
10857 * required to be done shortly after the API is invoked.
10858 */
10859 @Override
10860 @TelephonyManager.PrepareUnattendedRebootResult
10861 public int prepareForUnattendedReboot() {
10862 enforceRebootPermission();
10863
10864 final long identity = Binder.clearCallingIdentity();
10865 try {
10866 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10867 } finally {
10868 Binder.restoreCallingIdentity(identity);
10869 }
10870 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010871
10872 /**
10873 * Request to get the current slicing configuration including URSP rules and
10874 * NSSAIs (configured, allowed and rejected).
10875 *
10876 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10877 */
10878 @Override
10879 public void getSlicingConfig(ResultReceiver callback) {
10880 enforceReadPrivilegedPermission("getSlicingConfig");
10881
10882 final long identity = Binder.clearCallingIdentity();
10883 try {
10884 Phone phone = getDefaultPhone();
10885 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10886 } finally {
10887 Binder.restoreCallingIdentity(identity);
10888 }
10889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010890}