blob: 71a3f145b678bbfd42fc52fe92cbb2a6d6c8cdfe [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
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Hall Liu82694d52020-12-11 18:22:04 -080029import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070030import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070031import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.content.Context;
33import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070034import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080067import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080068import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070069import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070080import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070081import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070082import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080083import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070084import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070086import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080087import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080088import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070089import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.RadioAccessSpecifier;
Daniel Bright59e67312020-11-13 11:49:37 -080091import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080093import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080094import android.telephony.SignalStrengthUpdateRequest;
95import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080096import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080098import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070099import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700100import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800102import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800103import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000104import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700105import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800107import android.telephony.data.ApnSetting;
108import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.gba.GbaAuthRequest;
110import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700111import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000113import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700114import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700117import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000120import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700121import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800123import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800125import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700128import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800130import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800131
Andrew Lee312e8172014-10-23 17:01:36 -0700132import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800133import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800134import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800135import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700136import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700137import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700138import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800139import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800142import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700144import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800145import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800146import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700147import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800149import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800151import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700152import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700153import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700156import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800157import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700158import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700159import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700160import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700161import com.android.internal.telephony.RIL;
Jack Yu5f7092c2018-04-13 14:05:37 -0700162import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700163import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800165import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800166import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800167import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700168import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800169import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700170import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800171import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700172import com.android.internal.telephony.imsphone.ImsPhone;
173import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800174import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700175import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800177import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700180import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000184import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800185import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700186import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700187import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800188import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800189import com.android.phone.callcomposer.CallComposerPictureManager;
190import com.android.phone.callcomposer.CallComposerPictureTransfer;
191import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700192import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700193import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800194import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700195import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700196import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800197import com.android.services.telephony.TelecomAccountRegistry;
198import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800199import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800200
Hall Liu82694d52020-12-11 18:22:04 -0800201import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700202import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800203import java.io.IOException;
204import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700205import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800208import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800210import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100211import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800212import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700213import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800214import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800215import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800216import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800217import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800218import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219
220/**
221 * Implementation of the ITelephony interface.
222 */
Santos Cordon117fee72014-05-16 17:56:12 -0700223public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 private static final String LOG_TAG = "PhoneInterfaceManager";
225 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
226 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800227 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229 // Message codes used with mMainThreadHandler
230 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700231 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
232 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700233 private static final int CMD_OPEN_CHANNEL = 9;
234 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
235 private static final int CMD_CLOSE_CHANNEL = 11;
236 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800237 private static final int CMD_NV_READ_ITEM = 13;
238 private static final int EVENT_NV_READ_ITEM_DONE = 14;
239 private static final int CMD_NV_WRITE_ITEM = 15;
240 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
241 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
242 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700243 private static final int CMD_RESET_MODEM_CONFIG = 19;
244 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800245 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
246 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800247 private static final int CMD_SEND_ENVELOPE = 25;
248 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000249 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
250 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700251 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
252 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
253 private static final int CMD_EXCHANGE_SIM_IO = 31;
254 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800255 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
256 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700257 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
258 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700259 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
260 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700261 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
262 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
263 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
264 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700265 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
266 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
267 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
268 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700269 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800270 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
271 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000272 private static final int CMD_SWITCH_SLOTS = 50;
273 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700274 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
275 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
276 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
277 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
278 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
279 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
280 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
281 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700282 private static final int CMD_GET_ALL_CELL_INFO = 60;
283 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
284 private static final int CMD_GET_CELL_LOCATION = 62;
285 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700286 private static final int CMD_MODEM_REBOOT = 64;
287 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700288 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
289 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800290 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
291 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700292 private static final int CMD_GET_MODEM_STATUS = 70;
293 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700294 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
295 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700296 private static final int CMD_ERASE_MODEM_CONFIG = 74;
297 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800298 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
299 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
300 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
301 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800302 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
303 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800304 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800305 private static final int CMD_GET_CALL_FORWARDING = 83;
306 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
307 private static final int CMD_SET_CALL_FORWARDING = 85;
308 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
309 private static final int CMD_GET_CALL_WAITING = 87;
310 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
311 private static final int CMD_SET_CALL_WAITING = 89;
312 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700313 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
314 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
315 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
316 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700317 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
318 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800319 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
320 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800321 private static final int CMD_SET_DATA_THROTTLING = 99;
322 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800323 private static final int CMD_SET_SIM_POWER = 101;
324 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800325 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
326 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
327 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
328 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800329 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
330 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000331 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800333 // Parameters of select command.
334 private static final int SELECT_COMMAND = 0xA4;
335 private static final int SELECT_P1 = 0x04;
336 private static final int SELECT_P2 = 0;
337 private static final int SELECT_P3 = 0x10;
338
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 /** The singleton instance. */
340 private static PhoneInterfaceManager sInstance;
341
Wink Saville3ab207e2014-11-20 13:07:20 -0800342 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800344 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700345 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800346 private AppOpsManager mAppOps;
347 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800348 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800349 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700350 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351
Peter Wangdafb9ac2020-01-15 14:13:38 -0800352 /** User Activity */
353 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800354 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
355
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700356 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
357
Derek Tan97ebb422014-09-05 16:55:38 -0700358 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
359 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800360 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800361 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700362
Michelecea4cf22018-12-21 15:00:11 -0800363 // String to store multi SIM allowed
364 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
365
Derek Tan740e1672017-06-27 14:56:27 -0700366 // The AID of ISD-R.
367 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
368
yinxub1bed742017-04-17 11:45:04 -0700369 private NetworkScanRequestTracker mNetworkScanRequestTracker;
370
David Kelly5e06a7f2018-03-12 14:10:59 +0000371 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
372 private static final int MANUFACTURER_CODE_LENGTH = 8;
373
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800374 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
375
Derek Tan89e89d42014-07-08 17:00:10 -0700376 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700377 * Experiment flag to enable erase modem config on reset network, default value is false
378 */
379 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
380 "reset_network_erase_modem_config_enabled";
381
382 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700383 * A request object to use for transmitting data to an ICC.
384 */
385 private static final class IccAPDUArgument {
386 public int channel, cla, command, p1, p2, p3;
387 public String data;
388
389 public IccAPDUArgument(int channel, int cla, int command,
390 int p1, int p2, int p3, String data) {
391 this.channel = channel;
392 this.cla = cla;
393 this.command = command;
394 this.p1 = p1;
395 this.p2 = p2;
396 this.p3 = p3;
397 this.data = data;
398 }
399 }
400
401 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700402 * A request object to use for transmitting data to an ICC.
403 */
404 private static final class ManualNetworkSelectionArgument {
405 public OperatorInfo operatorInfo;
406 public boolean persistSelection;
407
408 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
409 this.operatorInfo = operatorInfo;
410 this.persistSelection = persistSelection;
411 }
412 }
413
414 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
416 * request after sending. The main thread will notify the request when it is complete.
417 */
418 private static final class MainThreadRequest {
419 /** The argument to use for the request */
420 public Object argument;
421 /** The result of the request that is run on the main thread */
422 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800423 // The subscriber id that this request applies to. Defaults to
424 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
425 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426
Nathan Harold92bed182018-10-12 18:16:49 -0700427 // In cases where subId is unavailable, the caller needs to specify the phone.
428 public Phone phone;
429
vagdeviaf9a5b92018-08-15 16:01:53 -0700430 public WorkSource workSource;
431
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 public MainThreadRequest(Object argument) {
433 this.argument = argument;
434 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800435
Nathan Harold92bed182018-10-12 18:16:49 -0700436 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
437 this.argument = argument;
438 if (phone != null) {
439 this.phone = phone;
440 }
441 this.workSource = workSource;
442 }
443
vagdeviaf9a5b92018-08-15 16:01:53 -0700444 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800445 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800446 if (subId != null) {
447 this.subId = subId;
448 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700449 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 }
452
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800453 private static final class IncomingThirdPartyCallArgs {
454 public final ComponentName component;
455 public final String callId;
456 public final String callerDisplayName;
457
458 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
459 String callerDisplayName) {
460 this.component = component;
461 this.callId = callId;
462 this.callerDisplayName = callerDisplayName;
463 }
464 }
465
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466 /**
467 * A handler that processes messages on the main thread in the phone process. Since many
468 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
469 * inbound binder threads to the main thread in the phone process. The Binder thread
470 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
471 * on, which will be notified when the operation completes and will contain the result of the
472 * request.
473 *
474 * <p>If a MainThreadRequest object is provided in the msg.obj field,
475 * note that request.result must be set to something non-null for the calling thread to
476 * unblock.
477 */
478 private final class MainThreadHandler extends Handler {
479 @Override
480 public void handleMessage(Message msg) {
481 MainThreadRequest request;
482 Message onCompleted;
483 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800484 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800486 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487
488 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 case CMD_HANDLE_USSD_REQUEST: {
490 request = (MainThreadRequest) msg.obj;
491 final Phone phone = getPhoneFromRequest(request);
492 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
493 String ussdRequest = ussdObject.first;
494 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700495
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 if (!isUssdApiAllowed(request.subId)) {
497 // Carrier does not support use of this API, return failure.
498 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
499 UssdResponse response = new UssdResponse(ussdRequest, null);
500 Bundle returnData = new Bundle();
501 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
502 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700503
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 request.result = true;
505 notifyRequester(request);
506 return;
507 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700508
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 try {
510 request.result = phone != null
511 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
512 } catch (CallStateException cse) {
513 request.result = false;
514 }
515 // Wake up the requesting thread
516 notifyRequester(request);
517 break;
pkanwar32d516d2016-10-14 19:37:38 -0700518 }
519
Yorke Lee716f67e2015-06-17 15:39:16 -0700520 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700522 final Phone phone = getPhoneFromRequest(request);
523 request.result = phone != null ?
524 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
525 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700532 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700535 if (uiccCard == null) {
536 loge("iccTransmitApduLogicalChannel: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
541 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 iccArgument.channel, iccArgument.cla, iccArgument.command,
544 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 break;
548
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
552 if (ar.exception == null && ar.result != null) {
553 request.result = ar.result;
554 } else {
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
556 if (ar.result == null) {
557 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800558 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800560 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 } else {
562 loge("iccTransmitApduLogicalChannel: Unknown exception");
563 }
564 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 break;
567
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
569 request = (MainThreadRequest) msg.obj;
570 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800571 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 if (uiccCard == null) {
573 loge("iccTransmitApduBasicChannel: No UICC");
574 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700575 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 } else {
577 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
578 request);
579 uiccCard.iccTransmitApduBasicChannel(
580 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
581 iccArgument.p3, iccArgument.data, onCompleted);
582 }
583 break;
584
585 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
586 ar = (AsyncResult) msg.obj;
587 request = (MainThreadRequest) ar.userObj;
588 if (ar.exception == null && ar.result != null) {
589 request.result = ar.result;
590 } else {
591 request.result = new IccIoResult(0x6F, 0, (byte[])null);
592 if (ar.result == null) {
593 loge("iccTransmitApduBasicChannel: Empty response");
594 } else if (ar.exception instanceof CommandException) {
595 loge("iccTransmitApduBasicChannel: CommandException: " +
596 ar.exception);
597 } else {
598 loge("iccTransmitApduBasicChannel: Unknown exception");
599 }
600 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 break;
603
604 case CMD_EXCHANGE_SIM_IO:
605 request = (MainThreadRequest) msg.obj;
606 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800607 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 if (uiccCard == null) {
609 loge("iccExchangeSimIO: No UICC");
610 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 } else {
613 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
614 request);
615 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
616 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
617 iccArgument.data, onCompleted);
618 }
619 break;
620
621 case EVENT_EXCHANGE_SIM_IO_DONE:
622 ar = (AsyncResult) msg.obj;
623 request = (MainThreadRequest) ar.userObj;
624 if (ar.exception == null && ar.result != null) {
625 request.result = ar.result;
626 } else {
627 request.result = new IccIoResult(0x6f, 0, (byte[])null);
628 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 break;
631
Derek Tan4d5e5c12014-02-04 11:54:58 -0800632 case CMD_SEND_ENVELOPE:
633 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800634 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 if (uiccCard == null) {
636 loge("sendEnvelopeWithStatus: No UICC");
637 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 } else {
640 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
641 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
642 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800643 break;
644
645 case EVENT_SEND_ENVELOPE_DONE:
646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700648 if (ar.exception == null && ar.result != null) {
649 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800650 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700651 request.result = new IccIoResult(0x6F, 0, (byte[])null);
652 if (ar.result == null) {
653 loge("sendEnvelopeWithStatus: Empty response");
654 } else if (ar.exception instanceof CommandException) {
655 loge("sendEnvelopeWithStatus: CommandException: " +
656 ar.exception);
657 } else {
658 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
659 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800660 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700661 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800662 break;
663
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 case CMD_OPEN_CHANNEL:
665 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800666 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800667 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 if (uiccCard == null) {
669 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800670 request.result = new IccOpenLogicalChannelResponse(-1,
671 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700673 } else {
674 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800675 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
676 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 break;
679
680 case EVENT_OPEN_CHANNEL_DONE:
681 ar = (AsyncResult) msg.obj;
682 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 int[] result = (int[]) ar.result;
686 int channelId = result[0];
687 byte[] selectResponse = null;
688 if (result.length > 1) {
689 selectResponse = new byte[result.length - 1];
690 for (int i = 1; i < result.length; ++i) {
691 selectResponse[i - 1] = (byte) result[i];
692 }
693 }
694 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700695 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 if (ar.result == null) {
698 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 if (ar.exception != null) {
701 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
702 }
703
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700704 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700705 if (ar.exception instanceof CommandException) {
706 CommandException.Error error =
707 ((CommandException) (ar.exception)).getCommandError();
708 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700709 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700710 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700711 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700712 }
713 }
714 openChannelResp = new IccOpenLogicalChannelResponse(
715 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700717 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 break;
720
721 case CMD_CLOSE_CHANNEL:
722 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800723 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700724 if (uiccCard == null) {
725 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900726 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700728 } else {
729 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
730 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
731 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700732 break;
733
734 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800735 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
736 break;
737
738 case CMD_NV_READ_ITEM:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800741 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
742 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800743 break;
744
745 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700746 ar = (AsyncResult) msg.obj;
747 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800748 if (ar.exception == null && ar.result != null) {
749 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800751 request.result = "";
752 if (ar.result == null) {
753 loge("nvReadItem: Empty response");
754 } else if (ar.exception instanceof CommandException) {
755 loge("nvReadItem: CommandException: " +
756 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800758 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 }
760 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 break;
763
Jake Hambye994d462014-02-03 13:10:13 -0800764 case CMD_NV_WRITE_ITEM:
765 request = (MainThreadRequest) msg.obj;
766 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
767 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800768 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700769 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800770 break;
771
772 case EVENT_NV_WRITE_ITEM_DONE:
773 handleNullReturnEvent(msg, "nvWriteItem");
774 break;
775
776 case CMD_NV_WRITE_CDMA_PRL:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800779 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800780 break;
781
782 case EVENT_NV_WRITE_CDMA_PRL_DONE:
783 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
784 break;
785
chen xu6dac5ab2018-10-26 17:39:23 -0700786 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800787 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700788 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800789 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800790 break;
791
chen xu6dac5ab2018-10-26 17:39:23 -0700792 case EVENT_RESET_MODEM_CONFIG_DONE:
793 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800794 break;
795
Sooraj Sasindran37444802020-08-11 10:40:43 -0700796 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
797 request = (MainThreadRequest) msg.obj;
798 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
799 request);
800 Phone phone = getPhoneFromRequest(request);
801 if (phone != null) {
802 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
803 } else {
804 loge("isNRDualConnectivityEnabled: No phone object");
805 request.result = false;
806 notifyRequester(request);
807 }
808 break;
809 }
810
811 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
812 ar = (AsyncResult) msg.obj;
813 request = (MainThreadRequest) ar.userObj;
814 if (ar.exception == null && ar.result != null) {
815 request.result = ar.result;
816 } else {
817 // request.result must be set to something non-null
818 // for the calling thread to unblock
819 if (request.result != null) {
820 request.result = ar.result;
821 } else {
822 request.result = false;
823 }
824 if (ar.result == null) {
825 loge("isNRDualConnectivityEnabled: Empty response");
826 } else if (ar.exception instanceof CommandException) {
827 loge("isNRDualConnectivityEnabled: CommandException: "
828 + ar.exception);
829 } else {
830 loge("isNRDualConnectivityEnabled: Unknown exception");
831 }
832 }
833 notifyRequester(request);
834 break;
835
836 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
837 request = (MainThreadRequest) msg.obj;
838 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
839 Phone phone = getPhoneFromRequest(request);
840 if (phone != null) {
841 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
842 request.workSource);
843 } else {
844 loge("enableNrDualConnectivity: No phone object");
845 request.result =
846 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
847 notifyRequester(request);
848 }
849 break;
850 }
851
852 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null) {
856 request.result =
857 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
858 } else {
859 request.result =
860 TelephonyManager
861 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
862 if (ar.exception instanceof CommandException) {
863 CommandException.Error error =
864 ((CommandException) (ar.exception)).getCommandError();
865 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
866 request.result =
867 TelephonyManager
868 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
869 }
870 loge("enableNrDualConnectivity" + ": CommandException: "
871 + ar.exception);
872 } else {
873 loge("enableNrDualConnectivity" + ": Unknown exception");
874 }
875 }
876 notifyRequester(request);
877 break;
878 }
879
SongFerngWang3ef3e072020-12-21 16:41:52 +0800880 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800881 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800882 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
883 request);
884 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800885 break;
886
SongFerngWang3ef3e072020-12-21 16:41:52 +0800887 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800888 ar = (AsyncResult) msg.obj;
889 request = (MainThreadRequest) ar.userObj;
890 if (ar.exception == null && ar.result != null) {
891 request.result = ar.result; // Integer
892 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530893 // request.result must be set to something non-null
894 // for the calling thread to unblock
895 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800897 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800898 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800899 loge("getAllowedNetworkTypesBitmask: CommandException: "
900 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800902 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 }
904 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700905 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 break;
907
SongFerngWang3ef3e072020-12-21 16:41:52 +0800908 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800909 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800910 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
911 request);
912 Pair<Integer, Long> reasonWithNetworkTypes =
913 (Pair<Integer, Long>) request.argument;
914 getPhoneFromRequest(request).setAllowedNetworkTypes(
915 reasonWithNetworkTypes.first,
916 reasonWithNetworkTypes.second,
917 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 break;
919
SongFerngWang3ef3e072020-12-21 16:41:52 +0800920 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
921 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800922 break;
923
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000924 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
925 request = (MainThreadRequest)msg.obj;
926 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800927 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000928 break;
929
930 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
931 ar = (AsyncResult)msg.obj;
932 request = (MainThreadRequest)ar.userObj;
933 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700934 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000935 break;
936
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800937 case CMD_SET_VOICEMAIL_NUMBER:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
940 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800941 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
942 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800943 break;
944
945 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
946 handleNullReturnEvent(msg, "setVoicemailNumber");
947 break;
948
Stuart Scott54788802015-03-30 13:18:01 -0700949 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
952 request);
953 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
954 break;
955
956 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
957 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
958 break;
959
Shishir Agrawal302c8692015-06-19 13:49:39 -0700960 case CMD_PERFORM_NETWORK_SCAN:
961 request = (MainThreadRequest) msg.obj;
962 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
963 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
964 break;
965
Hall Liu27d24262020-09-18 19:04:59 -0700966 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700969 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
970 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
971 request.argument;
972 int callForwardingReason = args.first;
973 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800974 break;
Hall Liu27d24262020-09-18 19:04:59 -0700975 }
976 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700979 TelephonyManager.CallForwardingInfoCallback callback =
980 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
981 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800982 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700983 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800984 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
985 for (CallForwardInfo callForwardInfo : callForwardInfos) {
986 // Service Class is a bit mask per 3gpp 27.007. Search for
987 // any service for voice call.
988 if ((callForwardInfo.serviceClass
989 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700990 callForwardingInfo = new CallForwardingInfo(true,
991 callForwardInfo.reason,
992 callForwardInfo.number,
993 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800994 break;
995 }
996 }
997 // Didn't find a call forward info for voice call.
998 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700999 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1000 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001001 }
Hall Liu27d24262020-09-18 19:04:59 -07001002 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001003 } else {
1004 if (ar.result == null) {
1005 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1006 }
1007 if (ar.exception != null) {
1008 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1009 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001010 int errorCode = TelephonyManager
1011 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001012 if (ar.exception instanceof CommandException) {
1013 CommandException.Error error =
1014 ((CommandException) (ar.exception)).getCommandError();
1015 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001016 errorCode = TelephonyManager
1017 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001018 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001019 errorCode = TelephonyManager
1020 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001021 }
1022 }
Hall Liu27d24262020-09-18 19:04:59 -07001023 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001024 }
Shuo Qian4a594052020-01-23 11:59:30 -08001025 break;
Hall Liu27d24262020-09-18 19:04:59 -07001026 }
Shuo Qian4a594052020-01-23 11:59:30 -08001027
Hall Liu27d24262020-09-18 19:04:59 -07001028 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001029 request = (MainThreadRequest) msg.obj;
1030 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001031 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001032 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001033 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1034 request.argument).first;
1035 request.phone.setCallForwardingOption(
1036 callForwardingInfoToSet.isEnabled()
1037 ? CommandsInterface.CF_ACTION_ENABLE
1038 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001039 callForwardingInfoToSet.getReason(),
1040 callForwardingInfoToSet.getNumber(),
1041 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1042 break;
Hall Liu27d24262020-09-18 19:04:59 -07001043 }
Shuo Qian4a594052020-01-23 11:59:30 -08001044
Hall Liu27d24262020-09-18 19:04:59 -07001045 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001046 ar = (AsyncResult) msg.obj;
1047 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001048 Consumer<Integer> callback =
1049 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1050 request.argument).second;
1051 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001052 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001053 int errorCode = TelephonyManager.CallForwardingInfoCallback
1054 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001055 if (ar.exception instanceof CommandException) {
1056 CommandException.Error error =
1057 ((CommandException) (ar.exception)).getCommandError();
1058 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001059 errorCode = TelephonyManager.CallForwardingInfoCallback
1060 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001061 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001062 errorCode = TelephonyManager.CallForwardingInfoCallback
1063 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001064 }
1065 }
1066 callback.accept(errorCode);
1067 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001068 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001069 }
Shuo Qian4a594052020-01-23 11:59:30 -08001070 break;
Hall Liu27d24262020-09-18 19:04:59 -07001071 }
Shuo Qian4a594052020-01-23 11:59:30 -08001072
Hall Liu27d24262020-09-18 19:04:59 -07001073 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001074 request = (MainThreadRequest) msg.obj;
1075 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1076 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1077 break;
Hall Liu27d24262020-09-18 19:04:59 -07001078 }
Shuo Qian4a594052020-01-23 11:59:30 -08001079
Hall Liu27d24262020-09-18 19:04:59 -07001080 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001081 ar = (AsyncResult) msg.obj;
1082 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001083 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001084 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1085 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001086 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001087 // Service Class is a bit mask per 3gpp 27.007.
1088 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001089 if (callForwardResults.length > 1
1090 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001091 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001092 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001093 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1094 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001095 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001096 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001097 }
1098 } else {
1099 if (ar.result == null) {
1100 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1101 }
1102 if (ar.exception != null) {
1103 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1104 }
1105 if (ar.exception instanceof CommandException) {
1106 CommandException.Error error =
1107 ((CommandException) (ar.exception)).getCommandError();
1108 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1109 callForwardingStatus =
1110 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1111 }
1112 }
1113 }
Hall Liu27d24262020-09-18 19:04:59 -07001114 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001115 break;
Hall Liu27d24262020-09-18 19:04:59 -07001116 }
Shuo Qian4a594052020-01-23 11:59:30 -08001117
Hall Liu27d24262020-09-18 19:04:59 -07001118 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001119 request = (MainThreadRequest) msg.obj;
1120 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001121 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1122 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001123 break;
Hall Liu27d24262020-09-18 19:04:59 -07001124 }
Shuo Qian4a594052020-01-23 11:59:30 -08001125
Hall Liu27d24262020-09-18 19:04:59 -07001126 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001129 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1130 Consumer<Integer> callback =
1131 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1132 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001133 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001134 if (ar.exception instanceof CommandException) {
1135 CommandException.Error error =
1136 ((CommandException) (ar.exception)).getCommandError();
1137 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1138 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1139 } else {
1140 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1141 }
1142 } else {
1143 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1144 }
1145 } else {
1146 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1147 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001148 }
Shuo Qian4a594052020-01-23 11:59:30 -08001149 break;
Hall Liu27d24262020-09-18 19:04:59 -07001150 }
Shuo Qian4a594052020-01-23 11:59:30 -08001151
Shishir Agrawal302c8692015-06-19 13:49:39 -07001152 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
1155 CellNetworkScanResult cellScanResult;
1156 if (ar.exception == null && ar.result != null) {
1157 cellScanResult = new CellNetworkScanResult(
1158 CellNetworkScanResult.STATUS_SUCCESS,
1159 (List<OperatorInfo>) ar.result);
1160 } else {
1161 if (ar.result == null) {
1162 loge("getCellNetworkScanResults: Empty response");
1163 }
1164 if (ar.exception != null) {
1165 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1166 }
1167 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1168 if (ar.exception instanceof CommandException) {
1169 CommandException.Error error =
1170 ((CommandException) (ar.exception)).getCommandError();
1171 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1172 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1173 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1174 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1175 }
1176 }
1177 cellScanResult = new CellNetworkScanResult(errorCode, null);
1178 }
1179 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001180 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001181 break;
1182
1183 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1184 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001185 ManualNetworkSelectionArgument selArg =
1186 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001187 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1188 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001189 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1190 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001191 break;
1192
1193 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001194 ar = (AsyncResult) msg.obj;
1195 request = (MainThreadRequest) ar.userObj;
1196 if (ar.exception == null) {
1197 request.result = true;
1198 } else {
1199 request.result = false;
1200 loge("setNetworkSelectionModeManual " + ar.exception);
1201 }
1202 notifyRequester(request);
1203 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001204 break;
1205
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001206 case CMD_GET_MODEM_ACTIVITY_INFO:
1207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001209 if (defaultPhone != null) {
1210 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001211 } else {
1212 ResultReceiver result = (ResultReceiver) request.argument;
1213 Bundle bundle = new Bundle();
1214 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001215 new ModemActivityInfo(0, 0, 0,
1216 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001217 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001218 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001219 break;
1220
Hall Liud0f208c2020-10-14 16:54:44 -07001221 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001222 ar = (AsyncResult) msg.obj;
1223 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001224 ResultReceiver result = (ResultReceiver) request.argument;
1225
Hall Liud0f208c2020-10-14 16:54:44 -07001226 ModemActivityInfo ret = null;
1227 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001228 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001229 // Update the last modem activity info and the result of the request.
1230 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1231 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001232 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001233 int[] txTimeMs = info.getTransmitTimeMillis();
1234 int[] lastModemTxTimeMs = mLastModemActivityInfo
1235 .getTransmitTimeMillis();
1236 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1237 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1238 }
Hall Liu49656c02020-10-09 19:00:11 -07001239 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001240 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1241 + mLastModemActivityInfo.getSleepTimeMillis());
1242 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1243 + mLastModemActivityInfo.getIdleTimeMillis());
1244 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1245 mLastModemActivityInfo.setReceiveTimeMillis(
1246 info.getReceiveTimeMillis()
1247 + mLastModemActivityInfo.getReceiveTimeMillis());
1248 }
Hall Liu49656c02020-10-09 19:00:11 -07001249 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001250 mLastModemActivityInfo.getSleepTimeMillis(),
1251 mLastModemActivityInfo.getIdleTimeMillis(),
1252 mLastModemActivityInfo.getTransmitTimeMillis(),
1253 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001254 } else {
1255 if (ar.result == null) {
1256 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001257 error = TelephonyManager.ModemActivityInfoException
1258 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001259 } else if (ar.exception instanceof CommandException) {
1260 loge("queryModemActivityInfo: CommandException: " +
1261 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001262 error = TelephonyManager.ModemActivityInfoException
1263 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001264 } else {
1265 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001266 error = TelephonyManager.ModemActivityInfoException
1267 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001268 }
1269 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001270 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001271 if (ret != null) {
1272 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1273 } else {
1274 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1275 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001276 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001277 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001278 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001279 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001280
Meng Wang1a7c35a2016-05-05 20:56:15 -07001281 case CMD_SET_ALLOWED_CARRIERS:
1282 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001283 CarrierRestrictionRules argument =
1284 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001285 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001286 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001287 break;
1288
1289 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1290 ar = (AsyncResult) msg.obj;
1291 request = (MainThreadRequest) ar.userObj;
1292 if (ar.exception == null && ar.result != null) {
1293 request.result = ar.result;
1294 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001295 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1296 if (ar.exception instanceof CommandException) {
1297 loge("setAllowedCarriers: CommandException: " + ar.exception);
1298 CommandException.Error error =
1299 ((CommandException) (ar.exception)).getCommandError();
1300 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1301 request.result =
1302 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1303 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 } else {
1305 loge("setAllowedCarriers: Unknown exception");
1306 }
1307 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001308 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001309 break;
1310
1311 case CMD_GET_ALLOWED_CARRIERS:
1312 request = (MainThreadRequest) msg.obj;
1313 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001314 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001315 break;
1316
1317 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1318 ar = (AsyncResult) msg.obj;
1319 request = (MainThreadRequest) ar.userObj;
1320 if (ar.exception == null && ar.result != null) {
1321 request.result = ar.result;
1322 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001323 request.result = new IllegalStateException(
1324 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001325 if (ar.result == null) {
1326 loge("getAllowedCarriers: Empty response");
1327 } else if (ar.exception instanceof CommandException) {
1328 loge("getAllowedCarriers: CommandException: " +
1329 ar.exception);
1330 } else {
1331 loge("getAllowedCarriers: Unknown exception");
1332 }
1333 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001334 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001335 break;
1336
Nathan Haroldb3014052017-01-25 15:57:32 -08001337 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1338 ar = (AsyncResult) msg.obj;
1339 request = (MainThreadRequest) ar.userObj;
1340 if (ar.exception == null && ar.result != null) {
1341 request.result = ar.result;
1342 } else {
1343 request.result = new IllegalArgumentException(
1344 "Failed to retrieve Forbidden Plmns");
1345 if (ar.result == null) {
1346 loge("getForbiddenPlmns: Empty response");
1347 } else {
1348 loge("getForbiddenPlmns: Unknown exception");
1349 }
1350 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001351 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001352 break;
1353
1354 case CMD_GET_FORBIDDEN_PLMNS:
1355 request = (MainThreadRequest) msg.obj;
1356 uiccCard = getUiccCardFromRequest(request);
1357 if (uiccCard == null) {
1358 loge("getForbiddenPlmns() UiccCard is null");
1359 request.result = new IllegalArgumentException(
1360 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001361 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001362 break;
1363 }
1364 Integer appType = (Integer) request.argument;
1365 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1366 if (uiccApp == null) {
1367 loge("getForbiddenPlmns() no app with specified type -- "
1368 + appType);
1369 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001370 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001371 break;
1372 } else {
1373 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1374 + " specified type -- " + appType);
1375 }
1376 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1377 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1378 onCompleted);
1379 break;
1380
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001381 case CMD_SWITCH_SLOTS:
1382 request = (MainThreadRequest) msg.obj;
1383 int[] physicalSlots = (int[]) request.argument;
1384 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1385 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1386 break;
1387
1388 case EVENT_SWITCH_SLOTS_DONE:
1389 ar = (AsyncResult) msg.obj;
1390 request = (MainThreadRequest) ar.userObj;
1391 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001392 notifyRequester(request);
1393 break;
1394 case CMD_GET_NETWORK_SELECTION_MODE:
1395 request = (MainThreadRequest) msg.obj;
1396 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1397 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1398 break;
1399
1400 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 if (ar.exception != null) {
1404 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1405 } else {
1406 int mode = ((int[]) ar.result)[0];
1407 if (mode == 0) {
1408 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1409 } else {
1410 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1411 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001412 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001413 notifyRequester(request);
1414 break;
1415 case CMD_GET_CDMA_ROAMING_MODE:
1416 request = (MainThreadRequest) msg.obj;
1417 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1418 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1419 break;
1420 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 if (ar.exception != null) {
1424 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1425 } else {
1426 request.result = ((int[]) ar.result)[0];
1427 }
1428 notifyRequester(request);
1429 break;
1430 case CMD_SET_CDMA_ROAMING_MODE:
1431 request = (MainThreadRequest) msg.obj;
1432 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1433 int mode = (int) request.argument;
1434 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1435 break;
1436 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1437 ar = (AsyncResult) msg.obj;
1438 request = (MainThreadRequest) ar.userObj;
1439 request.result = ar.exception == null;
1440 notifyRequester(request);
1441 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001442 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1445 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1446 break;
1447 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception != null) {
1451 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1452 } else {
1453 request.result = ((int[]) ar.result)[0];
1454 }
1455 notifyRequester(request);
1456 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001457 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1458 request = (MainThreadRequest) msg.obj;
1459 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1460 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001461 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1462 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001463 break;
1464 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1465 ar = (AsyncResult) msg.obj;
1466 request = (MainThreadRequest) ar.userObj;
1467 request.result = ar.exception == null;
1468 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001469 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001470 case CMD_GET_ALL_CELL_INFO:
1471 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001472 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001473 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001474 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001475 case EVENT_GET_ALL_CELL_INFO_DONE:
1476 ar = (AsyncResult) msg.obj;
1477 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001478 // If a timeout occurs, the response will be null
1479 request.result = (ar.exception == null && ar.result != null)
1480 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001481 synchronized (request) {
1482 request.notifyAll();
1483 }
1484 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001485 case CMD_REQUEST_CELL_INFO_UPDATE:
1486 request = (MainThreadRequest) msg.obj;
1487 request.phone.requestCellInfoUpdate(request.workSource,
1488 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1489 break;
1490 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1491 ar = (AsyncResult) msg.obj;
1492 request = (MainThreadRequest) ar.userObj;
1493 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1494 try {
1495 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001496 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001497 cb.onError(
1498 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1499 ar.exception.getClass().getName(),
1500 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001501 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001502 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001503 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001504 } else {
1505 // use the result as returned
1506 cb.onCellInfo((List<CellInfo>) ar.result);
1507 }
1508 } catch (RemoteException re) {
1509 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1510 }
1511 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001512 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001513 request = (MainThreadRequest) msg.obj;
1514 WorkSource ws = (WorkSource) request.argument;
1515 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001516 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001517 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001518 }
1519 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001520 ar = (AsyncResult) msg.obj;
1521 request = (MainThreadRequest) ar.userObj;
1522 if (ar.exception == null) {
1523 request.result = ar.result;
1524 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001525 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001526 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001527 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001528 }
1529
1530 synchronized (request) {
1531 request.notifyAll();
1532 }
1533 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001534 }
chen xu6dac5ab2018-10-26 17:39:23 -07001535 case CMD_MODEM_REBOOT:
1536 request = (MainThreadRequest) msg.obj;
1537 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001538 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001539 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001540 case EVENT_CMD_MODEM_REBOOT_DONE:
1541 handleNullReturnEvent(msg, "rebootModem");
1542 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001543 case CMD_REQUEST_ENABLE_MODEM:
1544 request = (MainThreadRequest) msg.obj;
1545 boolean enable = (boolean) request.argument;
1546 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001547 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001548 PhoneConfigurationManager.getInstance()
1549 .enablePhone(request.phone, enable, onCompleted);
1550 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001551 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001552 ar = (AsyncResult) msg.obj;
1553 request = (MainThreadRequest) ar.userObj;
1554 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001555 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001556 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001557 if ((boolean) request.result) {
1558 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1559 updateModemStateMetrics();
1560 } else {
1561 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1562 + ar.exception);
1563 }
1564 notifyRequester(request);
1565 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001566 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001567 case CMD_GET_MODEM_STATUS:
1568 request = (MainThreadRequest) msg.obj;
1569 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1570 PhoneConfigurationManager.getInstance()
1571 .getPhoneStatusFromModem(request.phone, onCompleted);
1572 break;
1573 case EVENT_GET_MODEM_STATUS_DONE:
1574 ar = (AsyncResult) msg.obj;
1575 request = (MainThreadRequest) ar.userObj;
1576 int id = request.phone.getPhoneId();
1577 if (ar.exception == null && ar.result != null) {
1578 request.result = ar.result;
1579 //update the cache as modem status has changed
1580 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1581 (boolean) request.result);
1582 } else {
1583 // Return true if modem status cannot be retrieved. For most cases,
1584 // modem status is on. And for older version modems, GET_MODEM_STATUS
1585 // and disable modem are not supported. Modem is always on.
1586 // TODO: this should be fixed in R to support a third
1587 // status UNKNOWN b/131631629
1588 request.result = true;
1589 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1590 + ar.exception);
1591 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001592 notifyRequester(request);
1593 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001594 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1595 request = (MainThreadRequest) msg.obj;
1596 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1597 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1598 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1599 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1600 break;
1601 }
1602 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1603 ar = (AsyncResult) msg.obj;
1604 request = (MainThreadRequest) ar.userObj;
1605 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1606 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1607 args.second.accept(ar.exception == null);
1608 notifyRequester(request);
1609 break;
1610 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001611 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1612 request = (MainThreadRequest) msg.obj;
1613 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1614 Phone phone = getPhoneFromRequest(request);
1615 if (phone != null) {
1616 phone.getSystemSelectionChannels(onCompleted);
1617 } else {
1618 loge("getSystemSelectionChannels: No phone object");
1619 request.result = new ArrayList<RadioAccessSpecifier>();
1620 notifyRequester(request);
1621 }
1622 break;
1623 }
1624 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 if (ar.exception == null && ar.result != null) {
1628 request.result = ar.result;
1629 } else {
1630 request.result = new IllegalArgumentException(
1631 "Failed to retrieve system selection channels");
1632 if (ar.result == null) {
1633 loge("getSystemSelectionChannels: Empty response");
1634 } else {
1635 loge("getSystemSelectionChannels: Unknown exception");
1636 }
1637 }
1638 notifyRequester(request);
1639 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001640 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1641 ar = (AsyncResult) msg.obj;
1642 request = (MainThreadRequest) ar.userObj;
1643 if (ar.exception == null && ar.result != null) {
1644 request.result = ar.result;
1645 } else {
1646 request.result = -1;
1647 loge("Failed to set Forbidden Plmns");
1648 if (ar.result == null) {
1649 loge("setForbidenPlmns: Empty response");
1650 } else if (ar.exception != null) {
1651 loge("setForbiddenPlmns: Exception: " + ar.exception);
1652 request.result = -1;
1653 } else {
1654 loge("setForbiddenPlmns: Unknown exception");
1655 }
1656 }
1657 notifyRequester(request);
1658 break;
1659 case CMD_SET_FORBIDDEN_PLMNS:
1660 request = (MainThreadRequest) msg.obj;
1661 uiccCard = getUiccCardFromRequest(request);
1662 if (uiccCard == null) {
1663 loge("setForbiddenPlmns: UiccCard is null");
1664 request.result = -1;
1665 notifyRequester(request);
1666 break;
1667 }
1668 Pair<Integer, List<String>> setFplmnsArgs =
1669 (Pair<Integer, List<String>>) request.argument;
1670 appType = setFplmnsArgs.first;
1671 List<String> fplmns = setFplmnsArgs.second;
1672 uiccApp = uiccCard.getApplicationByType(appType);
1673 if (uiccApp == null) {
1674 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1675 request.result = -1;
1676 loge("Failed to get UICC App");
1677 notifyRequester(request);
1678 } else {
1679 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1680 ((SIMRecords) uiccApp.getIccRecords())
1681 .setForbiddenPlmns(onCompleted, fplmns);
1682 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001683 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001684 case CMD_ERASE_MODEM_CONFIG:
1685 request = (MainThreadRequest) msg.obj;
1686 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1687 defaultPhone.eraseModemConfig(onCompleted);
1688 break;
1689 case EVENT_ERASE_MODEM_CONFIG_DONE:
1690 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001691 break;
zoey chene02881a2019-12-30 16:11:23 +08001692
1693 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1694 request = (MainThreadRequest) msg.obj;
1695 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1696 Pair<String, String> changed = (Pair<String, String>) request.argument;
1697 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1698 changed.first, changed.second, onCompleted);
1699 break;
1700 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
1703 if (ar.exception == null) {
1704 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001705 // If the operation is successful, update the PIN storage
1706 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1707 int phoneId = getPhoneFromRequest(request).getPhoneId();
1708 UiccController.getInstance().getPinStorage()
1709 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001710 } else {
1711 request.result = msg.arg1;
1712 }
1713 notifyRequester(request);
1714 break;
1715
Michele Berionne5e411512020-11-13 02:36:59 +00001716 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001717 request = (MainThreadRequest) msg.obj;
1718 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1719 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1720 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1721 enabled.first, enabled.second, onCompleted);
1722 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001723 }
zoey chene02881a2019-12-30 16:11:23 +08001724 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1725 ar = (AsyncResult) msg.obj;
1726 request = (MainThreadRequest) ar.userObj;
1727 if (ar.exception == null) {
1728 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001729 // If the operation is successful, update the PIN storage
1730 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1731 int phoneId = getPhoneFromRequest(request).getPhoneId();
1732 if (enabled.first) {
1733 UiccController.getInstance().getPinStorage()
1734 .storePin(enabled.second, phoneId);
1735 } else {
1736 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1737 }
zoey chene02881a2019-12-30 16:11:23 +08001738 } else {
1739 request.result = msg.arg1;
1740 }
Michele Berionne5e411512020-11-13 02:36:59 +00001741
1742
zoey chene02881a2019-12-30 16:11:23 +08001743 notifyRequester(request);
1744 break;
1745
Peter Wangdafb9ac2020-01-15 14:13:38 -08001746 case MSG_NOTIFY_USER_ACTIVITY:
1747 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001748 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001749 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1750 getDefaultPhone().getContext().sendBroadcastAsUser(
1751 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1752 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001753
1754 case CMD_SET_DATA_THROTTLING: {
1755 request = (MainThreadRequest) msg.obj;
1756 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1757 DataThrottlingRequest dataThrottlingRequest =
1758 (DataThrottlingRequest) request.argument;
1759 Phone phone = getPhoneFromRequest(request);
1760 if (phone != null) {
1761 phone.setDataThrottling(onCompleted,
1762 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1763 dataThrottlingRequest.getCompletionDurationMillis());
1764 } else {
1765 loge("setDataThrottling: No phone object");
1766 request.result =
1767 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1768 notifyRequester(request);
1769 }
1770
1771 break;
1772 }
1773 case EVENT_SET_DATA_THROTTLING_DONE:
1774 ar = (AsyncResult) msg.obj;
1775 request = (MainThreadRequest) ar.userObj;
1776
1777 if (ar.exception == null) {
1778 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1779 } else if (ar.exception instanceof CommandException) {
1780 loge("setDataThrottling: CommandException: " + ar.exception);
1781 CommandException.Error error =
1782 ((CommandException) (ar.exception)).getCommandError();
1783
1784 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1785 request.result = TelephonyManager
1786 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1787 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1788 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1789 } else {
1790 request.result =
1791 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1792 }
1793 } else {
1794 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1795 }
1796 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1797 notifyRequester(request);
1798 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001799
1800 case CMD_SET_SIM_POWER: {
1801 request = (MainThreadRequest) msg.obj;
1802 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1803 request = (MainThreadRequest) msg.obj;
1804 int stateToSet =
1805 ((Pair<Integer, IIntegerConsumer>)
1806 request.argument).first;
1807 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1808 break;
1809 }
1810 case EVENT_SET_SIM_POWER_DONE: {
1811 ar = (AsyncResult) msg.obj;
1812 request = (MainThreadRequest) ar.userObj;
1813 IIntegerConsumer callback =
1814 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1815 if (ar.exception != null) {
1816 loge("setSimPower exception: " + ar.exception);
1817 int errorCode = TelephonyManager.CallForwardingInfoCallback
1818 .RESULT_ERROR_UNKNOWN;
1819 if (ar.exception instanceof CommandException) {
1820 CommandException.Error error =
1821 ((CommandException) (ar.exception)).getCommandError();
1822 if (error == CommandException.Error.SIM_ERR) {
1823 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1824 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1825 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1826 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1827 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1828 } else {
1829 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1830 }
1831 }
1832 try {
1833 callback.accept(errorCode);
1834 } catch (RemoteException e) {
1835 // Ignore if the remote process is no longer available to call back.
1836 Log.w(LOG_TAG, "setSimPower: callback not available.");
1837 }
1838 } else {
1839 try {
1840 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1841 } catch (RemoteException e) {
1842 // Ignore if the remote process is no longer available to call back.
1843 Log.w(LOG_TAG, "setSimPower: callback not available.");
1844 }
1845 }
1846 break;
1847 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001848 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1849 request = (MainThreadRequest) msg.obj;
1850
1851 final Phone phone = getPhoneFromRequest(request);
1852 if (phone == null || phone.getServiceStateTracker() == null) {
1853 request.result = new IllegalStateException("Phone or SST is null");
1854 notifyRequester(request);
1855 break;
1856 }
1857
1858 Pair<Integer, SignalStrengthUpdateRequest> pair =
1859 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1860 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1861 request);
1862 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1863 request.subId, pair.first /*callingUid*/,
1864 pair.second /*request*/, onCompleted);
1865 break;
1866 }
1867 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1868 ar = (AsyncResult) msg.obj;
1869 request = (MainThreadRequest) ar.userObj;
1870 // request.result will be the exception of ar if present, true otherwise.
1871 // Be cautious not to leave result null which will wait() forever
1872 request.result = ar.exception != null ? ar.exception : true;
1873 notifyRequester(request);
1874 break;
1875 }
1876 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1877 request = (MainThreadRequest) msg.obj;
1878
1879 Phone phone = getPhoneFromRequest(request);
1880 if (phone == null || phone.getServiceStateTracker() == null) {
1881 request.result = new IllegalStateException("Phone or SST is null");
1882 notifyRequester(request);
1883 break;
1884 }
1885
1886 Pair<Integer, SignalStrengthUpdateRequest> pair =
1887 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1888 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1889 request);
1890 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1891 request.subId, pair.first /*callingUid*/,
1892 pair.second /*request*/, onCompleted);
1893 break;
1894 }
1895 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 request.result = ar.exception != null ? ar.exception : true;
1899 notifyRequester(request);
1900 break;
1901 }
Jordan Liu109698e2020-11-24 14:50:34 -08001902
Michele Berionne5e411512020-11-13 02:36:59 +00001903 case CMD_PREPARE_UNATTENDED_REBOOT:
1904 request = (MainThreadRequest) msg.obj;
1905 request.result =
1906 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1907 notifyRequester(request);
1908 break;
1909
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 default:
1911 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1912 break;
1913 }
1914 }
Jake Hambye994d462014-02-03 13:10:13 -08001915
Pengquan Menga1bb6272018-09-06 09:59:22 -07001916 private void notifyRequester(MainThreadRequest request) {
1917 synchronized (request) {
1918 request.notifyAll();
1919 }
1920 }
1921
Jake Hambye994d462014-02-03 13:10:13 -08001922 private void handleNullReturnEvent(Message msg, String command) {
1923 AsyncResult ar = (AsyncResult) msg.obj;
1924 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1925 if (ar.exception == null) {
1926 request.result = true;
1927 } else {
1928 request.result = false;
1929 if (ar.exception instanceof CommandException) {
1930 loge(command + ": CommandException: " + ar.exception);
1931 } else {
1932 loge(command + ": Unknown exception");
1933 }
1934 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001935 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 }
1938
1939 /**
1940 * Posts the specified command to be executed on the main thread,
1941 * waits for the request to complete, and returns the result.
1942 * @see #sendRequestAsync
1943 */
1944 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001945 return sendRequest(
1946 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001947 }
1948
1949 /**
1950 * Posts the specified command to be executed on the main thread,
1951 * waits for the request to complete, and returns the result.
1952 * @see #sendRequestAsync
1953 */
1954 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1955 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001956 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
1959 /**
1960 * Posts the specified command to be executed on the main thread,
1961 * waits for the request to complete, and returns the result.
1962 * @see #sendRequestAsync
1963 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001964 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001965 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001966 }
1967
1968 /**
1969 * Posts the specified command to be executed on the main thread,
1970 * waits for the request to complete, and returns the result.
1971 * @see #sendRequestAsync
1972 */
Nathan Harold92bed182018-10-12 18:16:49 -07001973 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1974 return sendRequest(command, argument, subId, null, workSource);
1975 }
1976
1977 /**
1978 * Posts the specified command to be executed on the main thread,
1979 * waits for the request to complete, and returns the result.
1980 * @see #sendRequestAsync
1981 */
1982 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1983 return sendRequest(
1984 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1985 }
1986
1987 /**
1988 * Posts the specified command to be executed on the main thread,
1989 * waits for the request to complete, and returns the result.
1990 * @see #sendRequestAsync
1991 */
1992 private Object sendRequest(
1993 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1995 throw new RuntimeException("This method will deadlock if called from the main thread.");
1996 }
1997
Nathan Harold92bed182018-10-12 18:16:49 -07001998 MainThreadRequest request = null;
1999 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2000 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2001 } else if (phone != null) {
2002 request = new MainThreadRequest(argument, phone, workSource);
2003 } else {
2004 request = new MainThreadRequest(argument, subId, workSource);
2005 }
2006
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 Message msg = mMainThreadHandler.obtainMessage(command, request);
2008 msg.sendToTarget();
2009
2010 // Wait for the request to complete
2011 synchronized (request) {
2012 while (request.result == null) {
2013 try {
2014 request.wait();
2015 } catch (InterruptedException e) {
2016 // Do nothing, go back and wait until the request is complete
2017 }
2018 }
2019 }
2020 return request.result;
2021 }
2022
2023 /**
2024 * Asynchronous ("fire and forget") version of sendRequest():
2025 * Posts the specified command to be executed on the main thread, and
2026 * returns immediately.
2027 * @see #sendRequest
2028 */
2029 private void sendRequestAsync(int command) {
2030 mMainThreadHandler.sendEmptyMessage(command);
2031 }
2032
2033 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002034 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002035 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002036 */
2037 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002038 sendRequestAsync(command, argument, null, null);
2039 }
2040
2041 /**
2042 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2043 * @see {@link #sendRequest(int,Object)}
2044 */
2045 private void sendRequestAsync(
2046 int command, Object argument, Phone phone, WorkSource workSource) {
2047 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002048 Message msg = mMainThreadHandler.obtainMessage(command, request);
2049 msg.sendToTarget();
2050 }
2051
2052 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 * Initialize the singleton PhoneInterfaceManager instance.
2054 * This is only done once, at startup, from PhoneApp.onCreate().
2055 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002056 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 synchronized (PhoneInterfaceManager.class) {
2058 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002059 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 } else {
2061 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2062 }
2063 return sInstance;
2064 }
2065 }
2066
2067 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002068 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002071 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002072 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2074 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002075 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002076 mTelephonySharedPreferences =
2077 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002078 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002079 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002080 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002081
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 publish();
2083 }
2084
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002085 private Phone getDefaultPhone() {
2086 Phone thePhone = getPhone(getDefaultSubscription());
2087 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2088 }
2089
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 private void publish() {
2091 if (DBG) log("publish: " + this);
2092
Peter Wangc035ce42020-01-08 21:00:22 -08002093 TelephonyFrameworkInitializer
2094 .getTelephonyServiceManager()
2095 .getTelephonyServiceRegisterer()
2096 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 }
2098
Stuart Scott584921c2015-01-15 17:10:34 -08002099 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002100 if (request.phone != null) {
2101 return request.phone;
2102 } else {
2103 return getPhoneFromSubId(request.subId);
2104 }
2105 }
2106
2107 private Phone getPhoneFromSubId(int subId) {
2108 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2109 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002110 }
2111
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002112 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2113 Phone phone = getPhoneFromRequest(request);
2114 return phone == null ? null :
2115 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2116 }
2117
Wink Saville36469e72014-06-11 15:17:00 -07002118 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002119 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002120 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002121 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122
Naina Nallurid63128d2019-09-17 14:10:30 -07002123 private void sendEraseModemConfig(Phone phone) {
2124 if (phone != null) {
2125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2126 mApp, phone.getSubId(), "eraseModemConfig");
2127 final long identity = Binder.clearCallingIdentity();
2128 try {
2129 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2130 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2131 } finally {
2132 Binder.restoreCallingIdentity(identity);
2133 }
2134 }
2135 }
2136
Peter Wang44b186e2020-01-13 23:33:09 -08002137 private boolean isImsAvailableOnDevice() {
2138 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2139 if (pm == null) {
2140 // For some reason package manger is not available.. This will fail internally anyway,
2141 // so do not throw error and allow.
2142 return true;
2143 }
2144 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2145 }
2146
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002148 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002149 }
2150
Wink Savilleb564aae2014-10-23 10:18:09 -07002151 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 if (DBG) log("dial: " + number);
2153 // No permission check needed here: This is just a wrapper around the
2154 // ACTION_DIAL intent, which is available to any app since it puts up
2155 // the UI before it does anything.
2156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002157 final long identity = Binder.clearCallingIdentity();
2158 try {
2159 String url = createTelUrl(number);
2160 if (url == null) {
2161 return;
2162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002164 // PENDING: should we just silently fail if phone is offhook or ringing?
2165 PhoneConstants.State state = mCM.getState(subId);
2166 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2167 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2168 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2169 mApp.startActivity(intent);
2170 }
2171 } finally {
2172 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 }
2174 }
2175
2176 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002177 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002178 }
2179
Wink Savilleb564aae2014-10-23 10:18:09 -07002180 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 if (DBG) log("call: " + number);
2182
2183 // This is just a wrapper around the ACTION_CALL intent, but we still
2184 // need to do a permission check since we're calling startActivity()
2185 // from the context of the phone app.
2186 enforceCallPermission();
2187
Jordan Liu1617b712019-07-10 15:06:26 -07002188 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 != AppOpsManager.MODE_ALLOWED) {
2190 return;
2191 }
2192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 String url = createTelUrl(number);
2196 if (url == null) {
2197 return;
2198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200 boolean isValid = false;
2201 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2202 if (slist != null) {
2203 for (SubscriptionInfo subInfoRecord : slist) {
2204 if (subInfoRecord.getSubscriptionId() == subId) {
2205 isValid = true;
2206 break;
2207 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002208 }
Wink Saville08874612014-08-31 19:19:58 -07002209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210 if (!isValid) {
2211 return;
2212 }
Wink Saville08874612014-08-31 19:19:58 -07002213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2215 intent.putExtra(SUBSCRIPTION_KEY, subId);
2216 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2217 mApp.startActivity(intent);
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
2220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 }
2222
Wink Savilleb564aae2014-10-23 10:18:09 -07002223 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002224 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002225 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2226 }
2227
Wink Savilleb564aae2014-10-23 10:18:09 -07002228 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002229 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002230 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2231 }
2232
Wink Savilleb564aae2014-10-23 10:18:09 -07002233 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235
2236 final long identity = Binder.clearCallingIdentity();
2237 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002238 Phone phone = getPhone(subId);
2239 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240 checkSimPin.start();
2241 return checkSimPin.unlockSim(null, pin);
2242 } finally {
2243 Binder.restoreCallingIdentity(identity);
2244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
Wink Savilleb564aae2014-10-23 10:18:09 -07002247 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249
2250 final long identity = Binder.clearCallingIdentity();
2251 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002252 Phone phone = getPhone(subId);
2253 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002254 checkSimPuk.start();
2255 return checkSimPuk.unlockSim(puk, pin);
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
2258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
2261 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002262 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 * a synchronous one.
2264 */
2265 private static class UnlockSim extends Thread {
2266
2267 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002268 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269
2270 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002271 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2272 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273
2274 // For replies from SimCard interface
2275 private Handler mHandler;
2276
2277 // For async handler to identify request type
2278 private static final int SUPPLY_PIN_COMPLETE = 100;
2279
Michele Berionne5e411512020-11-13 02:36:59 +00002280 UnlockSim(int phoneId, IccCard simCard) {
2281 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 mSimCard = simCard;
2283 }
2284
2285 @Override
2286 public void run() {
2287 Looper.prepare();
2288 synchronized (UnlockSim.this) {
2289 mHandler = new Handler() {
2290 @Override
2291 public void handleMessage(Message msg) {
2292 AsyncResult ar = (AsyncResult) msg.obj;
2293 switch (msg.what) {
2294 case SUPPLY_PIN_COMPLETE:
2295 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2296 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002297 mRetryCount = msg.arg1;
2298 if (ar.exception != null) {
2299 if (ar.exception instanceof CommandException &&
2300 ((CommandException)(ar.exception)).getCommandError()
2301 == CommandException.Error.PASSWORD_INCORRECT) {
2302 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002303 } //When UiccCardApp dispose,handle message and return exception
2304 else if (ar.exception instanceof CommandException &&
2305 ((CommandException) (ar.exception)).getCommandError()
2306 == CommandException.Error.ABORTED) {
2307 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002308 } else {
2309 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2310 }
2311 } else {
2312 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 mDone = true;
2315 UnlockSim.this.notifyAll();
2316 }
2317 break;
2318 }
2319 }
2320 };
2321 UnlockSim.this.notifyAll();
2322 }
2323 Looper.loop();
2324 }
2325
2326 /*
2327 * Use PIN or PUK to unlock SIM card
2328 *
2329 * If PUK is null, unlock SIM card with PIN
2330 *
2331 * If PUK is not null, unlock SIM card with PUK and set PIN code
2332 */
Wink Saville9de0f752013-10-22 19:04:03 -07002333 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334
2335 while (mHandler == null) {
2336 try {
2337 wait();
2338 } catch (InterruptedException e) {
2339 Thread.currentThread().interrupt();
2340 }
2341 }
2342 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2343
2344 if (puk == null) {
2345 mSimCard.supplyPin(pin, callback);
2346 } else {
2347 mSimCard.supplyPuk(puk, pin, callback);
2348 }
2349
2350 while (!mDone) {
2351 try {
2352 Log.d(LOG_TAG, "wait for done");
2353 wait();
2354 } catch (InterruptedException e) {
2355 // Restore the interrupted status
2356 Thread.currentThread().interrupt();
2357 }
2358 }
2359 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002360 int[] resultArray = new int[2];
2361 resultArray[0] = mResult;
2362 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002363
2364 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2365 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2366 }
2367
Wink Saville9de0f752013-10-22 19:04:03 -07002368 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 }
2370 }
2371
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002372 /**
2373 * This method has been removed due to privacy and stability concerns.
2374 */
2375 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002377 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2378 return;
Wink Saville36469e72014-06-11 15:17:00 -07002379 }
2380
Nathan Harold1f889d82020-06-04 17:05:26 -07002381 @Override
2382 public void updateServiceLocationWithPackageName(String callingPackage) {
2383 mApp.getSystemService(AppOpsManager.class)
2384 .checkPackage(Binder.getCallingUid(), callingPackage);
2385
Nathan Haroldf096d982020-11-18 17:18:06 -08002386 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002387 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2388 // Callers targeting S have no business invoking this method.
2389 return;
2390 }
2391
2392 LocationAccessPolicy.LocationPermissionResult locationResult =
2393 LocationAccessPolicy.checkLocationPermission(mApp,
2394 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2395 .setCallingPackage(callingPackage)
2396 .setCallingFeatureId(null)
2397 .setCallingPid(Binder.getCallingPid())
2398 .setCallingUid(Binder.getCallingUid())
2399 .setMethod("updateServiceLocation")
2400 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2401 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2402 .build());
2403 // Apps that lack location permission have no business calling this method;
2404 // however, because no permission was declared in the public API, denials must
2405 // all be "soft".
2406 switch (locationResult) {
2407 case DENIED_HARD: /* fall through */
2408 case DENIED_SOFT:
2409 return;
2410 }
2411
2412 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002413 final long identity = Binder.clearCallingIdentity();
2414 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002415 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002417 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418 }
2419 } finally {
2420 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 }
2423
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002424 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002425 @Override
2426 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002427 return isRadioOnWithFeature(callingPackage, null);
2428 }
2429
2430
2431 @Override
2432 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2433 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2434 callingFeatureId);
2435 }
2436
2437 @Deprecated
2438 @Override
2439 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2440 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002441 }
2442
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002443 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002444 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2445 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002447 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002448 return false;
2449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450
2451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 return isRadioOnForSubscriber(subId);
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
2456 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002457 }
2458
2459 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460 final long identity = Binder.clearCallingIdentity();
2461 try {
2462 final Phone phone = getPhone(subId);
2463 if (phone != null) {
2464 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2465 } else {
2466 return false;
2467 }
2468 } finally {
2469 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 }
2472
2473 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002474 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 }
Wink Saville36469e72014-06-11 15:17:00 -07002476
Wink Savilleb564aae2014-10-23 10:18:09 -07002477 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002479
2480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 final Phone phone = getPhone(subId);
2483 if (phone != null) {
2484 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2485 }
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002488 }
Wink Saville36469e72014-06-11 15:17:00 -07002489 }
2490
2491 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002492 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002493 }
2494
Wink Savilleb564aae2014-10-23 10:18:09 -07002495 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 final Phone phone = getPhone(subId);
2501 if (phone == null) {
2502 return false;
2503 }
2504 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2505 toggleRadioOnOffForSubscriber(subId);
2506 }
2507 return true;
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
Wink Saville36469e72014-06-11 15:17:00 -07002512
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002513 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002514 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002515 /*
2516 * If any of the Radios are available, it will need to be
2517 * shutdown. So return true if any Radio is available.
2518 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519 final long identity = Binder.clearCallingIdentity();
2520 try {
2521 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2522 Phone phone = PhoneFactory.getPhone(i);
2523 if (phone != null && phone.isRadioAvailable()) return true;
2524 }
2525 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2526 return false;
2527 } finally {
2528 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002529 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002530 }
2531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002533 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534 enforceModifyPermission();
2535
2536 final long identity = Binder.clearCallingIdentity();
2537 try {
2538 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2539 logv("Shutting down Phone " + i);
2540 shutdownRadioUsingPhoneId(i);
2541 }
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002544 }
2545 }
2546
2547 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002548 Phone phone = PhoneFactory.getPhone(phoneId);
2549 if (phone != null && phone.isRadioAvailable()) {
2550 phone.shutdownRadio();
2551 }
2552 }
2553
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2560 if (defaultPhone != null) {
2561 defaultPhone.setRadioPower(turnOn);
2562 return true;
2563 } else {
2564 loge("There's no default phone.");
2565 return false;
2566 }
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002569 }
Wink Saville36469e72014-06-11 15:17:00 -07002570 }
2571
Wink Savilleb564aae2014-10-23 10:18:09 -07002572 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 if (phone != null) {
2579 phone.setRadioPower(turnOn);
2580 return true;
2581 } else {
2582 return false;
2583 }
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 }
2588
Wink Saville36469e72014-06-11 15:17:00 -07002589 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002590 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591 public boolean enableDataConnectivity() {
2592 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593
2594 final long identity = Binder.clearCallingIdentity();
2595 try {
2596 int subId = mSubscriptionController.getDefaultDataSubId();
2597 final Phone phone = getPhone(subId);
2598 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002599 phone.getDataEnabledSettings().setDataEnabled(
2600 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 return true;
2602 } else {
2603 return false;
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609
Wink Saville36469e72014-06-11 15:17:00 -07002610 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 public boolean disableDataConnectivity() {
2613 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 int subId = mSubscriptionController.getDefaultDataSubId();
2618 final Phone phone = getPhone(subId);
2619 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002620 phone.getDataEnabledSettings().setDataEnabled(
2621 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 return true;
2623 } else {
2624 return false;
2625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 }
2630
Sanket Padawe356d7632015-06-22 14:03:32 -07002631 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002632 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 final Phone phone = getPhone(subId);
2636 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002637 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 } else {
2639 return false;
2640 }
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 }
2645
2646 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002647 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002648 }
2649
pkanwarae03a6b2016-11-06 20:37:09 -08002650 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 enforceCallPermission();
2652
2653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2656 return;
2657 }
2658 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2659 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
pkanwar32d516d2016-10-14 19:37:38 -07002663 };
2664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667
2668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2671 return false;
2672 }
2673 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 }
2678
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002680 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002681 }
2682
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002683 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 Phone phone = PhoneFactory.getPhone(slotIndex);
2687 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2688 PhoneConstantConversions.convertCallState(phone.getState());
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
2691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 }
2693
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002695 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002696 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2697 }
2698
2699 @Override
2700 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701 final long identity = Binder.clearCallingIdentity();
2702 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002703 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704 if (phone != null) {
2705 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2706 } else {
2707 return PhoneConstantConversions.convertDataState(
2708 PhoneConstants.DataState.DISCONNECTED);
2709 }
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 }
2714
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002716 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002717 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2718 }
2719
2720 @Override
2721 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002724 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 if (phone != null) {
2726 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2727 } else {
2728 return TelephonyManager.DATA_ACTIVITY_NONE;
2729 }
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 }
2734
2735 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002736 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002737 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002738 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002739
2740 LocationAccessPolicy.LocationPermissionResult locationResult =
2741 LocationAccessPolicy.checkLocationPermission(mApp,
2742 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2743 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002744 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002745 .setCallingPid(Binder.getCallingPid())
2746 .setCallingUid(Binder.getCallingUid())
2747 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002748 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002749 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2750 .build());
2751 switch (locationResult) {
2752 case DENIED_HARD:
2753 throw new SecurityException("Not allowed to access cell location");
2754 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002755 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2756 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 }
2758
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002759 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002763 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002764 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 } finally {
2766 Binder.restoreCallingIdentity(identity);
2767 }
Svetoslav64fad262015-04-14 14:35:21 -07002768 }
2769
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002771 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002772 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2773 // registered cell info, so return a NULL country instead.
2774 final long identity = Binder.clearCallingIdentity();
2775 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002776 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2777 // Get default phone in this case.
2778 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2779 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002780 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002782 if (phone == null) return "";
2783 ServiceStateTracker sst = phone.getServiceStateTracker();
2784 if (sst == null) return "";
2785 LocaleTracker lt = sst.getLocaleTracker();
2786 if (lt == null) return "";
2787 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2788 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2789 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002790 } finally {
2791 Binder.restoreCallingIdentity(identity);
2792 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002793 }
2794
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002795 /**
2796 * This method was removed due to potential issues caused by performing partial
2797 * updates of service state, and lack of a credible use case.
2798 *
2799 * This has the ability to break the telephony implementation by disabling notification of
2800 * changes in device connectivity. DO NOT USE THIS!
2801 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002802 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002803 public void enableLocationUpdates() {
2804 mApp.enforceCallingOrSelfPermission(
2805 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806 }
2807
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002808 /**
2809 * This method was removed due to potential issues caused by performing partial
2810 * updates of service state, and lack of a credible use case.
2811 *
2812 * This has the ability to break the telephony implementation by disabling notification of
2813 * changes in device connectivity. DO NOT USE THIS!
2814 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 @Override
2816 public void disableLocationUpdates() {
2817 mApp.enforceCallingOrSelfPermission(
2818 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
2821 @Override
2822 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002823 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2824 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002825 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002826 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2827 throw new SecurityException(
2828 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2829 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002830
Jordan Liu1617b712019-07-10 15:06:26 -07002831 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2833 return null;
2834 }
Svetoslav64fad262015-04-14 14:35:21 -07002835
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002836 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002838 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002839 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840
Nathan Haroldf180aac2018-06-01 18:43:55 -07002841 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2842 for (CellInfo ci : info) {
2843 if (ci instanceof CellInfoGsm) {
2844 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2845 } else if (ci instanceof CellInfoWcdma) {
2846 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002849 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002852 private List<CellInfo> getCachedCellInfo() {
2853 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2854 for (Phone phone : PhoneFactory.getPhones()) {
2855 List<CellInfo> info = phone.getAllCellInfo();
2856 if (info != null) cellInfos.addAll(info);
2857 }
2858 return cellInfos;
2859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860
2861 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002862 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002864 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002865
2866 LocationAccessPolicy.LocationPermissionResult locationResult =
2867 LocationAccessPolicy.checkLocationPermission(mApp,
2868 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2869 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002870 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002871 .setCallingPid(Binder.getCallingPid())
2872 .setCallingUid(Binder.getCallingUid())
2873 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002874 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002875 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2876 .build());
2877 switch (locationResult) {
2878 case DENIED_HARD:
2879 throw new SecurityException("Not allowed to access cell info");
2880 case DENIED_SOFT:
2881 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
2883
Nathan Haroldf096d982020-11-18 17:18:06 -08002884 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002885 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2886 return getCachedCellInfo();
2887 }
2888
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002889 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002890 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2894 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002895 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002896 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 if (info != null) cellInfos.addAll(info);
2898 }
2899 return cellInfos;
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903 }
2904
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002905 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002906 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2907 String callingFeatureId) {
2908 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2909 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002910 }
2911
2912 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002913 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2914 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002915 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002916 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002917 }
2918
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002919 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2920 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002921 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002922 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002923
2924 LocationAccessPolicy.LocationPermissionResult locationResult =
2925 LocationAccessPolicy.checkLocationPermission(mApp,
2926 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2927 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002928 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002929 .setCallingPid(Binder.getCallingPid())
2930 .setCallingUid(Binder.getCallingUid())
2931 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002932 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2933 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002934 .build());
2935 switch (locationResult) {
2936 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002937 if (TelephonyPermissions
2938 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002939 // Safetynet logging for b/154934934
2940 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2941 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002942 throw new SecurityException("Not allowed to access cell info");
2943 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002944 if (TelephonyPermissions
2945 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002946 // Safetynet logging for b/154934934
2947 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2948 }
Nathan Harold5320c422019-05-09 10:26:08 -07002949 try {
2950 cb.onCellInfo(new ArrayList<CellInfo>());
2951 } catch (RemoteException re) {
2952 // Drop without consequences
2953 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002954 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002955 }
2956
Nathan Harolda939a962019-05-09 10:13:47 -07002957
2958 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002959 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2960
2961 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2962 }
2963
2964 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002966 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002967 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002968
2969 final long identity = Binder.clearCallingIdentity();
2970 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002971 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 }
2976
Shishir Agrawala9f32182016-04-12 12:00:16 -07002977 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002978 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002979 Phone phone = PhoneFactory.getPhone(slotIndex);
2980 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002981 return null;
2982 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002983 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002984 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002985 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002986 return null;
2987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
2991 return phone.getImei();
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002995 }
2996
2997 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002998 public String getTypeAllocationCodeForSlot(int slotIndex) {
2999 Phone phone = PhoneFactory.getPhone(slotIndex);
3000 String tac = null;
3001 if (phone != null) {
3002 String imei = phone.getImei();
3003 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3004 }
3005 return tac;
3006 }
3007
3008 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003009 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003010 Phone phone = PhoneFactory.getPhone(slotIndex);
3011 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003012 return null;
3013 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003014
Jeff Davidson913390f2018-02-23 17:11:49 -08003015 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003016 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003017 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003018 return null;
3019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020
3021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 return phone.getMeid();
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
Jack Yu2af8d712017-03-15 17:14:14 -07003027 }
3028
3029 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003030 public String getManufacturerCodeForSlot(int slotIndex) {
3031 Phone phone = PhoneFactory.getPhone(slotIndex);
3032 String manufacturerCode = null;
3033 if (phone != null) {
3034 String meid = phone.getMeid();
3035 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3036 }
3037 return manufacturerCode;
3038 }
3039
3040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003041 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3042 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003043 Phone phone = PhoneFactory.getPhone(slotIndex);
3044 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003045 return null;
3046 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003047 int subId = phone.getSubId();
3048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003049 mApp, subId, callingPackage, callingFeatureId,
3050 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003051 return null;
3052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003053
3054 final long identity = Binder.clearCallingIdentity();
3055 try {
3056 return phone.getDeviceSvn();
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
3059 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003060 }
3061
fionaxu43304da2017-11-27 22:51:16 -08003062 @Override
3063 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 final Phone phone = getPhone(subId);
3067 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
fionaxu43304da2017-11-27 22:51:16 -08003071 }
3072
3073 @Override
3074 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 final Phone phone = getPhone(subId);
3078 return phone == null ? null : phone.getCarrierName();
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
fionaxu43304da2017-11-27 22:51:16 -08003082 }
3083
calvinpanffe225e2018-11-01 19:43:06 +08003084 @Override
chen xu0026ca62019-03-06 15:28:50 -08003085 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 final Phone phone = getPhone(subId);
3089 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003090 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
3094 }
3095
3096 @Override
chen xu0026ca62019-03-06 15:28:50 -08003097 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003101 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
3105 }
3106
chen xu651eec72018-11-11 19:03:44 -08003107 @Override
chen xu864e11c2018-12-06 22:10:03 -08003108 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3109 if (!isSubscriptionMccMnc) {
3110 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3111 }
chen xu651eec72018-11-11 19:03:44 -08003112 final Phone phone = PhoneFactory.getPhone(slotIndex);
3113 if (phone == null) {
3114 return TelephonyManager.UNKNOWN_CARRIER_ID;
3115 }
3116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003124 //
3125 // Internal helper methods.
3126 //
3127
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003128 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3130 *
3131 * @throws SecurityException if the caller does not have the required permission
3132 */
3133 private void enforceModifyPermission() {
3134 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3135 }
3136
Shuo Qiancd19c462020-01-16 20:51:11 -08003137 /**
3138 * Make sure the caller is system.
3139 *
3140 * @throws SecurityException if the caller is not system.
3141 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003142 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003143 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3144 throw new SecurityException("Caller must be system");
3145 }
3146 }
3147
Shuo Qian3b6ee772019-11-13 17:43:31 -08003148 private void enforceActiveEmergencySessionPermission() {
3149 mApp.enforceCallingOrSelfPermission(
3150 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3151 }
3152
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 /**
3154 * Make sure the caller has the CALL_PHONE permission.
3155 *
3156 * @throws SecurityException if the caller does not have the required permission
3157 */
3158 private void enforceCallPermission() {
3159 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3160 }
3161
paulhu5a773602019-08-23 19:17:33 +08003162 private void enforceSettingsPermission() {
3163 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003164 }
3165
Michele Berionne5e411512020-11-13 02:36:59 +00003166 private void enforceRebootPermission() {
3167 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3168 }
3169
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 private String createTelUrl(String number) {
3171 if (TextUtils.isEmpty(number)) {
3172 return null;
3173 }
3174
Jake Hambye994d462014-02-03 13:10:13 -08003175 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003176 }
3177
Ihab Awadf9e92732013-12-05 18:02:52 -08003178 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003179 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3180 }
3181
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003182 private static void logv(String msg) {
3183 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3184 }
3185
Ihab Awadf9e92732013-12-05 18:02:52 -08003186 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3188 }
3189
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003190 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003192 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003193 }
3194
Sanket Padawe356d7632015-06-22 14:03:32 -07003195 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003196 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 final Phone phone = PhoneFactory.getPhone(slotIndex);
3200 if (phone == null) {
3201 return PhoneConstants.PHONE_TYPE_NONE;
3202 } else {
3203 return phone.getPhoneType();
3204 }
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 }
3209
3210 /**
3211 * Returns the CDMA ERI icon index to display
3212 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003213 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003214 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3215 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3216 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003217 }
3218
Sanket Padawe356d7632015-06-22 14:03:32 -07003219 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003220 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3221 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003223 mApp, subId, callingPackage, callingFeatureId,
3224 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003225 return -1;
3226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 final Phone phone = getPhone(subId);
3231 if (phone != null) {
3232 return phone.getCdmaEriIconIndex();
3233 } else {
3234 return -1;
3235 }
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003239 }
3240
3241 /**
3242 * Returns the CDMA ERI icon mode,
3243 * 0 - ON
3244 * 1 - FLASHING
3245 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003246 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003247 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3248 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3249 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003250 }
3251
Sanket Padawe356d7632015-06-22 14:03:32 -07003252 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003253 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3254 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003256 mApp, subId, callingPackage, callingFeatureId,
3257 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003258 return -1;
3259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260
3261 final long identity = Binder.clearCallingIdentity();
3262 try {
3263 final Phone phone = getPhone(subId);
3264 if (phone != null) {
3265 return phone.getCdmaEriIconMode();
3266 } else {
3267 return -1;
3268 }
3269 } finally {
3270 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 }
3273
3274 /**
3275 * Returns the CDMA ERI text,
3276 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003277 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003278 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3279 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3280 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003281 }
3282
Sanket Padawe356d7632015-06-22 14:03:32 -07003283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003284 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3285 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003287 mApp, subId, callingPackage, callingFeatureId,
3288 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003289 return null;
3290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291
3292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 final Phone phone = getPhone(subId);
3295 if (phone != null) {
3296 return phone.getCdmaEriText();
3297 } else {
3298 return null;
3299 }
3300 } finally {
3301 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003303 }
3304
3305 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003306 * Returns the CDMA MDN.
3307 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003308 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003309 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3311 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312
3313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003316 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003317 return phone.getLine1Number();
3318 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003319 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320 return null;
3321 }
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003324 }
3325 }
3326
3327 /**
3328 * Returns the CDMA MIN.
3329 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003330 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003331 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3333 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334
3335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 final Phone phone = getPhone(subId);
3338 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3339 return phone.getCdmaMin();
3340 } else {
3341 return null;
3342 }
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003345 }
3346 }
3347
Hall Liud892bec2018-11-30 14:51:45 -08003348 @Override
3349 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3350 INumberVerificationCallback callback, String callingPackage) {
3351 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3352 != PERMISSION_GRANTED) {
3353 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3354 }
3355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3356
3357 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3358 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003359 throw new SecurityException("Calling package must be configured in the device config: "
3360 + "calling package: " + callingPackage
3361 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003362 }
3363
3364 if (range == null) {
3365 throw new NullPointerException("Range must be non-null");
3366 }
3367
3368 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003369 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003370
3371 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3372 }
3373
Junda Liuca05d5d2014-08-14 22:36:34 -07003374 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003375 * Returns true if CDMA provisioning needs to run.
3376 */
3377 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 final long identity = Binder.clearCallingIdentity();
3379 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003384 }
3385
3386 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003387 * Sets the voice mail number of a given subId.
3388 */
3389 @Override
3390 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003391 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3392 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393
3394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3397 new Pair<String, String>(alphaTag, number), new Integer(subId));
3398 return success;
3399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003402 }
3403
Ta-wei Yen87c49842016-05-13 21:19:52 -07003404 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003405 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3406 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003407 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3408 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003409 if (!TextUtils.equals(callingPackage, systemDialer)) {
3410 throw new SecurityException("caller must be system dialer");
3411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003412
3413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3416 if (phoneAccountHandle == null) {
3417 return null;
3418 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003419 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420 } finally {
3421 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003422 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003423 }
3424
3425 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003426 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3427 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003428 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003430 mApp, subId, callingPackage, callingFeatureId,
3431 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003432 return null;
3433 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003435 final long identity = Binder.clearCallingIdentity();
3436 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003437 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003438 } finally {
3439 Binder.restoreCallingIdentity(identity);
3440 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003441 }
3442
3443 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003444 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3445 VisualVoicemailSmsFilterSettings settings) {
3446 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003451 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452 } finally {
3453 Binder.restoreCallingIdentity(identity);
3454 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003455 }
3456
3457 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003458 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003460
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003468 }
3469
3470 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003471 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3472 String callingPackage, int subId) {
3473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003474
3475 final long identity = Binder.clearCallingIdentity();
3476 try {
3477 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003482 }
3483
3484 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003485 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003486 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003487
3488 final long identity = Binder.clearCallingIdentity();
3489 try {
3490 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003491 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492 } finally {
3493 Binder.restoreCallingIdentity(identity);
3494 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003495 }
3496
3497 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003498 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3499 String callingAttributionTag, int subId, String number, int port, String text,
3500 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003502 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003503 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003504 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003505 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3506 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003507 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003508
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003509 /**
fionaxu0152e512016-11-14 13:36:14 -08003510 * Sets the voice activation state of a given subId.
3511 */
3512 @Override
3513 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3515 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003516
3517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 final Phone phone = getPhone(subId);
3520 if (phone != null) {
3521 phone.setVoiceActivationState(activationState);
3522 } else {
3523 loge("setVoiceActivationState fails with invalid subId: " + subId);
3524 }
3525 } finally {
3526 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003527 }
3528 }
3529
3530 /**
3531 * Sets the data activation state of a given subId.
3532 */
3533 @Override
3534 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3536 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537
3538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 final Phone phone = getPhone(subId);
3541 if (phone != null) {
3542 phone.setDataActivationState(activationState);
3543 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003544 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545 }
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003548 }
3549 }
3550
3551 /**
3552 * Returns the voice activation state of a given subId.
3553 */
3554 @Override
3555 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
fionaxu0152e512016-11-14 13:36:14 -08003558 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 if (phone != null) {
3562 return phone.getVoiceActivationState();
3563 } else {
3564 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3565 }
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003568 }
3569 }
3570
3571 /**
3572 * Returns the data activation state of a given subId.
3573 */
3574 @Override
3575 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577
fionaxu0152e512016-11-14 13:36:14 -08003578 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 if (phone != null) {
3582 return phone.getDataActivationState();
3583 } else {
3584 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003588 }
3589 }
3590
3591 /**
Wink Saville36469e72014-06-11 15:17:00 -07003592 * Returns the unread count of voicemails for a subId
3593 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003594 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003595 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3596 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003598 mApp, subId, callingPackage, callingFeatureId,
3599 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003600 return 0;
3601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 final Phone phone = getPhone(subId);
3605 if (phone != null) {
3606 return phone.getVoiceMessageCount();
3607 } else {
3608 return 0;
3609 }
3610 } finally {
3611 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003613 }
3614
3615 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003616 * returns true, if the device is in a state where both voice and data
3617 * are supported simultaneously. This can change based on location or network condition.
3618 */
3619 @Override
3620 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 final Phone phone = getPhone(subId);
3624 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003628 }
3629
3630 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003631 * Send the dialer code if called from the current default dialer or the caller has
3632 * carrier privilege.
3633 * @param inputCode The dialer code to send
3634 */
3635 @Override
3636 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003638 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003639 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3640 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003641 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003642 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003643 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645
3646 final long identity = Binder.clearCallingIdentity();
3647 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003648 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
fionaxu235cc5e2017-03-06 22:25:57 -08003652 }
3653
Pengquan Menga1bb6272018-09-06 09:59:22 -07003654 @Override
3655 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003656 TelephonyPermissions
3657 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3658 mApp, subId, "getNetworkSelectionMode");
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 if (!isActiveSubscription(subId)) {
3662 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3663 }
3664 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3665 } finally {
3666 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003667 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003668 }
3669
Brad Ebinger35c841c2018-10-01 10:40:55 -07003670 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003671 public boolean isInEmergencySmsMode() {
3672 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 for (Phone phone : PhoneFactory.getPhones()) {
3676 if (phone.isInEmergencySmsMode()) {
3677 return true;
3678 }
3679 }
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 return false;
3684 }
3685
shilu366312e2019-12-17 09:28:10 -08003686 /**
3687 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3688 * @param subId The subscription to use to check the configuration.
3689 * @param c The callback that will be used to send the result.
3690 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003691 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003692 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3693 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003694 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3695 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003696
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003697 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3698 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3699 "IMS not available on device.");
3700 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 final long token = Binder.clearCallingIdentity();
3702 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003703 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003704 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003706 } catch (ImsException e) {
3707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 } finally {
3709 Binder.restoreCallingIdentity(token);
3710 }
3711 }
3712
shilu366312e2019-12-17 09:28:10 -08003713 /**
3714 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3715 * @param subId The subscription to use to check the configuration.
3716 * @param c The callback that will be used to send the result.
3717 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003719 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003720 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3721 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003722 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3723 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3724 }
Meng Wangafbc5852019-09-19 17:37:13 -07003725 final long token = Binder.clearCallingIdentity();
3726 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003727 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003728 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3729 .removeRegistrationCallbackForSubscription(c, subId);
3730 } catch (ImsException e) {
3731 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3732 + "is inactive, ignoring unregister.");
3733 // If the subscription is no longer active, just return, since the callback
3734 // will already have been removed internally.
3735 } finally {
3736 Binder.restoreCallingIdentity(token);
3737 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 }
3739
Brad Ebingera34a6c22019-10-22 17:36:18 -07003740 /**
3741 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3742 */
3743 @Override
3744 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3745 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3746 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3747 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3748 "IMS not available on device.");
3749 }
3750 final long token = Binder.clearCallingIdentity();
3751 try {
3752 Phone phone = getPhone(subId);
3753 if (phone == null) {
3754 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3755 + subId + "'");
3756 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3757 }
3758 phone.getImsRegistrationState(regState -> {
3759 try {
3760 consumer.accept((regState == null)
3761 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3762 } catch (RemoteException e) {
3763 // Ignore if the remote process is no longer available to call back.
3764 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3765 }
3766 });
3767 } finally {
3768 Binder.restoreCallingIdentity(token);
3769 }
3770 }
3771
3772 /**
3773 * Get the transport type for the IMS service registration state.
3774 */
3775 @Override
3776 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003777 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3778 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003779 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3780 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3781 "IMS not available on device.");
3782 }
3783 final long token = Binder.clearCallingIdentity();
3784 try {
3785 Phone phone = getPhone(subId);
3786 if (phone == null) {
3787 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3788 + subId + "'");
3789 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3790 }
3791 phone.getImsRegistrationTech(regTech -> {
3792 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3793 int regTechConverted = (regTech == null)
3794 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3795 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3796 regTechConverted);
3797 try {
3798 consumer.accept(regTechConverted);
3799 } catch (RemoteException e) {
3800 // Ignore if the remote process is no longer available to call back.
3801 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3802 }
3803 });
3804 } finally {
3805 Binder.restoreCallingIdentity(token);
3806 }
3807 }
3808
shilu366312e2019-12-17 09:28:10 -08003809 /**
3810 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3811 * @param subId The subscription to use to check the configuration.
3812 * @param c The callback that will be used to send the result.
3813 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003814 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003815 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3816 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003817 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3818 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003819 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3820 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3821 "IMS not available on device.");
3822 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3824 final long token = Binder.clearCallingIdentity();
3825 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003826 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003827 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003828 } catch (ImsException e) {
3829 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 } finally {
3831 Binder.restoreCallingIdentity(token);
3832 }
3833 }
3834
shilu366312e2019-12-17 09:28:10 -08003835 /**
3836 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3837 * @param subId The subscription to use to check the configuration.
3838 * @param c The callback that will be used to send the result.
3839 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003841 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003842 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3843 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003844 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3845 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3846 }
Meng Wangafbc5852019-09-19 17:37:13 -07003847
3848 final long token = Binder.clearCallingIdentity();
3849 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003850 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003851 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003852 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003853 } catch (ImsException e) {
3854 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3855 + "is inactive, ignoring unregister.");
3856 // If the subscription is no longer active, just return, since the callback
3857 // will already have been removed internally.
3858 } finally {
3859 Binder.restoreCallingIdentity(token);
3860 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 }
3862
3863 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003864 public boolean isCapable(int subId, int capability, int regTech) {
3865 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003866 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3867 final long token = Binder.clearCallingIdentity();
3868 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003869 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003870 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003871 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003872 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3873 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003874 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003875 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3876 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003877 } finally {
3878 Binder.restoreCallingIdentity(token);
3879 }
3880 }
3881
3882 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003883 public boolean isAvailable(int subId, int capability, int regTech) {
3884 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 final long token = Binder.clearCallingIdentity();
3886 try {
3887 Phone phone = getPhone(subId);
3888 if (phone == null) return false;
3889 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003890 } catch (com.android.ims.ImsException e) {
3891 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3892 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 } finally {
3894 Binder.restoreCallingIdentity(token);
3895 }
3896 }
3897
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003898 /**
3899 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3900 * subscription.
3901 * @param subId The subscription to use to check the configuration.
3902 * @param callback The callback that will be used to send the result.
3903 * @param capability The MmTelFeature capability that will be used to send the result.
3904 * @param transportType The transport type of the MmTelFeature capability.
3905 */
3906 @Override
3907 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3908 int transportType) {
3909 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3910 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3911 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3912 "IMS not available on device.");
3913 }
3914 final long token = Binder.clearCallingIdentity();
3915 try {
3916 int slotId = getSlotIndex(subId);
3917 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3918 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3919 + subId + "'");
3920 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3921 }
3922 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3923 transportType, aBoolean -> {
3924 try {
3925 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3926 } catch (RemoteException e) {
3927 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3928 + "running. Ignore");
3929 }
3930 });
3931 } finally {
3932 Binder.restoreCallingIdentity(token);
3933 }
3934 }
3935
shilu366312e2019-12-17 09:28:10 -08003936 /**
3937 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3938 * @param subId The subscription to use to check the configuration.
3939 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003940 @Override
3941 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003942 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3943 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003944
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3946 final long token = Binder.clearCallingIdentity();
3947 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003948 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003949 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003950 } catch (ImsException e) {
3951 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 } finally {
3953 Binder.restoreCallingIdentity(token);
3954 }
3955 }
3956
3957 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003958 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003960 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003964 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003966 } catch (ImsException e) {
3967 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 } finally {
3969 Binder.restoreCallingIdentity(identity);
3970 }
3971 }
3972
shilu366312e2019-12-17 09:28:10 -08003973 /**
3974 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3975 * @param subId The subscription to use to check the configuration.
3976 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003978 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003979 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3980 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003984 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3985 } catch (ImsException e) {
3986 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
3990 }
3991
3992 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003993 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003995 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003999 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004000 } catch (ImsException e) {
4001 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004002 } finally {
4003 Binder.restoreCallingIdentity(identity);
4004 }
4005 }
4006
shilu366312e2019-12-17 09:28:10 -08004007 /**
4008 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4009 * @param subId The subscription to use to check the configuration.
4010 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 @Override
4012 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004013 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4014 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 final long identity = Binder.clearCallingIdentity();
4016 try {
4017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004018 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004019 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004020 } catch (ImsException e) {
4021 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 } finally {
4023 Binder.restoreCallingIdentity(identity);
4024 }
4025 }
4026
4027 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004028 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004030 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 final long identity = Binder.clearCallingIdentity();
4032 try {
4033 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004034 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004035 } catch (ImsException e) {
4036 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 } finally {
4038 Binder.restoreCallingIdentity(identity);
4039 }
4040 }
4041
shilu366312e2019-12-17 09:28:10 -08004042 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004043 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4044 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4045 * @param subId The subscription to use to check the configuration.
4046 */
4047 @Override
4048 public boolean isCrossSimCallingEnabledByUser(int subId) {
4049 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4050 mApp, subId, "isCrossSimCallingEnabledByUser");
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4054 return ImsManager.getInstance(mApp,
4055 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4056 } catch (ImsException e) {
4057 throw new ServiceSpecificException(e.getCode());
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
4061 }
4062
4063 /**
4064 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4065 * Requires MODIFY_PHONE_STATE permission.
4066 * @param subId The subscription to use to check the configuration.
4067 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4068 * false otherwise
4069 */
4070 @Override
4071 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4073 "setCrossSimCallingEnabled");
4074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4077 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4078 .setCrossSimCallingEnabled(isEnabled);
4079 } catch (ImsException e) {
4080 throw new ServiceSpecificException(e.getCode());
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
4083 }
4084 }
4085
4086 /**
shilu366312e2019-12-17 09:28:10 -08004087 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4088 * @param subId The subscription to use to check the configuration.
4089 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 @Override
4091 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004092 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4093 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004097 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (ImsException e) {
4100 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
4104 }
4105
4106 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004107 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004109 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004113 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004115 } catch (ImsException e) {
4116 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
4120 }
4121
4122 @Override
4123 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4125 "setVoWiFiNonPersistent");
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004129 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004130 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004131 } catch (ImsException e) {
4132 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 } finally {
4134 Binder.restoreCallingIdentity(identity);
4135 }
4136 }
4137
shilu366312e2019-12-17 09:28:10 -08004138 /**
4139 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4140 * @param subId The subscription to use to check the configuration.
4141 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 @Override
4143 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004144 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4145 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 final long identity = Binder.clearCallingIdentity();
4147 try {
4148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004149 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004151 } catch (ImsException e) {
4152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 } finally {
4154 Binder.restoreCallingIdentity(identity);
4155 }
4156 }
4157
4158 @Override
4159 public void setVoWiFiModeSetting(int subId, int mode) {
4160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4161 "setVoWiFiModeSetting");
4162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004165 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004167 } catch (ImsException e) {
4168 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
4172 }
4173
4174 @Override
4175 public int getVoWiFiRoamingModeSetting(int subId) {
4176 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004180 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004182 } catch (ImsException e) {
4183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
4187 }
4188
4189 @Override
4190 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4192 "setVoWiFiRoamingModeSetting");
4193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004196 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004198 } catch (ImsException e) {
4199 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
4203 }
4204
4205 @Override
4206 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4208 "setRttCapabilityEnabled");
4209 final long identity = Binder.clearCallingIdentity();
4210 try {
4211 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004212 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4213 } catch (ImsException e) {
4214 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 } finally {
4216 Binder.restoreCallingIdentity(identity);
4217 }
4218 }
4219
shilu366312e2019-12-17 09:28:10 -08004220 /**
4221 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4222 * @param subId The subscription to use to check the configuration.
4223 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 @Override
4225 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004226 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4227 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 final long identity = Binder.clearCallingIdentity();
4229 try {
4230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004231 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004233 } catch (ImsException e) {
4234 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
4238 }
4239
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004240 @Override
4241 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4242 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4243 final long identity = Binder.clearCallingIdentity();
4244 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004245 if (!isImsAvailableOnDevice()) {
4246 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4247 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004248 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004249 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004250 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004251 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004252 } catch (ImsException e) {
4253 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004254 } finally {
4255 Binder.restoreCallingIdentity(identity);
4256 }
4257 }
4258
4259 @Override
4260 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4261 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4262 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004263 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4264 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4265 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004266 try {
4267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004268 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004269 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004270 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004271 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4272 + "is inactive, ignoring unregister.");
4273 // If the subscription is no longer active, just return, since the callback will already
4274 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
4277 }
4278 }
4279
allenwtsu99c623b2020-01-03 18:24:23 +08004280
4281 private void checkModifyPhoneStatePermission(int subId, String message) {
4282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4283 message);
4284 }
4285
4286 private boolean isImsProvisioningRequired(int subId, int capability,
4287 boolean isMmtelCapability) {
4288 Phone phone = getPhone(subId);
4289 if (phone == null) {
4290 loge("phone instance null for subid " + subId);
4291 return false;
4292 }
4293 if (isMmtelCapability) {
4294 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4295 return false;
4296 }
4297 } else {
4298 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4299 return false;
4300 }
4301 }
4302 return true;
4303 }
4304
4305 @Override
4306 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4307 boolean isProvisioned) {
4308 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4309
4310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4313 if (!isImsProvisioningRequired(subId, capability, false)) {
4314 return;
4315 }
4316
4317 // this capability requires provisioning, route to the correct API.
4318 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4319 switch (capability) {
4320 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4321 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4322 ims.setEabProvisioned(isProvisioned);
4323 break;
4324 default: {
4325 throw new IllegalArgumentException("Tried to set provisioning for "
4326 + "rcs capability '" + capability + "', which does not require "
4327 + "provisioning.");
4328 }
4329 }
4330 } finally {
4331 Binder.restoreCallingIdentity(identity);
4332 }
4333
4334 }
4335
4336
4337 @Override
4338 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4339 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4340 final long identity = Binder.clearCallingIdentity();
4341 try {
4342 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4343 if (!isImsProvisioningRequired(subId, capability, false)) {
4344 return true;
4345 }
4346
4347 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4348 switch (capability) {
4349 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4350 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4351 return ims.isEabProvisionedOnDevice();
4352
4353 default: {
4354 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4355 + "capability '" + capability + "', which does not require "
4356 + "provisioning.");
4357 }
4358 }
4359
4360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
4363 }
4364
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004365 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004366 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4367 boolean isProvisioned) {
4368 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4369 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4370 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4371 }
allenwtsu99c623b2020-01-03 18:24:23 +08004372 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004376 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004377 return;
4378 }
4379
4380 // this capability requires provisioning, route to the correct API.
4381 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4382 switch (capability) {
4383 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4384 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4385 ims.setVolteProvisioned(isProvisioned);
4386 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4387 ims.setWfcProvisioned(isProvisioned);
4388 }
4389 break;
4390 }
4391 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4392 // There is currently no difference in VT provisioning type.
4393 ims.setVtProvisioned(isProvisioned);
4394 break;
4395 }
4396 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4397 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4398 // change the capability of the feature instead if needed.
4399 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4400 == isProvisioned) {
4401 // No change in provisioning.
4402 return;
4403 }
4404 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4405 try {
4406 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004407 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004408 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4409 + ", Exception" + e.getMessage());
4410 }
4411 break;
4412 }
4413 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004414 throw new IllegalArgumentException("Tried to set provisioning for "
4415 + "MmTel capability '" + capability + "', which does not require "
4416 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004417 }
4418 }
4419
4420 } finally {
4421 Binder.restoreCallingIdentity(identity);
4422 }
4423 }
4424
4425 @Override
4426 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4427 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4428 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4429 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4430 }
4431 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4432 final long identity = Binder.clearCallingIdentity();
4433 try {
4434 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004435 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004436 return true;
4437 }
4438
4439 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4440 switch (capability) {
4441 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4442 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4443 return ims.isVolteProvisionedOnDevice();
4444 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4445 return ims.isWfcProvisionedOnDevice();
4446 }
4447 // This should never happen, since we are checking tech above to make sure it
4448 // is either LTE or IWLAN.
4449 throw new IllegalArgumentException("Invalid radio technology for voice "
4450 + "capability.");
4451 }
4452 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4453 // There is currently no difference in VT provisioning type.
4454 return ims.isVtProvisionedOnDevice();
4455 }
4456 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4457 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4458 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4459 }
4460 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004461 throw new IllegalArgumentException(
4462 "Tried to get provisioning for MmTel capability '" + capability
4463 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004464 }
4465 }
4466
4467 } finally {
4468 Binder.restoreCallingIdentity(identity);
4469 }
4470 }
4471
4472 @Override
4473 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4474 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4475 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4476 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4477 }
4478 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4479 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4480 return (provisionedBits & capability) > 0;
4481 }
4482
4483 @Override
4484 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4485 boolean isProvisioned) {
4486 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4487 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4488 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4489 }
4490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4491 "setProvisioningStatusForCapability");
4492 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4493 // If the current provisioning status for capability already matches isProvisioned,
4494 // do nothing.
4495 if (((provisionedBits & capability) > 0) == isProvisioned) {
4496 return;
4497 }
4498 if (isProvisioned) {
4499 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4500 } else {
4501 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4502 }
4503 }
4504
4505 /**
4506 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4507 * technology. The bitfield should mirror the bitfield defined by
4508 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4509 */
4510 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4511 String key = getMmTelProvisioningKey(subId, tech);
4512 // Default is no capabilities are provisioned.
4513 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4514 }
4515
4516 /**
4517 * Sets the MmTel capability provisioning bitfield (defined by
4518 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4519 * technology specified.
4520 *
4521 * Note: This is a synchronous command and should not be called on UI thread.
4522 */
4523 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4524 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4525 String key = getMmTelProvisioningKey(subId, tech);
4526 editor.putInt(key, newField);
4527 editor.commit();
4528 }
4529
4530 private static String getMmTelProvisioningKey(int subId, int tech) {
4531 // resulting key is provision_ims_mmtel_{subId}_{tech}
4532 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4533 }
4534
4535 /**
4536 * Query CarrierConfig to see if the specified capability requires provisioning for the
4537 * carrier associated with the subscription id.
4538 */
4539 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4540 int capability) {
4541 CarrierConfigManager configManager = new CarrierConfigManager(context);
4542 PersistableBundle c = configManager.getConfigForSubId(subId);
4543 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004544 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004545 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4546 false);
4547 boolean requireVoiceVtProvisioning = c.getBoolean(
4548 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4549
4550 // First check to make sure that the capability requires provisioning.
4551 switch (capability) {
4552 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4553 // intentional fallthrough
4554 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4555 if (requireVoiceVtProvisioning) {
4556 // Voice and Video requires provisioning
4557 return true;
4558 }
4559 break;
4560 }
4561 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4562 if (requireUtProvisioning) {
4563 // UT requires provisioning
4564 return true;
4565 }
4566 break;
4567 }
4568 }
4569 return false;
4570 }
4571
allenwtsu99c623b2020-01-03 18:24:23 +08004572 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4573 int capability) {
4574 CarrierConfigManager configManager = new CarrierConfigManager(context);
4575 PersistableBundle c = configManager.getConfigForSubId(subId);
4576
4577 boolean requireRcsProvisioning = c.getBoolean(
4578 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4579
4580 // First check to make sure that the capability requires provisioning.
4581 switch (capability) {
4582 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4583 // intentional fallthrough
4584 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4585 if (requireRcsProvisioning) {
4586 // OPTION or PRESENCE requires provisioning
4587 return true;
4588 }
4589 break;
4590 }
4591 }
4592 return false;
4593 }
4594
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004595 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004596 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4598 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4599 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004600 enforceReadPrivilegedPermission("getImsProvisioningInt");
4601 final long identity = Binder.clearCallingIdentity();
4602 try {
4603 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004604 int slotId = getSlotIndex(subId);
4605 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4606 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4607 + subId + "' for key:" + key);
4608 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4609 }
4610 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004611 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004612 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4613 + subId + "' for key:" + key);
4614 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
4618 }
4619
4620 @Override
4621 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004622 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4623 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4624 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004625 enforceReadPrivilegedPermission("getImsProvisioningString");
4626 final long identity = Binder.clearCallingIdentity();
4627 try {
4628 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004629 int slotId = getSlotIndex(subId);
4630 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4631 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4632 + subId + "' for key:" + key);
4633 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4634 }
4635 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004636 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004637 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4638 + subId + "' for key:" + key);
4639 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004640 } finally {
4641 Binder.restoreCallingIdentity(identity);
4642 }
4643 }
4644
4645 @Override
4646 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004647 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4648 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4649 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4651 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004652 final long identity = Binder.clearCallingIdentity();
4653 try {
4654 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004655 int slotId = getSlotIndex(subId);
4656 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4657 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4658 + subId + "' for key:" + key);
4659 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4660 }
4661 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004662 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004663 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4664 + "' for key:" + key);
4665 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
4669 }
4670
4671 @Override
4672 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004673 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4674 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4675 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4677 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004678 final long identity = Binder.clearCallingIdentity();
4679 try {
4680 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004681 int slotId = getSlotIndex(subId);
4682 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4683 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4684 + subId + "' for key:" + key);
4685 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4686 }
4687 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004688 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004689 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4690 + "' for key:" + key);
4691 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
4695 }
4696
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004697 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004698 int slotId = SubscriptionManager.getSlotIndex(subId);
4699 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004700 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4701 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004702 }
4703 return slotId;
4704 }
4705
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004706 private int getSlotIndex(int subId) {
4707 int slotId = SubscriptionManager.getSlotIndex(subId);
4708 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4709 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4710 }
4711 return slotId;
4712 }
4713
Wink Saville36469e72014-06-11 15:17:00 -07004714 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004715 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004716 */
4717 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004718 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4719 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004720 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004721 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004722 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004723 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004724 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004725 mApp, subId, callingPackage, callingFeatureId,
4726 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004727 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4728 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730 final long identity = Binder.clearCallingIdentity();
4731 try {
4732 final Phone phone = getPhone(subId);
4733 if (phone != null) {
4734 return phone.getServiceState().getDataNetworkType();
4735 } else {
4736 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4737 }
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004741 }
4742
4743 /**
4744 * Returns the data network type
4745 */
4746 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004747 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4748 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4749 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004750 }
4751
4752 /**
4753 * Returns the data network type for a subId
4754 */
4755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004756 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4757 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004758 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004759 mApp, subId, callingPackage, callingFeatureId,
4760 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004761 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4762 }
4763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 final long identity = Binder.clearCallingIdentity();
4765 try {
4766 final Phone phone = getPhone(subId);
4767 if (phone != null) {
4768 return phone.getServiceState().getDataNetworkType();
4769 } else {
4770 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4771 }
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004775 }
4776
4777 /**
Wink Saville36469e72014-06-11 15:17:00 -07004778 * Returns the Voice network type for a subId
4779 */
4780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004781 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4782 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004784 mApp, subId, callingPackage, callingFeatureId,
4785 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004786 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4787 }
4788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 final Phone phone = getPhone(subId);
4792 if (phone != null) {
4793 return phone.getServiceState().getVoiceNetworkType();
4794 } else {
4795 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4796 }
4797 } finally {
4798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004800 }
4801
4802 /**
4803 * @return true if a ICC card is present
4804 */
4805 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004806 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004807 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4808 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004809 }
4810
4811 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004812 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004813 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004814 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004815 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 final long identity = Binder.clearCallingIdentity();
4817 try {
4818 final Phone phone = PhoneFactory.getPhone(slotIndex);
4819 if (phone != null) {
4820 return phone.getIccCard().hasIccCard();
4821 } else {
4822 return false;
4823 }
4824 } finally {
4825 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004827 }
4828
4829 /**
4830 * Return if the current radio is LTE on CDMA. This
4831 * is a tri-state return value as for a period of time
4832 * the mode may be unknown.
4833 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004834 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004835 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004836 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004837 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004838 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004839 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4840 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4841 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004842 }
4843
Sanket Padawe356d7632015-06-22 14:03:32 -07004844 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004845 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4846 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004847 try {
4848 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4849 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004850 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4851 }
4852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 final long identity = Binder.clearCallingIdentity();
4854 try {
4855 final Phone phone = getPhone(subId);
4856 if (phone == null) {
4857 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4858 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004859 return TelephonyProperties.lte_on_cdma_device()
4860 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 }
4862 } finally {
4863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004864 }
Wink Saville36469e72014-06-11 15:17:00 -07004865 }
4866
Wink Saville36469e72014-06-11 15:17:00 -07004867 /**
4868 * {@hide}
4869 * Returns Default subId, 0 in the case of single standby.
4870 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004871 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004872 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004873 }
4874
Shishir Agrawala9f32182016-04-12 12:00:16 -07004875 private int getSlotForDefaultSubscription() {
4876 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4877 }
4878
Wink Savilleb564aae2014-10-23 10:18:09 -07004879 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004880 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004881 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004882
Pengquan Menge92a50d2018-09-21 15:54:48 -07004883 private boolean isActiveSubscription(int subId) {
4884 return mSubscriptionController.isActiveSubId(subId);
4885 }
4886
Ihab Awadf2177b72013-11-25 13:33:23 -08004887 /**
4888 * @see android.telephony.TelephonyManager.WifiCallingChoices
4889 */
4890 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 final long identity = Binder.clearCallingIdentity();
4892 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004893 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4895 getWhenToMakeWifiCallsDefaultPreference());
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
4898 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004899 }
4900
4901 /**
4902 * @see android.telephony.TelephonyManager.WifiCallingChoices
4903 */
4904 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905 final long identity = Binder.clearCallingIdentity();
4906 try {
4907 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004908 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004913 }
4914
Sailesh Nepald1e68152013-12-12 19:08:02 -08004915 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004916 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004917 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004918 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004919
Jordan Liu4c733742019-02-28 12:03:40 -08004920 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4921 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4922 if (phoneId == -1) {
4923 throw new IllegalArgumentException("Given slot index: " + slotIndex
4924 + " does not correspond to an active phone");
4925 }
4926 return PhoneFactory.getPhone(phoneId);
4927 }
4928
Shishir Agrawal566b7612013-10-28 14:41:00 -07004929 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004930 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4931 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4933 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004935 if (DBG) {
4936 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4937 }
4938 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4939 p2);
4940 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004941
Jordan Liu4c733742019-02-28 12:03:40 -08004942
4943 @Override
4944 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4945 int slotIndex, String callingPackage, String aid, int p2) {
4946 enforceModifyPermission();
4947 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4948 if (DBG) {
4949 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4950 }
4951 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4952 callingPackage, aid, p2);
4953 }
4954
4955 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4956 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957 final long identity = Binder.clearCallingIdentity();
4958 try {
4959 if (TextUtils.equals(ISDR_AID, aid)) {
4960 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004961 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4962 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 if (bestComponent == null
4964 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4965 loge("The calling package is not allowed to access ISD-R.");
4966 throw new SecurityException(
4967 "The calling package is not allowed to access ISD-R.");
4968 }
Derek Tan740e1672017-06-27 14:56:27 -07004969 }
Derek Tan740e1672017-06-27 14:56:27 -07004970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004972 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4973 null /* workSource */);
4974 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 return response;
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004979 }
4980
4981 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004982 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4984 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004985 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4986 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4987 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004988
Jordan Liu4c733742019-02-28 12:03:40 -08004989 @Override
4990 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4991 enforceModifyPermission();
4992 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4993 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4994 channel);
4995 }
4996
4997 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 final long identity = Binder.clearCallingIdentity();
4999 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 if (channel < 0) {
5001 return false;
5002 }
Jordan Liu4c733742019-02-28 12:03:40 -08005003 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5004 null /* workSource */);
5005 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 return success;
5007 } finally {
5008 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005009 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005010 }
5011
5012 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005013 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005014 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5016 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005017 if (DBG) {
5018 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5019 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5020 + p3 + " data=" + data);
5021 }
5022 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5023 command, p1, p2, p3, data);
5024 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005025
Jordan Liu4c733742019-02-28 12:03:40 -08005026 @Override
5027 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5028 int command, int p1, int p2, int p3, String data) {
5029 enforceModifyPermission();
5030 if (DBG) {
5031 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5032 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5033 + p3 + " data=" + data);
5034 }
5035 return iccTransmitApduLogicalChannelWithPermission(
5036 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5037 data);
5038 }
5039
5040 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5041 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 final long identity = Binder.clearCallingIdentity();
5043 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005044 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 return "";
5046 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005049 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5050 null /* workSource */);
5051 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053 // Append the returned status code to the end of the response payload.
5054 String s = Integer.toHexString(
5055 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5056 if (response.payload != null) {
5057 s = IccUtils.bytesToHexString(response.payload) + s;
5058 }
5059 return s;
5060 } finally {
5061 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005062 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005063 }
Jake Hambye994d462014-02-03 13:10:13 -08005064
Evan Charltonc66da362014-05-16 14:06:40 -07005065 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005066 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5067 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5069 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005071 if (DBG) {
5072 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5073 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5074 }
5075 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5076 cla, command, p1, p2, p3, data);
5077 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005078
Jordan Liu4c733742019-02-28 12:03:40 -08005079 @Override
5080 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5081 int command, int p1, int p2, int p3, String data) {
5082 enforceModifyPermission();
5083 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5084 if (DBG) {
5085 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5086 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5087 + " data=" + data);
5088 }
5089
5090 return iccTransmitApduBasicChannelWithPermission(
5091 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5092 p2, p3, data);
5093 }
5094
5095 // open APDU basic channel assuming the caller has sufficient permissions
5096 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5097 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 final long identity = Binder.clearCallingIdentity();
5099 try {
5100 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5101 && TextUtils.equals(ISDR_AID, data)) {
5102 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005103 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5104 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 if (bestComponent == null
5106 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5107 loge("The calling package is not allowed to select ISD-R.");
5108 throw new SecurityException(
5109 "The calling package is not allowed to select ISD-R.");
5110 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005111 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005114 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5115 null /* workSource */);
5116 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118 // Append the returned status code to the end of the response payload.
5119 String s = Integer.toHexString(
5120 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5121 if (response.payload != null) {
5122 s = IccUtils.bytesToHexString(response.payload) + s;
5123 }
5124 return s;
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005127 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005128 }
5129
5130 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005131 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005132 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5134 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136 final long identity = Binder.clearCallingIdentity();
5137 try {
5138 if (DBG) {
5139 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5140 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5141 }
5142
5143 IccIoResult response =
5144 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5145 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5146 subId);
5147
5148 if (DBG) {
5149 log("Exchange SIM_IO [R]" + response);
5150 }
5151
5152 byte[] result = null;
5153 int length = 2;
5154 if (response.payload != null) {
5155 length = 2 + response.payload.length;
5156 result = new byte[length];
5157 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5158 } else {
5159 result = new byte[length];
5160 }
5161
5162 result[length - 1] = (byte) response.sw2;
5163 result[length - 2] = (byte) response.sw1;
5164 return result;
5165 } finally {
5166 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005167 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005168 }
5169
Nathan Haroldb3014052017-01-25 15:57:32 -08005170 /**
5171 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5172 * on a particular subscription
5173 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005174 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5175 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005177 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005178 return null;
5179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180
5181 final long identity = Binder.clearCallingIdentity();
5182 try {
5183 if (appType != TelephonyManager.APPTYPE_USIM
5184 && appType != TelephonyManager.APPTYPE_SIM) {
5185 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5186 return null;
5187 }
5188 Object response = sendRequest(
5189 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5190 if (response instanceof String[]) {
5191 return (String[]) response;
5192 }
yincheng zhao2737e882019-09-06 17:06:54 -07005193 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005195 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 } finally {
5197 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005198 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005199 }
5200
yincheng zhao2737e882019-09-06 17:06:54 -07005201 /**
5202 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5203 * subscription.
5204 *
5205 * @param subId the id of the subscription.
5206 * @param appType the uicc app type, must be USIM or SIM.
5207 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5208 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005209 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005210 * @return number of fplmns that is successfully written to the SIM.
5211 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005212 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5213 String callingFeatureId) {
5214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5215 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005216 if (DBG) logv("no permissions for setForbiddenplmns");
5217 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5218 }
5219 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5220 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5221 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5222 }
5223 if (fplmns == null) {
5224 throw new IllegalArgumentException("Fplmn List provided is null");
5225 }
5226 for (String fplmn : fplmns) {
5227 if (!CellIdentity.isValidPlmn(fplmn)) {
5228 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5229 }
5230 }
5231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 Object response = sendRequest(
5234 CMD_SET_FORBIDDEN_PLMNS,
5235 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5236 subId);
5237 return (int) response;
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
5240 }
5241 }
5242
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005243 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005244 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5246 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 final long identity = Binder.clearCallingIdentity();
5249 try {
5250 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5251 if (response.payload == null) {
5252 return "";
5253 }
Evan Charltonc66da362014-05-16 14:06:40 -07005254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 // Append the returned status code to the end of the response payload.
5256 String s = Integer.toHexString(
5257 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5258 s = IccUtils.bytesToHexString(response.payload) + s;
5259 return s;
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
Evan Charltonc66da362014-05-16 14:06:40 -07005263 }
5264
Jake Hambye994d462014-02-03 13:10:13 -08005265 /**
5266 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5267 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5268 *
5269 * @param itemID the ID of the item to read
5270 * @return the NV item as a String, or null on error.
5271 */
5272 @Override
5273 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5276 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277
5278 final long identity = Binder.clearCallingIdentity();
5279 try {
5280 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005281 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5283 return value;
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
Jake Hambye994d462014-02-03 13:10:13 -08005287 }
5288
5289 /**
5290 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5291 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5292 *
5293 * @param itemID the ID of the item to read
5294 * @param itemValue the value to write, as a String
5295 * @return true on success; false on any failure
5296 */
5297 @Override
5298 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005299 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5301 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302
5303 final long identity = Binder.clearCallingIdentity();
5304 try {
5305 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5306 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005307 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5309 return success;
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
5312 }
Jake Hambye994d462014-02-03 13:10:13 -08005313 }
5314
5315 /**
5316 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5317 * Used for device configuration by some CDMA operators.
5318 *
5319 * @param preferredRoamingList byte array containing the new PRL
5320 * @return true on success; false on any failure
5321 */
5322 @Override
5323 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5325 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326
5327 final long identity = Binder.clearCallingIdentity();
5328 try {
5329 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5330 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5331 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5332 return success;
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
Jake Hambye994d462014-02-03 13:10:13 -08005336 }
5337
5338 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005339 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005340 * Used for device configuration by some CDMA operators.
5341 *
chen xu6dac5ab2018-10-26 17:39:23 -07005342 * @param slotIndex - device slot.
5343 *
Jake Hambye994d462014-02-03 13:10:13 -08005344 * @return true on success; false on any failure
5345 */
5346 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005347 public boolean resetModemConfig(int slotIndex) {
5348 Phone phone = PhoneFactory.getPhone(slotIndex);
5349 if (phone != null) {
5350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5351 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352
chen xu6dac5ab2018-10-26 17:39:23 -07005353 final long identity = Binder.clearCallingIdentity();
5354 try {
5355 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5356 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5357 return success;
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 }
chen xu6dac5ab2018-10-26 17:39:23 -07005362 return false;
5363 }
5364
5365 /**
5366 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5367 *
5368 * @param slotIndex - device slot.
5369 *
5370 * @return true on success; false on any failure
5371 */
5372 @Override
5373 public boolean rebootModem(int slotIndex) {
5374 Phone phone = PhoneFactory.getPhone(slotIndex);
5375 if (phone != null) {
5376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5377 mApp, phone.getSubId(), "rebootModem");
5378
5379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5382 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5383 return success;
5384 } finally {
5385 Binder.restoreCallingIdentity(identity);
5386 }
5387 }
5388 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005389 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005390
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005391 public String[] getPcscfAddress(String apnType, String callingPackage,
5392 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005393 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5395 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005396 return new String[0];
5397 }
5398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 final long identity = Binder.clearCallingIdentity();
5400 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005401 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 } finally {
5403 Binder.restoreCallingIdentity(identity);
5404 }
Wink Saville36469e72014-06-11 15:17:00 -07005405 }
5406
Brad Ebinger51f743a2017-01-23 13:50:20 -08005407 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005408 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5409 * {@link #disableIms(int)}.
5410 * @param slotIndex device slot.
5411 */
5412 public void resetIms(int slotIndex) {
5413 enforceModifyPermission();
5414
5415 final long identity = Binder.clearCallingIdentity();
5416 try {
5417 if (mImsResolver == null) {
5418 // may happen if the does not support IMS.
5419 return;
5420 }
5421 mImsResolver.disableIms(slotIndex);
5422 mImsResolver.enableIms(slotIndex);
5423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
5426 }
5427
5428 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005429 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5430 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005431 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005432 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005433 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434
5435 final long identity = Binder.clearCallingIdentity();
5436 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005437 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005438 // may happen if the device does not support IMS.
5439 return;
5440 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005441 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005445 }
5446
5447 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005448 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5449 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005450 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005451 public void disableIms(int slotId) {
5452 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453
5454 final long identity = Binder.clearCallingIdentity();
5455 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005456 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005457 // may happen if the device does not support IMS.
5458 return;
5459 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005460 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005464 }
5465
5466 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005467 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5468 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005469 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005470 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005471 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005472 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473
5474 final long identity = Binder.clearCallingIdentity();
5475 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005476 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005477 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5478 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005479 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005480 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005484 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005485 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005486 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5487 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005488 @Override
5489 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005490 enforceModifyPermission();
5491
5492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005495 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
5499 }
5500
5501 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005502 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005503 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005504 */
5505 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507
5508 final long identity = Binder.clearCallingIdentity();
5509 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005510 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005511 // may happen if the device does not support IMS.
5512 return null;
5513 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005514 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005518 }
5519
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005520 /**
5521 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005522 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005523 */
5524 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526
5527 final long identity = Binder.clearCallingIdentity();
5528 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005529 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005530 // may happen if the device does not support IMS.
5531 return null;
5532 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005533 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005537 }
5538
Brad Ebinger884c07b2018-02-15 16:17:40 -08005539 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005540 * Sets the ImsService Package Name that Telephony will bind to.
5541 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005542 * @param slotIndex the slot ID that the ImsService should bind for.
5543 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005544 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005545 * @param featureTypes An integer array of feature types associated with a packageName.
5546 * @param packageName The name of the package that the current configuration will be replaced
5547 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005548 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005549 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005550 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5551 int[] featureTypes, String packageName) {
5552 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5555 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005556 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 final long identity = Binder.clearCallingIdentity();
5559 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005560 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005561 // may happen if the device does not support IMS.
5562 return false;
5563 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005564 Map<Integer, String> featureConfig = new HashMap<>();
5565 for (int featureType : featureTypes) {
5566 featureConfig.put(featureType, packageName);
5567 }
5568 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5569 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005573 }
5574
5575 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005576 * Clears any carrier ImsService overrides for the slot index specified that were previously
5577 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5578 *
5579 * This should only be used for testing.
5580 *
5581 * @param slotIndex the slot ID that the ImsService should bind for.
5582 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5583 */
5584 @Override
5585 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5586 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5587 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5588 "clearCarrierImsServiceOverride");
5589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5590 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5591 "clearCarrierImsServiceOverride");
5592
5593 final long identity = Binder.clearCallingIdentity();
5594 try {
5595 if (mImsResolver == null) {
5596 // may happen if the device does not support IMS.
5597 return false;
5598 }
5599 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
5603 }
5604
5605 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005606 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005607 *
5608 * @param slotId The slot that the ImsService is associated with.
5609 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5610 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005611 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005612 * @return the package name of the ImsService configuration.
5613 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005614 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5615 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005616 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005617 TelephonyPermissions
5618 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5619 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5620 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 final long identity = Binder.clearCallingIdentity();
5623 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005624 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005625 // may happen if the device does not support IMS.
5626 return "";
5627 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005628 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005629 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5630 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005634 }
5635
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005636 /**
5637 * Get the MmTelFeature state associated with the requested subscription id.
5638 * @param subId The subscription that the MmTelFeature is associated with.
5639 * @param callback A callback with an integer containing the
5640 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5641 */
5642 @Override
5643 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5644 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5645 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5646 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5647 "IMS not available on device.");
5648 }
5649 final long token = Binder.clearCallingIdentity();
5650 try {
5651 int slotId = getSlotIndex(subId);
5652 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5653 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5654 + subId + "'");
5655 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5656 }
5657 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5658 try {
5659 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5660 } catch (RemoteException e) {
5661 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5662 + "Ignore");
5663 }
5664 });
5665 } finally {
5666 Binder.restoreCallingIdentity(token);
5667 }
5668 }
5669
Daniel Brightbb5840b2021-01-12 15:48:18 -08005670 /**
5671 * Sets the ims registration state on all valid {@link Phone}s.
5672 */
5673 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005678 // NOTE: Before S, this method only set the default phone.
5679 for (final Phone phone : PhoneFactory.getPhones()) {
5680 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5681 phone.setImsRegistrationState(registered);
5682 }
5683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
Wink Saville36469e72014-06-11 15:17:00 -07005687 }
5688
5689 /**
Stuart Scott54788802015-03-30 13:18:01 -07005690 * Set the network selection mode to automatic.
5691 *
5692 */
5693 @Override
5694 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5696 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697
5698 final long identity = Binder.clearCallingIdentity();
5699 try {
shilufc958392020-01-20 11:36:01 -08005700 if (!isActiveSubscription(subId)) {
5701 return;
5702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5704 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Stuart Scott54788802015-03-30 13:18:01 -07005708 }
5709
Jack Yud10cdd42020-09-28 20:28:01 -07005710 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005711 * Ask the radio to connect to the input network and change selection mode to manual.
5712 *
5713 * @param subId the id of the subscription.
5714 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5715 * the operator to attach to.
5716 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5717 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5718 * normal network selection next time.
5719 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005720 */
5721 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005722 public boolean setNetworkSelectionModeManual(
5723 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5725 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005726
5727 if (!isActiveSubscription(subId)) {
5728 return false;
5729 }
5730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 final long identity = Binder.clearCallingIdentity();
5732 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005733 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005735 if (DBG) {
5736 log("setNetworkSelectionModeManual: subId: " + subId
5737 + " operator: " + operatorInfo);
5738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005743 }
shilu84f6e8b2019-12-19 13:58:01 -08005744 /**
5745 * Get the manual network selection
5746 *
5747 * @param subId the id of the subscription.
5748 *
5749 * @return the previously saved user selected PLMN
5750 */
5751 @Override
5752 public String getManualNetworkSelectionPlmn(int subId) {
5753 TelephonyPermissions
5754 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5755 mApp, subId, "getManualNetworkSelectionPlmn");
5756
5757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005760 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005761 }
5762
5763 final Phone phone = getPhone(subId);
5764 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005765 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005766 }
5767 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5768 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5769 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
5773 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005774
5775 /**
5776 * Scans for available networks.
5777 */
5778 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005779 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5780 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5782 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005783 LocationAccessPolicy.LocationPermissionResult locationResult =
5784 LocationAccessPolicy.checkLocationPermission(mApp,
5785 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5786 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005787 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005788 .setCallingPid(Binder.getCallingPid())
5789 .setCallingUid(Binder.getCallingUid())
5790 .setMethod("getCellNetworkScanResults")
5791 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005792 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5793 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005794 .build());
5795 switch (locationResult) {
5796 case DENIED_HARD:
5797 throw new SecurityException("Not allowed to access scan results -- location");
5798 case DENIED_SOFT:
5799 return null;
5800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801
Pengquan Menga1bb6272018-09-06 09:59:22 -07005802 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803 try {
5804 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005805 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807 } finally {
5808 Binder.restoreCallingIdentity(identity);
5809 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005810 }
5811
5812 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005813 * Get the call forwarding info, given the call forwarding reason.
5814 */
5815 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005816 public void getCallForwarding(int subId, int callForwardingReason,
5817 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005818 enforceReadPrivilegedPermission("getCallForwarding");
5819 long identity = Binder.clearCallingIdentity();
5820 try {
5821 if (DBG) {
5822 log("getCallForwarding: subId " + subId
5823 + " callForwardingReason" + callForwardingReason);
5824 }
Hall Liu27d24262020-09-18 19:04:59 -07005825
5826 Phone phone = getPhone(subId);
5827 if (phone == null) {
5828 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005829 callback.onError(
5830 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005831 } catch (RemoteException e) {
5832 // ignore
5833 }
5834 return;
5835 }
5836
5837 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5838 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5839 @Override
5840 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5841 try {
5842 callback.onCallForwardingInfoAvailable(info);
5843 } catch (RemoteException e) {
5844 // ignore
5845 }
5846 }
5847
5848 @Override
5849 public void onError(int error) {
5850 try {
5851 callback.onError(error);
5852 } catch (RemoteException e) {
5853 // ignore
5854 }
5855 }
5856 });
5857 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
5861 }
5862
5863 /**
5864 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5865 * reason, the number to forward, and the timeout before the forwarding is attempted.
5866 */
5867 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005868 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5869 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005870 enforceModifyPermission();
5871 long identity = Binder.clearCallingIdentity();
5872 try {
5873 if (DBG) {
5874 log("setCallForwarding: subId " + subId
5875 + " callForwardingInfo" + callForwardingInfo);
5876 }
Hall Liu27d24262020-09-18 19:04:59 -07005877
5878 Phone phone = getPhone(subId);
5879 if (phone == null) {
5880 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005881 callback.accept(
5882 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005883 } catch (RemoteException e) {
5884 // ignore
5885 }
5886 return;
5887 }
5888
5889 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5890 FunctionalUtils.ignoreRemoteException(callback::accept));
5891
5892 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
5896 }
5897
5898 /**
Hall Liu27d24262020-09-18 19:04:59 -07005899 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005900 */
5901 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005902 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005903 enforceReadPrivilegedPermission("getCallForwarding");
5904 long identity = Binder.clearCallingIdentity();
5905 try {
Hall Liu27d24262020-09-18 19:04:59 -07005906
5907 Phone phone = getPhone(subId);
5908 if (phone == null) {
5909 try {
5910 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5911 } catch (RemoteException e) {
5912 // ignore
5913 }
5914 return;
5915 }
5916
5917 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5918
Shuo Qian4a594052020-01-23 11:59:30 -08005919 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005920 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
5924 }
5925
5926 /**
Hall Liu27d24262020-09-18 19:04:59 -07005927 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005928 */
5929 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005930 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005931 enforceModifyPermission();
5932 long identity = Binder.clearCallingIdentity();
5933 try {
Hall Liu27d24262020-09-18 19:04:59 -07005934 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5935
5936 Phone phone = getPhone(subId);
5937 if (phone == null) {
5938 try {
5939 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5940 } catch (RemoteException e) {
5941 // ignore
5942 }
5943 return;
5944 }
5945
5946 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5947 FunctionalUtils.ignoreRemoteException(callback::accept));
5948
5949 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005950 } finally {
5951 Binder.restoreCallingIdentity(identity);
5952 }
5953 }
5954
5955 /**
yinxub1bed742017-04-17 11:45:04 -07005956 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005957 *
yinxub1bed742017-04-17 11:45:04 -07005958 * @param subId id of the subscription
5959 * @param request contains the radio access networks with bands/channels to scan
5960 * @param messenger callback messenger for scan results or errors
5961 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005962 * @return the id of the requested scan which can be used to stop the scan.
5963 */
5964 @Override
5965 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005966 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5968 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005969 LocationAccessPolicy.LocationPermissionResult locationResult =
5970 LocationAccessPolicy.checkLocationPermission(mApp,
5971 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5972 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005973 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005974 .setCallingPid(Binder.getCallingPid())
5975 .setCallingUid(Binder.getCallingUid())
5976 .setMethod("requestNetworkScan")
5977 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005978 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5979 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005980 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005981 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005982 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5983 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005984 if (e != null) {
5985 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5986 throw e;
5987 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005988 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005989 return TelephonyScanManager.INVALID_SCAN_ID;
5990 }
5991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 }
Hall Liu912dfd32019-04-25 14:02:26 -07005993 int callingUid = Binder.getCallingUid();
5994 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005995 final long identity = Binder.clearCallingIdentity();
5996 try {
5997 return mNetworkScanRequestTracker.startNetworkScan(
5998 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005999 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006000 } finally {
6001 Binder.restoreCallingIdentity(identity);
6002 }
yinxu504e1392017-04-12 16:03:22 -07006003 }
6004
Hall Liub2ac8ef2019-02-28 15:56:23 -08006005 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006006 NetworkScanRequest request, int subId, String callingPackage) {
6007 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006008 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6009 boolean hasNetworkScanPermission =
6010 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6011 == PERMISSION_GRANTED;
6012
6013 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6014 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6015 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006016 }
6017
6018 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6019 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006020 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6021 return new SecurityException("Specific channels must not be"
6022 + " scanned without location access.");
6023 }
6024 }
6025 }
6026
Hall Liub2ac8ef2019-02-28 15:56:23 -08006027 return null;
6028 }
6029
yinxu504e1392017-04-12 16:03:22 -07006030 /**
6031 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006032 *
6033 * @param subId id of the subscription
6034 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006035 */
6036 @Override
6037 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6039 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040
Hall Liu912dfd32019-04-25 14:02:26 -07006041 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 final long identity = Binder.clearCallingIdentity();
6043 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006044 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 } finally {
6046 Binder.restoreCallingIdentity(identity);
6047 }
yinxu504e1392017-04-12 16:03:22 -07006048 }
6049
6050 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006051 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006052 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006053 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006054 */
6055 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006056 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006057 TelephonyPermissions
6058 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006059 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060
6061 final long identity = Binder.clearCallingIdentity();
6062 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006063 if (DBG) log("getAllowedNetworkTypesBitmask");
6064 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6065 int networkTypesBitmask = (result != null ? result[0] : -1);
6066 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6067 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006071 }
6072
6073 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006074 * Get the allowed network types for certain reason.
6075 *
6076 * @param subId the id of the subscription.
6077 * @param reason the reason the allowed network type change is taking place
6078 * @return the allowed network types.
6079 */
6080 @Override
6081 public long getAllowedNetworkTypesForReason(int subId,
6082 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6083 TelephonyPermissions
6084 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6085 mApp, subId, "getAllowedNetworkTypesForReason");
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6089 } finally {
6090 Binder.restoreCallingIdentity(identity);
6091 }
6092 }
6093
6094 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006095 * Enable/Disable E-UTRA-NR Dual Connectivity
6096 * @param subId subscription id of the sim card
6097 * @param nrDualConnectivityState expected NR dual connectivity state
6098 * This can be passed following states
6099 * <ol>
6100 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6101 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6102 * <li>Disable NR dual connectivity and force secondary cell to be released
6103 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6104 * </ol>
6105 * @return operation result.
6106 */
6107 @Override
6108 public int setNrDualConnectivityState(int subId,
6109 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6111 mApp, subId, "enableNRDualConnectivity");
6112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6113 final long identity = Binder.clearCallingIdentity();
6114 try {
6115 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6116 nrDualConnectivityState, subId,
6117 workSource);
6118 if (DBG) log("enableNRDualConnectivity result: " + result);
6119 return result;
6120 } finally {
6121 Binder.restoreCallingIdentity(identity);
6122 }
6123 }
6124
6125 /**
6126 * Is E-UTRA-NR Dual Connectivity enabled
6127 * @return true if dual connectivity is enabled else false
6128 */
6129 @Override
6130 public boolean isNrDualConnectivityEnabled(int subId) {
6131 TelephonyPermissions
6132 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6133 mApp, subId, "isNRDualConnectivityEnabled");
6134 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6135 final long identity = Binder.clearCallingIdentity();
6136 try {
6137 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6138 null, subId, workSource);
6139 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6140 return isEnabled;
6141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
6144 }
6145
6146 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006147 * get carrier bandwidth per primary and secondary carrier
6148 * @param subId subscription id of the sim card
6149 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6150 */
6151 @Override
6152 public CarrierBandwidth getCarrierBandwidth(int subId) {
6153 TelephonyPermissions
6154 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6155 mApp, subId, "isNRDualConnectivityEnabled");
6156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6157 final long identity = Binder.clearCallingIdentity();
6158 try {
6159 CarrierBandwidth carrierBandwidth =
6160 getPhoneFromSubId(subId).getCarrierBandwidth();
6161 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6162 return carrierBandwidth;
6163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
6166 }
6167
6168 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006169 * Set the allowed network types of the device and
6170 * provide the reason triggering the allowed network change.
6171 *
6172 * @param subId the id of the subscription.
6173 * @param reason the reason the allowed network type change is taking place
6174 * @param allowedNetworkTypes the allowed network types.
6175 * @return true on success; false on any failure.
6176 */
6177 @Override
6178 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006179 @TelephonyManager.AllowedNetworkTypesReason int reason,
6180 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6182 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006183 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6184 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6185 return false;
6186 }
6187
6188 if (DBG) {
6189 log("setAllowedNetworkTypesForReason: " + reason
6190 + " value: " + allowedNetworkTypes);
6191 }
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006192 final long identity = Binder.clearCallingIdentity();
6193 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006194 Boolean success = (Boolean) sendRequest(
6195 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6196 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6197
6198 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6199 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
6203 }
6204
6205 /**
Miaoa84611c2019-03-15 09:21:10 +08006206 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006207 *
Miaoa84611c2019-03-15 09:21:10 +08006208 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006209 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006210 * @hide
6211 */
6212 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006213 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006214 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006216 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217 try {
Miaoa84611c2019-03-15 09:21:10 +08006218 if (phone != null) {
6219 return phone.hasMatchedTetherApnSetting();
6220 } else {
6221 return false;
6222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006223 } finally {
6224 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006225 }
Junda Liu475951f2014-11-07 16:45:03 -08006226 }
6227
6228 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006229 * Enable or disable always reporting signal strength changes from radio.
6230 *
6231 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6232 */
6233 @Override
6234 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6235 enforceModifyPermission();
6236 enforceSystemCaller();
6237
6238 final long identity = Binder.clearCallingIdentity();
6239 final Phone phone = getPhone(subId);
6240 try {
6241 if (phone != null) {
6242 if (DBG) {
6243 log("setAlwaysReportSignalStrength: subId=" + subId
6244 + " isEnable=" + isEnable);
6245 }
6246 phone.setAlwaysReportSignalStrength(isEnable);
6247 } else {
6248 loge("setAlwaysReportSignalStrength: no phone found for subId="
6249 + subId);
6250 }
6251 } finally {
6252 Binder.restoreCallingIdentity(identity);
6253 }
6254 }
6255
6256 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006257 * Get the user enabled state of Mobile Data.
6258 *
6259 * TODO: remove and use isUserDataEnabled.
6260 * This can't be removed now because some vendor codes
6261 * calls through ITelephony directly while they should
6262 * use TelephonyManager.
6263 *
6264 * @return true on enabled
6265 */
6266 @Override
6267 public boolean getDataEnabled(int subId) {
6268 return isUserDataEnabled(subId);
6269 }
6270
6271 /**
6272 * Get whether mobile data is enabled per user setting.
6273 *
6274 * There are other factors deciding whether mobile data is actually enabled, but they are
6275 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006276 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006277 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006278 *
6279 * @return {@code true} if data is enabled else {@code false}
6280 */
6281 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006282 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006283 try {
6284 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6285 null);
6286 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6288 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290
6291 final long identity = Binder.clearCallingIdentity();
6292 try {
6293 int phoneId = mSubscriptionController.getPhoneId(subId);
6294 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6295 Phone phone = PhoneFactory.getPhone(phoneId);
6296 if (phone != null) {
6297 boolean retVal = phone.isUserDataEnabled();
6298 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6299 return retVal;
6300 } else {
6301 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6302 return false;
6303 }
6304 } finally {
6305 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006306 }
6307 }
6308
6309 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006310 * Checks if the device is capable of mobile data by considering whether whether the
6311 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6312 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006313 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006314 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006315 */
6316 @Override
6317 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006318 try {
6319 try {
6320 mApp.enforceCallingOrSelfPermission(
6321 android.Manifest.permission.ACCESS_NETWORK_STATE,
6322 null);
6323 } catch (Exception e) {
6324 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6325 "isDataEnabled");
6326 }
6327 } catch (Exception e) {
6328 enforceReadPrivilegedPermission("isDataEnabled");
6329 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330
6331 final long identity = Binder.clearCallingIdentity();
6332 try {
6333 int phoneId = mSubscriptionController.getPhoneId(subId);
6334 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6335 Phone phone = PhoneFactory.getPhone(phoneId);
6336 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006337 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6339 return retVal;
6340 } else {
6341 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6342 return false;
6343 }
6344 } finally {
6345 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006346 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006347 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006348
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006349 /**
6350 * Check if data is enabled for a specific reason
6351 * @param subId Subscription index
6352 * @param reason the reason the data enable change is taking place
6353 * @return {@code true} if the overall data is enabled; {@code false} if not.
6354 */
6355 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006356 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006357 @TelephonyManager.DataEnabledReason int reason) {
6358 try {
6359 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6360 null);
6361 } catch (Exception e) {
6362 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006363 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006364 }
6365
6366
6367 final long identity = Binder.clearCallingIdentity();
6368 try {
6369 int phoneId = mSubscriptionController.getPhoneId(subId);
6370 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006371 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006372 + " reason=" + reason);
6373 }
6374 Phone phone = PhoneFactory.getPhone(phoneId);
6375 if (phone != null) {
6376 boolean retVal;
6377 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6378 retVal = phone.isUserDataEnabled();
6379 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006380 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006381 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006382 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006383 return retVal;
6384 } else {
6385 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006386 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006387 + subId + " retVal=false");
6388 }
6389 return false;
6390 }
6391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
6394 }
6395
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006396 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006397 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006398 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6399 // Skip the check if it's one of these special uids
6400 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6401 }
6402
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006403 //load access rules from carrier configs, and check those as well: b/139133814
6404 SubscriptionController subController = SubscriptionController.getInstance();
6405 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6406 || subController == null) return privilegeFromSim;
6407
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006408 PackageManager pkgMgr = phone.getContext().getPackageManager();
6409 String[] packages = pkgMgr.getPackagesForUid(uid);
6410
6411 final long identity = Binder.clearCallingIdentity();
6412 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006413 int subId = phone.getSubId();
6414 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6415 // A test override is in place for the privileges for this subId, so don't try to
6416 // read the subscription privileges.
6417 return privilegeFromSim;
6418 }
6419 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006420 SubscriptionManager subManager = (SubscriptionManager)
6421 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6422 for (String pkg : packages) {
6423 if (subManager.canManageSubscription(subInfo, pkg)) {
6424 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6425 }
6426 }
6427 return privilegeFromSim;
6428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
6431 }
6432
6433 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6434 String pkgName) {
6435 //load access rules from carrier configs, and check those as well: b/139133814
6436 SubscriptionController subController = SubscriptionController.getInstance();
6437 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6438 || subController == null) return privilegeFromSim;
6439
6440 final long identity = Binder.clearCallingIdentity();
6441 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006442 int subId = phone.getSubId();
6443 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6444 // A test override is in place for the privileges for this subId, so don't try to
6445 // read the subscription privileges.
6446 return privilegeFromSim;
6447 }
6448 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006449 SubscriptionManager subManager = (SubscriptionManager)
6450 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6451 return subManager.canManageSubscription(subInfo, pkgName)
6452 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
6456 }
6457
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006458 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006459 public int getCarrierPrivilegeStatus(int subId) {
6460 final Phone phone = getPhone(subId);
6461 if (phone == null) {
6462 loge("getCarrierPrivilegeStatus: Invalid subId");
6463 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6464 }
6465 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006466 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006467 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006468 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6469 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006470
6471 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6472 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006473 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006474 }
Junda Liu29340342014-07-10 15:23:27 -07006475
6476 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006477 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006478 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006479 final Phone phone = getPhone(subId);
6480 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006481 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006482 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6483 }
6484 UiccProfile profile =
6485 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6486 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006487 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006488 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6489 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006490 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006491 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006492 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006493 }
6494
6495 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006496 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6497 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006498 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006499 }
6500
6501 int phoneId = SubscriptionManager.getPhoneId(subId);
6502 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006503 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006504 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006505 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6506 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006507 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6508 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6509 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006510 }
6511
6512 @Override
6513 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006514 if (TextUtils.isEmpty(pkgName))
6515 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006516 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6517 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6518 UiccCard card = UiccController.getInstance().getUiccCard(i);
6519 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006520 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006521 continue;
6522 }
6523
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006524 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6525 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6526 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006527 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6528 break;
6529 }
6530 }
6531
6532 return result;
Junda Liu29340342014-07-10 15:23:27 -07006533 }
Derek Tan89e89d42014-07-08 17:00:10 -07006534
6535 @Override
Junda Liue64de782015-04-16 17:19:16 -07006536 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6537 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6538 loge("phoneId " + phoneId + " is not valid.");
6539 return null;
6540 }
6541 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006542 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006543 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006544 return null ;
6545 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006546 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006547 }
6548
Amith Yamasani6e118872016-02-19 12:53:51 -08006549 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006550 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006551 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006552 List<String> privilegedPackages = new ArrayList<>();
6553 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006554 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6555 // has UICC in that slot.
6556 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006557 if (card.hasCarrierPrivilegeRules()) {
6558 if (packages == null) {
6559 // Only check packages in user 0 for now
6560 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006561 PackageManager.MATCH_DISABLED_COMPONENTS
6562 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006563 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006564 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006565 }
6566 for (int p = packages.size() - 1; p >= 0; p--) {
6567 PackageInfo pkgInfo = packages.get(p);
6568 if (pkgInfo != null && pkgInfo.packageName != null
6569 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006570 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006571 privilegedPackages.add(pkgInfo.packageName);
6572 }
6573 }
6574 }
6575 }
6576 return privilegedPackages;
6577 }
6578
chen xuf7e9fe82019-05-09 19:31:02 -07006579 @Override
6580 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006581 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6582
6583 final long identity = Binder.clearCallingIdentity();
6584
chen xuf7e9fe82019-05-09 19:31:02 -07006585 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006586 try {
6587 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6588 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6589 }
6590 } finally {
6591 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006592 }
6593 return privilegedPackages;
6594 }
6595
Wink Savilleb564aae2014-10-23 10:18:09 -07006596 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006597 final Phone phone = getPhone(subId);
6598 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006599 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006600 return null;
6601 }
6602 String iccId = card.getIccId();
6603 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006604 return null;
6605 }
6606 return iccId;
6607 }
6608
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006609 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006610 public void setCallComposerStatus(int subId, int status) {
6611 enforceModifyPermission();
6612
6613 final long identity = Binder.clearCallingIdentity();
6614 try {
6615 Phone phone = getPhone(subId);
6616 if (phone != null) {
6617 Phone defaultPhone = phone.getImsPhone();
6618 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6619 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6620 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006621 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6622 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006623 }
6624 }
Shuo Qian284ae752020-12-22 19:10:14 -08006625 } catch (ImsException e) {
6626 throw new ServiceSpecificException(e.getCode());
6627 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006628 Binder.restoreCallingIdentity(identity);
6629 }
6630 }
6631
6632 @Override
6633 public int getCallComposerStatus(int subId) {
6634 enforceReadPrivilegedPermission("getCallComposerStatus");
6635
6636 final long identity = Binder.clearCallingIdentity();
6637 try {
6638 Phone phone = getPhone(subId);
6639 if (phone != null) {
6640 Phone defaultPhone = phone.getImsPhone();
6641 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6642 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6643 return imsPhone.getCallComposerStatus();
6644 }
6645 }
6646 } finally {
6647 Binder.restoreCallingIdentity(identity);
6648 }
6649 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6650 }
6651
6652 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006653 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6654 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006655 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006656 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 final long identity = Binder.clearCallingIdentity();
6659 try {
6660 final String iccId = getIccId(subId);
6661 final Phone phone = getPhone(subId);
6662 if (phone == null) {
6663 return false;
6664 }
6665 final String subscriberId = phone.getSubscriberId();
6666
6667 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006668 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 + subscriberId + " to " + number);
6670 }
6671
6672 if (TextUtils.isEmpty(iccId)) {
6673 return false;
6674 }
6675
6676 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6677
6678 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6679 if (alphaTag == null) {
6680 editor.remove(alphaTagPrefKey);
6681 } else {
6682 editor.putString(alphaTagPrefKey, alphaTag);
6683 }
6684
6685 // Record both the line number and IMSI for this ICCID, since we need to
6686 // track all merged IMSIs based on line number
6687 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6688 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6689 if (number == null) {
6690 editor.remove(numberPrefKey);
6691 editor.remove(subscriberPrefKey);
6692 } else {
6693 editor.putString(numberPrefKey, number);
6694 editor.putString(subscriberPrefKey, subscriberId);
6695 }
6696
6697 editor.commit();
6698 return true;
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006701 }
Derek Tan7226c842014-07-02 17:42:23 -07006702 }
6703
6704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006705 public String getLine1NumberForDisplay(int subId, String callingPackage,
6706 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006707 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006709 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006710 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006711 return null;
6712 }
Derek Tan97ebb422014-09-05 16:55:38 -07006713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 final long identity = Binder.clearCallingIdentity();
6715 try {
6716 String iccId = getIccId(subId);
6717 if (iccId != null) {
6718 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6719 if (DBG_MERGE) {
6720 log("getLine1NumberForDisplay returning "
6721 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6722 }
6723 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6726 return null;
6727 } finally {
6728 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006729 }
Derek Tan7226c842014-07-02 17:42:23 -07006730 }
6731
6732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006733 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6734 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006736 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006737 return null;
6738 }
Derek Tan97ebb422014-09-05 16:55:38 -07006739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740 final long identity = Binder.clearCallingIdentity();
6741 try {
6742 String iccId = getIccId(subId);
6743 if (iccId != null) {
6744 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6745 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6746 }
6747 return null;
6748 } finally {
6749 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006750 }
Derek Tan7226c842014-07-02 17:42:23 -07006751 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006752
6753 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006754 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6755 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006756 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6757 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006758 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006759 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006760 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006761 return null;
6762 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006763
Jordan Liub49b04b2019-05-06 14:45:15 -07006764 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6765 // the process, where TelephonyManager was instantiated.
6766 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006767 final long identity = Binder.clearCallingIdentity();
6768 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006769 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 final TelephonyManager tele = TelephonyManager.from(context);
6771 final SubscriptionManager sub = SubscriptionManager.from(context);
6772
6773 // Figure out what subscribers are currently active
6774 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775
Jordan Liub49b04b2019-05-06 14:45:15 -07006776 // Only consider subs which match the current subId
6777 // This logic can be simplified. See b/131189269 for progress.
6778 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006779 activeSubscriberIds.add(tele.getSubscriberId(subId));
6780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781
6782 // First pass, find a number override for an active subscriber
6783 String mergeNumber = null;
6784 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6785 for (String key : prefs.keySet()) {
6786 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6787 final String subscriberId = (String) prefs.get(key);
6788 if (activeSubscriberIds.contains(subscriberId)) {
6789 final String iccId = key.substring(
6790 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6791 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6792 mergeNumber = (String) prefs.get(numberKey);
6793 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006794 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 + " for active subscriber " + subscriberId);
6796 }
6797 if (!TextUtils.isEmpty(mergeNumber)) {
6798 break;
6799 }
6800 }
6801 }
6802 }
6803
6804 // Shortcut when no active merged subscribers
6805 if (TextUtils.isEmpty(mergeNumber)) {
6806 return null;
6807 }
6808
6809 // Second pass, find all subscribers under that line override
6810 final ArraySet<String> result = new ArraySet<>();
6811 for (String key : prefs.keySet()) {
6812 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6813 final String number = (String) prefs.get(key);
6814 if (mergeNumber.equals(number)) {
6815 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6816 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6817 final String subscriberId = (String) prefs.get(subscriberKey);
6818 if (!TextUtils.isEmpty(subscriberId)) {
6819 result.add(subscriberId);
6820 }
6821 }
6822 }
6823 }
6824
6825 final String[] resultArray = result.toArray(new String[result.size()]);
6826 Arrays.sort(resultArray);
6827 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006828 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6830 }
6831 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006832 } finally {
6833 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006834 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006835 }
6836
6837 @Override
zoey chen38003472019-12-13 17:16:31 +08006838 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6839 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006840
6841 final long identity = Binder.clearCallingIdentity();
6842 try {
6843 final TelephonyManager telephonyManager = mApp.getSystemService(
6844 TelephonyManager.class);
6845 String subscriberId = telephonyManager.getSubscriberId(subId);
6846 if (subscriberId == null) {
6847 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006848 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006849 + subId);
6850 }
6851 return null;
6852 }
6853
6854 final SubscriptionInfo info = SubscriptionController.getInstance()
6855 .getSubscriptionInfo(subId);
6856 final ParcelUuid groupUuid = info.getGroupUuid();
6857 // If it doesn't belong to any group, return just subscriberId of itself.
6858 if (groupUuid == null) {
6859 return new String[]{subscriberId};
6860 }
6861
6862 // Get all subscriberIds from the group.
6863 final List<String> mergedSubscriberIds = new ArrayList<>();
6864 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006865 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006866 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006867 for (SubscriptionInfo subInfo : groupInfos) {
6868 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6869 if (subscriberId != null) {
6870 mergedSubscriberIds.add(subscriberId);
6871 }
6872 }
6873
6874 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
6877
6878 }
6879 }
6880
6881 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006882 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006883 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006884 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885
6886 final long identity = Binder.clearCallingIdentity();
6887 try {
6888 final Phone phone = getPhone(subId);
6889 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6890 } finally {
6891 Binder.restoreCallingIdentity(identity);
6892 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006893 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006894
6895 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006896 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006897 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6898 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006899 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6900 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006901
6902 final long identity = Binder.clearCallingIdentity();
6903 try {
6904 final Phone phone = getPhone(subId);
6905 if (phone == null) {
6906 return false;
6907 }
6908 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6909 cdmaNonRoamingList);
6910 } finally {
6911 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006912 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006913 }
6914
6915 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006916 @Deprecated
6917 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6918 enforceModifyPermission();
6919
6920 int returnValue = 0;
6921 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006922 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006923 if(result.exception == null) {
6924 if (result.result != null) {
6925 byte[] responseData = (byte[])(result.result);
6926 if(responseData.length > oemResp.length) {
6927 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6928 responseData.length + "bytes. Buffer Size is " +
6929 oemResp.length + "bytes.");
6930 }
6931 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6932 returnValue = responseData.length;
6933 }
6934 } else {
6935 CommandException ex = (CommandException) result.exception;
6936 returnValue = ex.getCommandError().ordinal();
6937 if(returnValue > 0) returnValue *= -1;
6938 }
6939 } catch (RuntimeException e) {
6940 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6941 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6942 if(returnValue > 0) returnValue *= -1;
6943 }
6944
6945 return returnValue;
6946 }
6947
6948 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006949 public void setRadioCapability(RadioAccessFamily[] rafs) {
6950 try {
6951 ProxyController.getInstance().setRadioCapability(rafs);
6952 } catch (RuntimeException e) {
6953 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6954 }
6955 }
6956
6957 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006958 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006959 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006960 try {
6961 TelephonyPermissions
6962 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6963 mApp, phone.getSubId(), "getRadioAccessFamily");
6964 } catch (SecurityException e) {
6965 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6966 throw e;
6967 }
chen xub97461a2018-10-26 14:17:57 -07006968 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006969 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006970 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006971 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 final long identity = Binder.clearCallingIdentity();
6973 try {
chen xub97461a2018-10-26 14:17:57 -07006974 TelephonyPermissions
6975 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6976 mApp, phone.getSubId(), "getRadioAccessFamily");
6977 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 } finally {
6979 Binder.restoreCallingIdentity(identity);
6980 }
chen xub97461a2018-10-26 14:17:57 -07006981 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006982 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006983
6984 @Override
Hall Liu82694d52020-12-11 18:22:04 -08006985 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08006986 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08006987 try {
6988 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
6989 Binder.getCallingUid())) {
6990 throw new SecurityException("Package uid and package name do not match: "
6991 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
6992 }
6993 } catch (PackageManager.NameNotFoundException e) {
6994 throw new SecurityException("Package name invalid:" + callingPackage);
6995 }
6996 RoleManager rm = mApp.getSystemService(RoleManager.class);
6997 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
6998 if (!dialerRoleHolders.contains(callingPackage)) {
6999 throw new SecurityException("App must be the dialer role holder to"
7000 + " upload a call composer pic");
7001 }
7002
7003 Executors.newSingleThreadExecutor().execute(() -> {
7004 ByteArrayOutputStream output = new ByteArrayOutputStream(
7005 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7006 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7007 boolean readUntilEnd = false;
7008 int totalBytesRead = 0;
7009 byte[] buffer = new byte[16 * 1024];
7010 while (true) {
7011 int numRead;
7012 try {
7013 numRead = input.read(buffer);
7014 } catch (IOException e) {
7015 try {
7016 fd.checkError();
7017 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7018 null);
7019 } catch (IOException e1) {
7020 // This means that the other side closed explicitly with an error. If this
7021 // happens, log and ignore.
7022 loge("Remote end of call composer picture pipe closed: " + e1);
7023 }
7024 break;
7025 }
7026 if (numRead == -1) {
7027 readUntilEnd = true;
7028 break;
7029 }
7030 totalBytesRead += numRead;
7031 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7032 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7033 try {
7034 input.close();
7035 } catch (IOException e) {
7036 // ignore
7037 }
7038 break;
7039 }
7040 output.write(buffer, 0, numRead);
7041 }
7042 // Generally, the remote end will close the file descriptors. The only case where we
7043 // close is above, where the picture size is too big.
7044
7045 try {
7046 fd.checkError();
7047 } catch (IOException e) {
7048 loge("Remote end for call composer closed with an error: " + e);
7049 return;
7050 }
7051
Hall Liuaa4211e2021-01-20 15:43:39 -08007052 if (!readUntilEnd) {
7053 loge("Did not finish reading entire image; aborting");
7054 return;
7055 }
Hall Liu82694d52020-12-11 18:22:04 -08007056
Hall Liuaa4211e2021-01-20 15:43:39 -08007057 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7058 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7059 new CallComposerPictureTransfer.Factory() {},
7060 imageData,
7061 (result) -> {
7062 if (result.first != null) {
7063 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7064 Bundle outputResult = new Bundle();
7065 outputResult.putParcelable(
7066 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7067 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7068 outputResult);
7069 } else {
7070 callback.send(result.second, null);
7071 }
7072 }
7073 );
Hall Liu82694d52020-12-11 18:22:04 -08007074 });
7075 }
7076
7077 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007078 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007079 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007080 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081
7082 final long identity = Binder.clearCallingIdentity();
7083 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007084 ImsManager.getInstance(defaultPhone.getContext(),
7085 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007089 }
7090
7091 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007092 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007093 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7095 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007096 return false;
7097 }
Svet Ganovb320e182015-04-16 12:30:10 -07007098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099 final long identity = Binder.clearCallingIdentity();
7100 try {
7101 // Check the user preference and the system-level IMS setting. Even if the user has
7102 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7103 // In the long run, we may instead need to check if there exists a connection service
7104 // which can support video calling.
7105 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007106 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 return imsManager.isVtEnabledByPlatform()
7108 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7109 && imsManager.isVtEnabledByUser();
7110 } finally {
7111 Binder.restoreCallingIdentity(identity);
7112 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007113 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007114
Andrew Leea1239f22015-03-02 17:44:07 -08007115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007116 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7117 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007119 mApp, subId, callingPackage, callingFeatureId,
7120 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 return false;
7122 }
7123
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 CarrierConfigManager configManager =
7127 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007128 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7130 } finally {
7131 Binder.restoreCallingIdentity(identity);
7132 }
Andrew Leea1239f22015-03-02 17:44:07 -08007133 }
7134
7135 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007136 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007138 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139 return false;
7140 }
7141
7142 final long identity = Binder.clearCallingIdentity();
7143 try {
7144 CarrierConfigManager configManager =
7145 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007146 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7148 } finally {
7149 Binder.restoreCallingIdentity(identity);
7150 }
Andrew Leea1239f22015-03-02 17:44:07 -08007151 }
7152
Andrew Lee9431b832015-03-09 18:46:45 -07007153 @Override
7154 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007155 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007156 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007157 }
7158
7159 @Override
7160 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 final long identity = Binder.clearCallingIdentity();
7162 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007163 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 } finally {
7165 Binder.restoreCallingIdentity(identity);
7166 }
Andrew Lee9431b832015-03-09 18:46:45 -07007167 }
7168
Hall Liuf6668912018-10-31 17:05:23 -07007169 /**
7170 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7171 * support for the feature and device firmware support.
7172 *
7173 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7174 */
7175 @Override
7176 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007178 final Phone phone = getPhone(subscriptionId);
7179 if (phone == null) {
7180 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7181 return false;
7182 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007184 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7186 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007187 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188 return isCarrierSupported && isDeviceSupported;
7189 } finally {
7190 Binder.restoreCallingIdentity(identity);
7191 }
Hall Liu98187582018-01-22 19:15:32 -08007192 }
7193
Hall Liuf6668912018-10-31 17:05:23 -07007194 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007195 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7196 * RTT setting, will return true if the device and carrier both support RTT.
7197 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007198 */
7199 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 final long identity = Binder.clearCallingIdentity();
7201 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007202 boolean isRttSupported = isRttSupported(subscriptionId);
7203 boolean isUserRttSettingOn = Settings.Secure.getInt(
7204 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7205 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7206 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7207 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208 } finally {
7209 Binder.restoreCallingIdentity(identity);
7210 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007211 }
7212
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007213 @Deprecated
7214 @Override
7215 public String getDeviceId(String callingPackage) {
7216 return getDeviceIdWithFeature(callingPackage, null);
7217 }
7218
Sanket Padawe7310cc72015-01-14 09:53:20 -08007219 /**
7220 * Returns the unique device ID of phone, for example, the IMEI for
7221 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7222 *
7223 * <p>Requires Permission:
7224 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7225 */
7226 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007227 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007228 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007229 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007230 return null;
7231 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007232 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007233 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007234 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007235 return null;
7236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 return phone.getDeviceId();
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007244 }
7245
Ping Sunc67b7c22016-03-02 19:16:45 +08007246 /**
7247 * {@hide}
7248 * Returns the IMS Registration Status on a particular subid
7249 *
7250 * @param subId
7251 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007252 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007253 Phone phone = getPhone(subId);
7254 if (phone != null) {
7255 return phone.isImsRegistered();
7256 } else {
7257 return false;
7258 }
7259 }
7260
Santos Cordon7a1885b2015-02-03 11:15:19 -08007261 @Override
7262 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7266 } finally {
7267 Binder.restoreCallingIdentity(identity);
7268 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007269 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007270
Tyler Gunnf70ed162019-04-03 15:28:53 -07007271 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007272 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007273 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007275 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007276 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7277 }
7278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
7283 }
7284 }
7285
7286 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007287 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007288 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7289 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 Phone phone = getPhone(subscriptionId);
7293 if (phone == null) {
7294 return null;
7295 }
7296 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7297 } finally {
7298 Binder.restoreCallingIdentity(identity);
7299 }
7300 }
7301
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007302 /**
7303 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007304 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007305 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306 final long identity = Binder.clearCallingIdentity();
7307 try {
7308 Phone phone = getPhone(subId);
7309 if (phone != null) {
7310 return phone.isWifiCallingEnabled();
7311 } else {
7312 return false;
7313 }
7314 } finally {
7315 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007316 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007317 }
7318
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007319 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007320 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007321 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007322 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 final long identity = Binder.clearCallingIdentity();
7324 try {
7325 Phone phone = getPhone(subId);
7326 if (phone != null) {
7327 return phone.isVideoEnabled();
7328 } else {
7329 return false;
7330 }
7331 } finally {
7332 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007333 }
7334 }
7335
7336 /**
7337 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7338 * defined in {@link ImsRegistrationImplBase}.
7339 */
7340 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 final long identity = Binder.clearCallingIdentity();
7342 try {
7343 Phone phone = getPhone(subId);
7344 if (phone != null) {
7345 return phone.getImsRegistrationTech();
7346 } else {
7347 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7348 }
7349 } finally {
7350 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007351 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007352 }
7353
Stuart Scott8eef64f2015-04-08 15:13:54 -07007354 @Override
7355 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007356 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007357 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7358 return;
7359 }
7360
Svet Ganovcc087f82015-05-12 20:35:54 -07007361 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007362
Svet Ganovcc087f82015-05-12 20:35:54 -07007363 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007364 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7365 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007366 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007367 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007368 setNetworkSelectionModeAutomatic(subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007369 setAllowedNetworkTypesForReason(subId,
7370 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7371 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7372 setAllowedNetworkTypesForReason(subId,
7373 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7374 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7375 setAllowedNetworkTypesForReason(subId,
7376 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7377 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007378 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7379 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007380 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007381 // There has been issues when Sms raw table somehow stores orphan
7382 // fragments. They lead to garbled message when new fragments come
7383 // in and combined with those stale ones. In case this happens again,
7384 // user can reset all network settings which will clean up this table.
7385 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007386 // Clean up IMS settings as well here.
7387 int slotId = getSlotIndex(subId);
7388 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7389 ImsManager.getInstance(mApp, slotId).factoryReset();
7390 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007391
7392 // Erase modem config if erase modem on network setting is enabled.
7393 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7394 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7395 if (configValue != null && Boolean.parseBoolean(configValue)) {
7396 sendEraseModemConfig(getDefaultPhone());
7397 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007398 } finally {
7399 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007400 }
7401 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007402
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007403 private void cleanUpSmsRawTable(Context context) {
7404 ContentResolver resolver = context.getContentResolver();
7405 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7406 resolver.delete(uri, null, null);
7407 }
7408
Narayan Kamath1c496c22015-04-16 14:40:19 +01007409 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007410 public String getSimLocaleForSubscriber(int subId) {
7411 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7412 final Phone phone = getPhone(subId);
7413 if (phone == null) {
7414 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007415 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 final long identity = Binder.clearCallingIdentity();
7418 try {
chen xu5d3637b2019-01-21 23:31:38 -08007419 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007420 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007421 if (info == null) {
7422 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7423 return null;
7424 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 // Try and fetch the locale from the carrier properties or from the SIM language
7426 // preferences (EF-PL and EF-LI)...
7427 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007429 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7430 if (localeFromDefaultSim != null) {
7431 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7432 if (DBG) log("Using locale from subId: " + subId + " locale: "
7433 + localeFromDefaultSim);
7434 return localeFromDefaultSim.toLanguageTag();
7435 } else {
7436 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 }
7438 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 // The SIM language preferences only store a language (e.g. fr = French), not an
7441 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7442 // the SIM and carrier preferences does not include a country we add the country
7443 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007444 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007446 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 return mccLocale.toLanguageTag();
7448 }
7449
7450 if (DBG) log("No locale found - returning null");
7451 return null;
7452 } finally {
7453 Binder.restoreCallingIdentity(identity);
7454 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007455 }
7456
7457 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007458 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007459 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007460 }
7461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 /**
7463 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7464 */
7465 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007466 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007467 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007468 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007469
Chenjie Yu1ba97252018-01-11 18:16:20 -08007470 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007471 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007472
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007473 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007474 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7475 * representing the state of the modem.
7476 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007477 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7478 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007479 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007480 */
7481 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007482 public void requestModemActivityInfo(ResultReceiver result) {
7483 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007484 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007488 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 } finally {
7490 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007491 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007492 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007493
Siddharth Rayb8114062018-06-17 15:02:38 -07007494 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7495 // less than total activity duration.
7496 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7497 if (info == null) {
7498 return false;
7499 }
7500 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007501 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7502 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7503
Siddharth Rayb8114062018-06-17 15:02:38 -07007504 return (info.isValid()
7505 && (info.getSleepTimeMillis() <= activityDurationMs)
7506 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007507 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007508 && (totalTxTimeMs <= activityDurationMs));
7509 }
7510
Jack Yu85bd38a2015-11-09 11:34:32 -08007511 /**
7512 * {@hide}
7513 * Returns the service state information on specified subscription.
7514 */
7515 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007516 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7517 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007519 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007520 return null;
7521 }
7522
Hall Liuf19c44f2018-11-27 14:38:17 -08007523 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7524 LocationAccessPolicy.checkLocationPermission(mApp,
7525 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7526 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007527 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007528 .setCallingPid(Binder.getCallingPid())
7529 .setCallingUid(Binder.getCallingUid())
7530 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007531 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007532 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007533 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7534 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007535 .build());
7536
7537 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7538 LocationAccessPolicy.checkLocationPermission(mApp,
7539 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7540 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007541 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007542 .setCallingPid(Binder.getCallingPid())
7543 .setCallingUid(Binder.getCallingUid())
7544 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007545 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007546 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007547 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7548 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007549 .build());
7550 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7551 boolean hasFinePermission =
7552 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7553 boolean hasCoarsePermission =
7554 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7555
Jack Yu479f40e2020-10-27 21:29:25 -07007556 final Phone phone = getPhone(subId);
7557 if (phone == null) {
7558 return null;
7559 }
7560
Jordan Liu0f2bc442020-11-18 16:47:37 -08007561 final long identity = Binder.clearCallingIdentity();
7562
Jack Yu479f40e2020-10-27 21:29:25 -07007563 boolean isCallingPackageDataService = phone.getDataServicePackages()
7564 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007566 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7567 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7568 Rlog.d(LOG_TAG,
7569 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7570 return null;
7571 }
7572
Hall Liuf19c44f2018-11-27 14:38:17 -08007573 ServiceState ss = phone.getServiceState();
7574
7575 // Scrub out the location info in ServiceState depending on what level of access
7576 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007577 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007578 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7579 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580 } finally {
7581 Binder.restoreCallingIdentity(identity);
7582 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007583 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007584
7585 /**
7586 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7587 *
7588 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7589 * voicemail ringtone.
7590 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7591 * PhoneAccount.
7592 */
7593 @Override
7594 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7598 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007599 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
7605 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007606 }
7607
7608 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007609 * Sets the per-account voicemail ringtone.
7610 *
7611 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7612 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7613 *
7614 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7615 * voicemail ringtone.
7616 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7617 * PhoneAccount.
7618 */
7619 @Override
7620 public void setVoicemailRingtoneUri(String callingPackage,
7621 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007622 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007623 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007624 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7625 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7627 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7628 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007630
7631 final long identity = Binder.clearCallingIdentity();
7632 try {
7633 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7634 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007635 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007636 }
7637 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007640 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007641 }
7642
7643 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007644 * Returns whether vibration is set for voicemail notification in Phone settings.
7645 *
7646 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7647 * voicemail vibration setting.
7648 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7649 */
7650 @Override
7651 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7655 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007656 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7660 } finally {
7661 Binder.restoreCallingIdentity(identity);
7662 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007663 }
7664
Youhan Wange64578a2016-05-02 15:32:42 -07007665 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007666 * Sets the per-account voicemail vibration.
7667 *
7668 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7669 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7670 *
7671 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7672 * voicemail vibration setting.
7673 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7674 * specific PhoneAccount.
7675 */
7676 @Override
7677 public void setVoicemailVibrationEnabled(String callingPackage,
7678 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007679 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007681 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7682 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7684 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7685 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007686 }
7687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7691 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007692 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 }
7694 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7695 } finally {
7696 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007697 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007698 }
7699
7700 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007701 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7702 *
7703 * @throws SecurityException if the caller does not have the required permission
7704 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007705 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007706 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007707 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007708 }
7709
7710 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007711 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7712 * permission.
7713 *
7714 * @throws SecurityException if the caller does not have the required permission
7715 */
7716 private void enforceSendSmsPermission() {
7717 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7718 }
7719
7720 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007721 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007722 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007723 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007724 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007725 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726 final long identity = Binder.clearCallingIdentity();
7727 try {
7728 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007729 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 if (componentName == null) {
7731 throw new SecurityException(
7732 "Caller not current active visual voicemail package[null]");
7733 }
7734 String vvmPackage = componentName.getPackageName();
7735 if (!callingPackage.equals(vvmPackage)) {
7736 throw new SecurityException("Caller not current active visual voicemail package["
7737 + vvmPackage + "]");
7738 }
7739 } finally {
7740 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007741 }
7742 }
7743
7744 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007745 * Return the application ID for the app type.
7746 *
7747 * @param subId the subscription ID that this request applies to.
7748 * @param appType the uicc app type.
7749 * @return Application ID for specificied app type, or null if no uicc.
7750 */
7751 @Override
7752 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007753 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007754 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007755
7756 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007757 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 if (phone == null) {
7759 return null;
7760 }
7761 String aid = null;
7762 try {
7763 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7764 .getApplicationByType(appType).getAid();
7765 } catch (Exception e) {
7766 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7767 }
7768 return aid;
7769 } finally {
7770 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007771 }
Youhan Wange64578a2016-05-02 15:32:42 -07007772 }
7773
Youhan Wang4001d252016-05-11 10:29:41 -07007774 /**
7775 * Return the Electronic Serial Number.
7776 *
7777 * @param subId the subscription ID that this request applies to.
7778 * @return ESN or null if error.
7779 */
7780 @Override
7781 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007782 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007783 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784
7785 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007786 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787 if (phone == null) {
7788 return null;
7789 }
7790 String esn = null;
7791 try {
7792 esn = phone.getEsn();
7793 } catch (Exception e) {
7794 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7795 }
7796 return esn;
7797 } finally {
7798 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007799 }
Youhan Wang4001d252016-05-11 10:29:41 -07007800 }
7801
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007802 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007803 * Return the Preferred Roaming List Version.
7804 *
7805 * @param subId the subscription ID that this request applies to.
7806 * @return PRLVersion or null if error.
7807 */
7808 @Override
7809 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007810 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007811 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812
7813 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007814 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 if (phone == null) {
7816 return null;
7817 }
7818 String cdmaPrlVersion = null;
7819 try {
7820 cdmaPrlVersion = phone.getCdmaPrlVersion();
7821 } catch (Exception e) {
7822 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7823 }
7824 return cdmaPrlVersion;
7825 } finally {
7826 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007827 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007828 }
7829
7830 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007831 * Get snapshot of Telephony histograms
7832 * @return List of Telephony histograms
7833 * @hide
7834 */
7835 @Override
7836 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7838 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007839
7840 final long identity = Binder.clearCallingIdentity();
7841 try {
7842 return RIL.getTelephonyRILTimingHistograms();
7843 } finally {
7844 Binder.restoreCallingIdentity(identity);
7845 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007846 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007847
7848 /**
7849 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007850 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7851 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007852 * Require system privileges. In the future we may add this to carrier APIs.
7853 *
Michele Berionne482f8202018-11-27 18:57:59 -08007854 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007855 */
7856 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007857 @TelephonyManager.SetCarrierRestrictionResult
7858 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007859 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007860 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007861
Michele Berionne482f8202018-11-27 18:57:59 -08007862 if (carrierRestrictionRules == null) {
7863 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007864 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 final long identity = Binder.clearCallingIdentity();
7867 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007868 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007869 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 } finally {
7871 Binder.restoreCallingIdentity(identity);
7872 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007873 }
7874
7875 /**
7876 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007877 * Get the allowed carrier list and the excluded carrier list, including the priority between
7878 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007879 * Require system privileges. In the future we may add this to carrier APIs.
7880 *
Michele Berionne482f8202018-11-27 18:57:59 -08007881 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007882 */
7883 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007884 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007885 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007887
7888 final long identity = Binder.clearCallingIdentity();
7889 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007890 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7891 if (response instanceof CarrierRestrictionRules) {
7892 return (CarrierRestrictionRules) response;
7893 }
7894 // Response is an Exception of some kind,
7895 // which is signalled to the user as a NULL retval
7896 return null;
7897 } catch (Exception e) {
7898 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7899 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 } finally {
7901 Binder.restoreCallingIdentity(identity);
7902 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007903 }
7904
fionaxu59545b42016-05-25 15:53:37 -07007905 /**
fionaxu59545b42016-05-25 15:53:37 -07007906 * Action set from carrier signalling broadcast receivers to enable/disable radio
7907 * @param subId the subscription ID that this action applies to.
7908 * @param enabled control enable or disable radio.
7909 * {@hide}
7910 */
7911 @Override
7912 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7913 enforceModifyPermission();
7914 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915
7916 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007917 if (phone == null) {
7918 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7919 return;
7920 }
7921 try {
7922 phone.carrierActionSetRadioEnabled(enabled);
7923 } catch (Exception e) {
7924 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 } finally {
7926 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007927 }
7928 }
7929
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007930 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007931 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7932 * network status based on which carrier apps could apply actions accordingly,
7933 * enable/disable default url handler for example.
7934 *
7935 * @param subId the subscription ID that this action applies to.
7936 * @param report control start/stop reporting the default network status.
7937 * {@hide}
7938 */
7939 @Override
7940 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7941 enforceModifyPermission();
7942 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943
7944 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007945 if (phone == null) {
7946 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7947 return;
7948 }
7949 try {
7950 phone.carrierActionReportDefaultNetworkStatus(report);
7951 } catch (Exception e) {
7952 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953 } finally {
7954 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007955 }
7956 }
7957
7958 /**
fionaxud9622282017-07-17 17:51:30 -07007959 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7960 * @param subId the subscription ID that this action applies to.
7961 * {@hide}
7962 */
7963 @Override
7964 public void carrierActionResetAll(int subId) {
7965 enforceModifyPermission();
7966 final Phone phone = getPhone(subId);
7967 if (phone == null) {
7968 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7969 return;
7970 }
7971 try {
7972 phone.carrierActionResetAll();
7973 } catch (Exception e) {
7974 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7975 }
7976 }
7977
7978 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007979 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7980 * bug report is being generated.
7981 */
7982 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007983 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007984 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7985 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007986 writer.println("Permission Denial: can't dump Phone from pid="
7987 + Binder.getCallingPid()
7988 + ", uid=" + Binder.getCallingUid()
7989 + "without permission "
7990 + android.Manifest.permission.DUMP);
7991 return;
7992 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007993 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007994 }
Jack Yueb89b242016-06-22 13:27:47 -07007995
Brad Ebingerdac2f002018-04-03 15:17:52 -07007996 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007997 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7998 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7999 @NonNull String[] args) {
8000 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8001 this, in.getFileDescriptor(), out.getFileDescriptor(),
8002 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008003 }
8004
Jack Yueb89b242016-06-22 13:27:47 -07008005 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008006 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008007 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008008 * @param reason the reason the data enable change is taking place
8009 * @param enabled True if enabling the data, otherwise disabling.
8010 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008011 */
8012 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008013 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008014 boolean enabled) {
8015 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8016 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8017 try {
8018 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008019 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008020 } catch (SecurityException se) {
8021 enforceModifyPermission();
8022 }
8023 } else {
8024 enforceModifyPermission();
8025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026
8027 final long identity = Binder.clearCallingIdentity();
8028 try {
8029 Phone phone = getPhone(subId);
8030 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008031 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8032 phone.carrierActionSetMeteredApnsEnabled(enabled);
8033 } else {
8034 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036 }
8037 } finally {
8038 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008039 }
8040 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008041
8042 /**
8043 * Get Client request stats
8044 * @return List of Client Request Stats
8045 * @hide
8046 */
8047 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008048 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8049 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008051 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008052 return null;
8053 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008054 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 final long identity = Binder.clearCallingIdentity();
8057 try {
8058 if (phone != null) {
8059 return phone.getClientRequestStats();
8060 }
8061
8062 return null;
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
8065 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008066 }
8067
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008068 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008069 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008070 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008071 }
Jack Yueb4124c2017-02-16 15:32:43 -08008072
8073 /**
Grace Chen70990072017-03-24 17:21:30 -07008074 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008075 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008076 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008077 * @param state State of SIM (power down, power up, pass through)
8078 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8079 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8080 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008081 *
8082 **/
8083 @Override
Grace Chen70990072017-03-24 17:21:30 -07008084 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008085 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008086 Phone phone = PhoneFactory.getPhone(slotIndex);
8087
vagdeviaf9a5b92018-08-15 16:01:53 -07008088 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 final long identity = Binder.clearCallingIdentity();
8091 try {
8092 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008093 phone.setSimPowerState(state, null, workSource);
8094 }
8095 } finally {
8096 Binder.restoreCallingIdentity(identity);
8097 }
8098 }
8099
8100 /**
8101 * Set SIM card power state.
8102 *
8103 * @param slotIndex SIM slot id.
8104 * @param state State of SIM (power down, power up, pass through)
8105 * @param callback callback to trigger after success or failure
8106 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8107 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8108 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8109 *
8110 **/
8111 @Override
8112 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8113 IIntegerConsumer callback) {
8114 enforceModifyPermission();
8115 Phone phone = PhoneFactory.getPhone(slotIndex);
8116
8117 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8118
8119 final long identity = Binder.clearCallingIdentity();
8120 try {
8121 if (phone != null) {
8122 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8123 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 }
8125 } finally {
8126 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008127 }
8128 }
Shuo Qiandd210312017-04-12 22:11:33 +00008129
Tyler Gunn65d45c22017-06-05 11:22:26 -07008130 private boolean isUssdApiAllowed(int subId) {
8131 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008132 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008133 if (configManager == null) {
8134 return false;
8135 }
8136 PersistableBundle pb = configManager.getConfigForSubId(subId);
8137 if (pb == null) {
8138 return false;
8139 }
8140 return pb.getBoolean(
8141 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8142 }
8143
Shuo Qiandd210312017-04-12 22:11:33 +00008144 /**
8145 * Check if phone is in emergency callback mode
8146 * @return true if phone is in emergency callback mode
8147 * @param subId sub id
8148 */
goneil9c5f4872017-12-05 14:07:56 -08008149 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008150 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008151 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008152 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153
8154 final long identity = Binder.clearCallingIdentity();
8155 try {
8156 if (phone != null) {
8157 return phone.isInEcm();
8158 } else {
8159 return false;
8160 }
8161 } finally {
8162 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008163 }
8164 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008165
8166 /**
8167 * Get the current signal strength information for the given subscription.
8168 * Because this information is not updated when the device is in a low power state
8169 * it should not be relied-upon to be current.
8170 * @param subId Subscription index
8171 * @return the most recent cached signal strength info from the modem
8172 */
8173 @Override
8174 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 final long identity = Binder.clearCallingIdentity();
8176 try {
8177 Phone p = getPhone(subId);
8178 if (p == null) {
8179 return null;
8180 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182 return p.getSignalStrength();
8183 } finally {
8184 Binder.restoreCallingIdentity(identity);
8185 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008186 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008187
Pengquan Meng77b7f132018-08-22 14:49:57 -07008188 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008189 * Get the current modem radio state for the given slot.
8190 * @param slotIndex slot index.
8191 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008192 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008193 * @return the current radio power state from the modem
8194 */
8195 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008196 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008197 Phone phone = PhoneFactory.getPhone(slotIndex);
8198 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008199 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8200 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008201 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8202 }
8203
8204 final long identity = Binder.clearCallingIdentity();
8205 try {
8206 return phone.getRadioPowerState();
8207 } finally {
8208 Binder.restoreCallingIdentity(identity);
8209 }
8210 }
8211 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8212 }
8213
8214 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008215 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8216 *
8217 * <p>Requires one of the following permissions:
8218 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8219 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8220 * privileges.
8221 *
8222 * @param subId subscription id
8223 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8224 * {@code false}.
8225 */
8226 @Override
8227 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008228 try {
8229 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8230 null);
8231 } catch (Exception e) {
8232 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8233 mApp, subId, "isDataRoamingEnabled");
8234 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008235
Pengquan Menga1bb6272018-09-06 09:59:22 -07008236 boolean isEnabled = false;
8237 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008238 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008239 Phone phone = getPhone(subId);
8240 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008241 } finally {
8242 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008243 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008244 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008245 }
8246
8247
8248 /**
8249 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8250 *
8251 * <p> Requires permission:
8252 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8253 * privileges.
8254 *
8255 * @param subId subscription id
8256 * @param isEnabled {@code true} means enable, {@code false} means disable.
8257 */
8258 @Override
8259 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8261 mApp, subId, "setDataRoamingEnabled");
8262
Pengquan Menga1bb6272018-09-06 09:59:22 -07008263 final long identity = Binder.clearCallingIdentity();
8264 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008265 Phone phone = getPhone(subId);
8266 if (phone != null) {
8267 phone.setDataRoamingEnabled(isEnabled);
8268 }
8269 } finally {
8270 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008271 }
8272 }
8273
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008274 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008275 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008276 TelephonyPermissions
8277 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008278 mApp, subId, "isManualNetworkSelectionAllowed");
8279
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008280 boolean isAllowed = true;
8281 final long identity = Binder.clearCallingIdentity();
8282 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008283 Phone phone = getPhone(subId);
8284 if (phone != null) {
8285 isAllowed = phone.isCspPlmnEnabled();
8286 }
8287 } finally {
8288 Binder.restoreCallingIdentity(identity);
8289 }
8290 return isAllowed;
8291 }
8292
8293 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008294 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008295 // Verify that tha callingPackage belongs to the calling UID
8296 mApp.getSystemService(AppOpsManager.class)
8297 .checkPackage(Binder.getCallingUid(), callingPackage);
8298
Jordan Liu1e142fc2019-04-22 15:10:43 -07008299 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008300 try {
8301 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008302 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008303 } catch (SecurityException e) {
8304 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8305 // has carrier privileges on an active UICC
8306 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8307 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008308 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008309 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008310 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008311
8312 final long identity = Binder.clearCallingIdentity();
8313 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008314 UiccController uiccController = UiccController.getInstance();
8315 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008316 if (hasReadPermission) {
8317 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008318 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008319
8320 // Remove private info if the caller doesn't have access
8321 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8322 for (UiccCardInfo cardInfo : cardInfos) {
8323 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8324 // is available
8325 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8326 if (card == null || card.getUiccProfile() == null) {
8327 // assume no access if the card or profile is unavailable
8328 filteredInfos.add(cardInfo.getUnprivileged());
8329 continue;
8330 }
8331 UiccProfile profile = card.getUiccProfile();
8332 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8333 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8334 filteredInfos.add(cardInfo);
8335 } else {
8336 filteredInfos.add(cardInfo.getUnprivileged());
8337 }
8338 }
8339 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008340 } finally {
8341 Binder.restoreCallingIdentity(identity);
8342 }
8343 }
8344
8345 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008346 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008347 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008349 final long identity = Binder.clearCallingIdentity();
8350 try {
8351 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8352 if (slots == null) {
8353 Rlog.i(LOG_TAG, "slots is null.");
8354 return null;
8355 }
8356
8357 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8358 for (int i = 0; i < slots.length; i++) {
8359 UiccSlot slot = slots[i];
8360 if (slot == null) {
8361 continue;
8362 }
8363
Jordan Liu7be7e652019-05-06 18:55:02 +00008364 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365 UiccCard card = slot.getUiccCard();
8366 if (card != null) {
8367 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008368 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008369 cardId = slot.getEid();
8370 if (TextUtils.isEmpty(cardId)) {
8371 cardId = slot.getIccId();
8372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008373 }
8374
Jordan Liu857451f2019-05-09 16:35:35 -07008375 if (cardId != null) {
8376 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8377 // if cardId is an EID, it's all digits so this is fine
8378 cardId = IccUtils.stripTrailingFs(cardId);
8379 }
8380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008381 int cardState = 0;
8382 switch (slot.getCardState()) {
8383 case CARDSTATE_ABSENT:
8384 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8385 break;
8386 case CARDSTATE_PRESENT:
8387 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8388 break;
8389 case CARDSTATE_ERROR:
8390 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8391 break;
8392 case CARDSTATE_RESTRICTED:
8393 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8394 break;
8395 default:
8396 break;
8397
8398 }
8399
8400 infos[i] = new UiccSlotInfo(
8401 slot.isActive(),
8402 slot.isEuicc(),
8403 cardId,
8404 cardState,
8405 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008406 slot.isExtendedApduSupported(),
8407 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008408 }
8409 return infos;
8410 } finally {
8411 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008412 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008413 }
8414
8415 @Override
8416 public boolean switchSlots(int[] physicalSlots) {
8417 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008418
8419 final long identity = Binder.clearCallingIdentity();
8420 try {
8421 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8422 } finally {
8423 Binder.restoreCallingIdentity(identity);
8424 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008425 }
Jack Yu4c988042018-02-27 15:30:01 -08008426
8427 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008428 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008429 final long identity = Binder.clearCallingIdentity();
8430 try {
8431 return UiccController.getInstance().getCardIdForDefaultEuicc();
8432 } finally {
8433 Binder.restoreCallingIdentity(identity);
8434 }
8435 }
8436
Pengquan Meng85728fb2018-03-12 16:31:21 -07008437 /**
goneil47ffb6e2018-04-06 15:40:58 -07008438 * A test API to reload the UICC profile.
8439 *
8440 * <p>Requires that the calling app has permission
8441 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8442 * @hide
8443 */
8444 @Override
8445 public void refreshUiccProfile(int subId) {
8446 enforceModifyPermission();
8447
8448 final long identity = Binder.clearCallingIdentity();
8449 try {
8450 Phone phone = getPhone(subId);
8451 if (phone == null) {
8452 return;
8453 }
8454 UiccCard uiccCard = phone.getUiccCard();
8455 if (uiccCard == null) {
8456 return;
8457 }
8458 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8459 if (uiccProfile == null) {
8460 return;
8461 }
8462 uiccProfile.refresh();
8463 } finally {
8464 Binder.restoreCallingIdentity(identity);
8465 }
8466 }
8467
8468 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008469 * Returns false if the mobile data is disabled by default, otherwise return true.
8470 */
8471 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008472 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008473 }
8474
8475 /**
8476 * Returns true if the data roaming is enabled by default, i.e the system property
8477 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8478 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8479 */
8480 private boolean getDefaultDataRoamingEnabled(int subId) {
8481 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008482 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008483 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008484 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8485 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8486 return isDataRoamingEnabled;
8487 }
8488
8489 /**
8490 * Returns the default network type for the given {@code subId}, if the default network type is
8491 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8492 */
8493 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008494 List<Integer> list = TelephonyProperties.default_network();
8495 int phoneId = mSubscriptionController.getPhoneId(subId);
8496 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8497 return list.get(phoneId);
8498 }
8499 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008500 }
fionaxua13278b2018-03-21 00:08:13 -07008501
8502 @Override
8503 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008504 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008505 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008506
8507 final long identity = Binder.clearCallingIdentity();
8508 try {
8509 final Phone phone = getPhone(subId);
8510 if (phone == null) {
8511 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8512 return;
8513 }
chen xueaba88a2019-03-15 13:15:10 -07008514 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8515 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008516 if (carrierPrivilegeRules == null) {
8517 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8518 } else {
8519 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008521 } finally {
8522 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008523 }
fionaxua13278b2018-03-21 00:08:13 -07008524 }
8525
8526 @Override
8527 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008528 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529
8530 final long identity = Binder.clearCallingIdentity();
8531 try {
8532 final Phone phone = getPhone(subId);
8533 if (phone == null) {
8534 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8535 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8536 }
8537 return phone.getCarrierIdListVersion();
8538 } finally {
8539 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008540 }
fionaxua13278b2018-03-21 00:08:13 -07008541 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008542
8543 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008544 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8545 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008547 mApp, subId, callingPackage, callingFeatureId,
8548 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008549 return -1;
8550 }
8551
8552 final long identity = Binder.clearCallingIdentity();
8553 try {
8554 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8555 } finally {
8556 Binder.restoreCallingIdentity(identity);
8557 }
8558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008559
8560 @Override
8561 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008562 TelephonyPermissions
8563 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008564 mApp, subId, "getCdmaRoamingMode");
8565
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
8568 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8569 } finally {
8570 Binder.restoreCallingIdentity(identity);
8571 }
8572 }
8573
8574 @Override
8575 public boolean setCdmaRoamingMode(int subId, int mode) {
8576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8577 mApp, subId, "setCdmaRoamingMode");
8578
8579 final long identity = Binder.clearCallingIdentity();
8580 try {
8581 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8582 } finally {
8583 Binder.restoreCallingIdentity(identity);
8584 }
8585 }
8586
8587 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008588 public int getCdmaSubscriptionMode(int subId) {
8589 TelephonyPermissions
8590 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8591 mApp, subId, "getCdmaSubscriptionMode");
8592
8593 final long identity = Binder.clearCallingIdentity();
8594 try {
8595 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8596 } finally {
8597 Binder.restoreCallingIdentity(identity);
8598 }
8599 }
8600
8601 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008602 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8604 mApp, subId, "setCdmaSubscriptionMode");
8605
8606 final long identity = Binder.clearCallingIdentity();
8607 try {
8608 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8609 } finally {
8610 Binder.restoreCallingIdentity(identity);
8611 }
8612 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008613
sqianc5eccab2018-10-19 18:46:41 -07008614 @Override
sqian8c685422019-02-22 15:55:18 -08008615 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008616 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008618 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8619 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008620 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8621 }
8622 final long identity = Binder.clearCallingIdentity();
8623 try {
sqian854d44b2018-12-12 16:48:18 -08008624 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8625 for (Phone phone: PhoneFactory.getPhones()) {
8626 if (phone.getEmergencyNumberTracker() != null
8627 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8628 emergencyNumberListInternal.put(
8629 phone.getSubId(),
8630 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8631 }
sqian11b7a0e2018-12-05 18:48:28 -08008632 }
sqian854d44b2018-12-12 16:48:18 -08008633 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008634 } finally {
8635 Binder.restoreCallingIdentity(identity);
8636 }
sqianc5eccab2018-10-19 18:46:41 -07008637 }
8638
8639 @Override
sqian8c685422019-02-22 15:55:18 -08008640 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008641 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008642 if (!exactMatch) {
8643 TelephonyPermissions
8644 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008645 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008646 }
8647 final long identity = Binder.clearCallingIdentity();
8648 try {
sqian854d44b2018-12-12 16:48:18 -08008649 for (Phone phone: PhoneFactory.getPhones()) {
8650 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008651 && phone.getEmergencyNumberTracker()
8652 .isEmergencyNumber(number, exactMatch)) {
8653 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008654 }
sqian11b7a0e2018-12-05 18:48:28 -08008655 }
8656 return false;
8657 } finally {
8658 Binder.restoreCallingIdentity(identity);
8659 }
8660 }
8661
sqianf4ca7ed2019-01-15 18:32:07 -08008662 /**
8663 * Update emergency number list for test mode.
8664 */
8665 @Override
8666 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8667 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8668 "updateEmergencyNumberListTestMode");
8669
8670 final long identity = Binder.clearCallingIdentity();
8671 try {
8672 for (Phone phone: PhoneFactory.getPhones()) {
8673 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8674 if (tracker != null) {
8675 tracker.executeEmergencyNumberTestModeCommand(action, num);
8676 }
8677 }
8678 } finally {
8679 Binder.restoreCallingIdentity(identity);
8680 }
8681 }
8682
8683 /**
8684 * Get the full emergency number list for test mode.
8685 */
8686 @Override
8687 public List<String> getEmergencyNumberListTestMode() {
8688 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8689 "getEmergencyNumberListTestMode");
8690
8691 final long identity = Binder.clearCallingIdentity();
8692 try {
8693 Set<String> emergencyNumbers = new HashSet<>();
8694 for (Phone phone: PhoneFactory.getPhones()) {
8695 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8696 if (tracker != null) {
8697 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8698 emergencyNumbers.add(num.getNumber());
8699 }
8700 }
8701 }
8702 return new ArrayList<>(emergencyNumbers);
8703 } finally {
8704 Binder.restoreCallingIdentity(identity);
8705 }
8706 }
8707
chen xud6b45bd2018-10-30 22:27:10 -07008708 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008709 public int getEmergencyNumberDbVersion(int subId) {
8710 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8711
8712 final long identity = Binder.clearCallingIdentity();
8713 try {
8714 final Phone phone = getPhone(subId);
8715 if (phone == null) {
8716 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8717 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8718 }
8719 return phone.getEmergencyNumberDbVersion();
8720 } finally {
8721 Binder.restoreCallingIdentity(identity);
8722 }
8723 }
8724
8725 @Override
8726 public void notifyOtaEmergencyNumberDbInstalled() {
8727 enforceModifyPermission();
8728
8729 final long identity = Binder.clearCallingIdentity();
8730 try {
8731 for (Phone phone: PhoneFactory.getPhones()) {
8732 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8733 if (tracker != null) {
8734 tracker.updateOtaEmergencyNumberDatabase();
8735 }
8736 }
8737 } finally {
8738 Binder.restoreCallingIdentity(identity);
8739 }
8740 }
8741
8742 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008743 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008744 enforceActiveEmergencySessionPermission();
8745
8746 final long identity = Binder.clearCallingIdentity();
8747 try {
8748 for (Phone phone: PhoneFactory.getPhones()) {
8749 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8750 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008751 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8752 }
8753 }
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 }
8758
8759 @Override
8760 public void resetOtaEmergencyNumberDbFilePath() {
8761 enforceActiveEmergencySessionPermission();
8762
8763 final long identity = Binder.clearCallingIdentity();
8764 try {
8765 for (Phone phone: PhoneFactory.getPhones()) {
8766 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8767 if (tracker != null) {
8768 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008769 }
8770 }
8771 } finally {
8772 Binder.restoreCallingIdentity(identity);
8773 }
8774 }
8775
8776 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008777 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8778 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8779 Phone phone = getPhone(subId);
8780 if (phone == null) {
8781 return null;
8782 }
8783 final long identity = Binder.clearCallingIdentity();
8784 try {
8785 UiccProfile profile = UiccController.getInstance()
8786 .getUiccProfileForPhone(phone.getPhoneId());
8787 if (profile != null) {
8788 return profile.getCertsFromCarrierPrivilegeAccessRules();
8789 }
8790 } finally {
8791 Binder.restoreCallingIdentity(identity);
8792 }
8793 return null;
8794 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008795
8796 /**
8797 * Enable or disable a modem stack.
8798 */
8799 @Override
8800 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8801 enforceModifyPermission();
8802
8803 final long identity = Binder.clearCallingIdentity();
8804 try {
8805 Phone phone = PhoneFactory.getPhone(slotIndex);
8806 if (phone == null) {
8807 return false;
8808 } else {
8809 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8810 }
8811 } finally {
8812 Binder.restoreCallingIdentity(identity);
8813 }
8814 }
Michelecea4cf22018-12-21 15:00:11 -08008815
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008816 /**
8817 * Whether a modem stack is enabled or not.
8818 */
8819 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008820 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8821 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008822 Phone phone = PhoneFactory.getPhone(slotIndex);
8823 if (phone == null) return false;
8824
8825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008826 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8827 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008828 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8829 }
8830
8831 final long identity = Binder.clearCallingIdentity();
8832 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008833 try {
8834 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8835 } catch (NoSuchElementException ex) {
8836 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8837 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008838 } finally {
8839 Binder.restoreCallingIdentity(identity);
8840 }
8841 }
8842
Michelecea4cf22018-12-21 15:00:11 -08008843 @Override
Michele0ea7d782019-03-19 14:58:42 -07008844 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008845 enforceModifyPermission();
8846
8847 final long identity = Binder.clearCallingIdentity();
8848 try {
8849 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008850 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008851 .commit();
8852 } finally {
8853 Binder.restoreCallingIdentity(identity);
8854 }
8855 }
8856
8857 @Override
Michele0ea7d782019-03-19 14:58:42 -07008858 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008859 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008861 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8862 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008863 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008864 }
Michelecea4cf22018-12-21 15:00:11 -08008865
8866 final long identity = Binder.clearCallingIdentity();
8867 try {
Michele0ea7d782019-03-19 14:58:42 -07008868 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008869 } finally {
8870 Binder.restoreCallingIdentity(identity);
8871 }
8872 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008873
Michele0ea7d782019-03-19 14:58:42 -07008874 @TelephonyManager.IsMultiSimSupportedResult
8875 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008876 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8877 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8878 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008879 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8880 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008881 }
8882 // Check if the hardware supports multisim functionality. If usage of multisim is not
8883 // supported by the modem, indicate that it is restricted.
8884 PhoneCapability staticCapability =
8885 mPhoneConfigurationManager.getStaticPhoneCapability();
8886 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008887 loge("isMultiSimSupportedInternal: no static configuration available");
8888 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008889 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008890 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008891 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8892 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008893 }
8894 // Check if support of multiple SIMs is restricted by carrier
8895 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008896 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008897 }
8898
Michele0ea7d782019-03-19 14:58:42 -07008899 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008900 }
8901
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008902 /**
8903 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008904 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8905 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8906 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008907 * @param numOfSims number of active sims we want to switch to
8908 */
8909 @Override
8910 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008911 if (numOfSims == 1) {
8912 enforceModifyPermission();
8913 } else {
8914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8915 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8916 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008917 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008918
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008919 try {
Michele30b57b22019-03-01 12:01:14 -08008920 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008921 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008922 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8923 return;
8924 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008925 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8926 } finally {
8927 Binder.restoreCallingIdentity(identity);
8928 }
8929 }
8930
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008931 @Override
8932 public boolean isApplicationOnUicc(int subId, int appType) {
8933 enforceReadPrivilegedPermission("isApplicationOnUicc");
8934 Phone phone = getPhone(subId);
8935 if (phone == null) {
8936 return false;
8937 }
8938 final long identity = Binder.clearCallingIdentity();
8939 try {
8940 UiccCard uiccCard = phone.getUiccCard();
8941 if (uiccCard == null) {
8942 return false;
8943 }
8944 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8945 if (uiccProfile == null) {
8946 return false;
8947 }
8948 if (TelephonyManager.APPTYPE_SIM <= appType
8949 && appType <= TelephonyManager.APPTYPE_ISIM) {
8950 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8951 }
8952 return false;
8953 } finally {
8954 Binder.restoreCallingIdentity(identity);
8955 }
8956 }
8957
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008958 /**
chen xub4baa772019-04-03 10:23:41 -07008959 * Get whether making changes to modem configurations will trigger reboot.
8960 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008961 */
8962 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008963 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8964 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008966 mApp, subId, callingPackage, callingFeatureId,
8967 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008968 return false;
8969 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008970 final long identity = Binder.clearCallingIdentity();
8971 try {
8972 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8973 } finally {
8974 Binder.restoreCallingIdentity(identity);
8975 }
8976 }
8977
Nathan Harold29f5f052019-02-15 13:41:57 -08008978 private void updateModemStateMetrics() {
8979 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8980 // TODO: check the state for each modem if the api is ready.
8981 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8982 }
8983
Pengquan Meng3889a572019-01-23 11:16:29 -08008984 @Override
8985 public int[] getSlotsMapping() {
8986 enforceReadPrivilegedPermission("getSlotsMapping");
8987
8988 final long identity = Binder.clearCallingIdentity();
8989 try {
8990 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8991 // All logical slots should have a mapping to a physical slot.
8992 int[] logicalSlotsMapping = new int[phoneCount];
8993 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8994 for (int i = 0; i < slotInfos.length; i++) {
8995 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8996 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8997 }
8998 }
8999 return logicalSlotsMapping;
9000 } finally {
9001 Binder.restoreCallingIdentity(identity);
9002 }
9003 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009004
9005 /**
9006 * Get the IRadio HAL Version
9007 */
9008 @Override
9009 public int getRadioHalVersion() {
9010 Phone phone = getDefaultPhone();
9011 if (phone == null) return -1;
9012 HalVersion hv = phone.getHalVersion();
9013 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9014 return hv.major * 100 + hv.minor;
9015 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009016
9017 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009018 * Get the current calling package name.
9019 * @return the current calling package name
9020 */
9021 @Override
9022 public String getCurrentPackageName() {
9023 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9024 }
9025
9026 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009027 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9028 * corresponding network requests on a subId.
9029 *
9030 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009031 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009032 * 2) APN is un-metered for this subscription, or
9033 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009034 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009035 *
9036 * @return whether data is allowed for a apn type.
9037 *
9038 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009039 */
9040 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009041 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009042 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9043 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009044
9045 // Now that all security checks passes, perform the operation as ourselves.
9046 final long identity = Binder.clearCallingIdentity();
9047 try {
9048 Phone phone = getPhone(subId);
9049 if (phone == null) return false;
9050
Jack Yu41407ee2019-05-13 16:54:09 -07009051 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009052 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9053 } finally {
9054 Binder.restoreCallingIdentity(identity);
9055 }
9056 }
9057
9058 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009059 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009060 enforceReadPrivilegedPermission("isApnMetered");
9061
9062 // Now that all security checks passes, perform the operation as ourselves.
9063 final long identity = Binder.clearCallingIdentity();
9064 try {
9065 Phone phone = getPhone(subId);
9066 if (phone == null) return true; // By default return true.
9067
Jack Yu41407ee2019-05-13 16:54:09 -07009068 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
9072 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009073
9074 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009075 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9076 int subscriptionId, IBooleanConsumer resultCallback) {
9077 enforceModifyPermission();
9078 long token = Binder.clearCallingIdentity();
9079 try {
9080 Phone phone = getPhone(subscriptionId);
9081 if (phone == null) {
9082 try {
9083 if (resultCallback != null) {
9084 resultCallback.accept(false);
9085 }
9086 } catch (RemoteException e) {
9087 // ignore
9088 }
9089 return;
9090 }
9091 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9092 Pair.create(specifiers, (x) -> {
9093 try {
9094 if (resultCallback != null) {
9095 resultCallback.accept(x);
9096 }
9097 } catch (RemoteException e) {
9098 // ignore
9099 }
9100 });
9101 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9102 } finally {
9103 Binder.restoreCallingIdentity(token);
9104 }
9105 }
9106
9107 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009108 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9109 TelephonyPermissions
9110 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9111 mApp, subId, "getSystemSelectionChannels");
9112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
9115 List<RadioAccessSpecifier> specifiers =
9116 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9117 null, subId, workSource);
9118 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9119 return specifiers;
9120 } finally {
9121 Binder.restoreCallingIdentity(identity);
9122 }
9123 }
9124
9125 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009126 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009127 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009128 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9129 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9130 if (iccRecords == null) {
9131 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9132 return false;
9133 }
9134 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9135 }
9136
9137 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009138 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9139 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009140 if (callingPackage == null) {
9141 callingPackage = getCurrentPackageName();
9142 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009143 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9144 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009145 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9146 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009147 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9148 }
9149 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9150 Intent intent = new Intent();
9151 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9152 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9153 // Bring up choose default SMS subscription dialog right now
9154 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9155 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9156 mApp.startActivity(intent);
9157 }
chen xud5ca2d52019-05-28 15:20:57 -07009158
9159 @Override
9160 public String getMmsUAProfUrl(int subId) {
9161 //TODO investigate if this API should require proper permission check in R b/133791609
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009164 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9165 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9166 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9167 return carrierUAProfUrl;
9168 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009169 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9170 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009171 } finally {
9172 Binder.restoreCallingIdentity(identity);
9173 }
9174 }
9175
9176 @Override
9177 public String getMmsUserAgent(int subId) {
9178 //TODO investigate if this API should require proper permission check in R b/133791609
9179 final long identity = Binder.clearCallingIdentity();
9180 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009181 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9182 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9183 if (!TextUtils.isEmpty(carrierUserAgent)) {
9184 return carrierUserAgent;
9185 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009186 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9187 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 }
Jack Yub07d4972019-05-28 16:12:25 -07009192
9193 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009194 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9195 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009196
Jack Yub07d4972019-05-28 16:12:25 -07009197 final long identity = Binder.clearCallingIdentity();
9198 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009199 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009200 if (phone == null) return false;
9201
Hall Liua62f5da2020-09-25 10:42:19 -07009202 switch (policy) {
9203 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9204 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9205 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9206 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9207 default:
9208 throw new IllegalArgumentException(policy + " is not a valid policy");
9209 }
Jack Yub07d4972019-05-28 16:12:25 -07009210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
9214
9215 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009216 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9217 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009218 enforceModifyPermission();
9219
changbettyd5c246e2019-12-24 15:40:37 +08009220 final long identity = Binder.clearCallingIdentity();
9221 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009222 Phone phone = getPhone(subscriptionId);
9223 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009224
Hall Liua62f5da2020-09-25 10:42:19 -07009225 switch (policy) {
9226 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9227 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9228 break;
9229 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9230 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9231 break;
9232 default:
9233 throw new IllegalArgumentException(policy + " is not a valid policy");
9234 }
changbettyd5c246e2019-12-24 15:40:37 +08009235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 }
9239
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009240 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009241 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009242 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9243 * otherwise.
9244 */
9245 @Override
9246 public void setCepEnabled(boolean isCepEnabled) {
9247 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9248
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
9251 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9252 for (Phone phone : PhoneFactory.getPhones()) {
9253 Phone defaultPhone = phone.getImsPhone();
9254 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9255 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9256 ImsPhoneCallTracker imsPhoneCallTracker =
9257 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9258 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9259 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9260 + imsPhone.getMsisdn());
9261 }
9262 }
9263 } finally {
9264 Binder.restoreCallingIdentity(identity);
9265 }
9266 }
allenwtsu46dcc572020-01-08 18:24:03 +08009267
9268 /**
9269 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9270 *
9271 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9272 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9273 * before being read.
9274 */
9275 @Override
9276 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9277 isCompressed) {
9278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9279 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009280 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9281 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9282 }
9283 if (!isImsAvailableOnDevice()) {
9284 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9285 "IMS not available on device.");
9286 }
9287
9288 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009289 try {
Hui Wang761a6682020-10-31 05:12:53 +00009290 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9291 } finally {
9292 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009293 }
9294 }
zoey chene02881a2019-12-30 16:11:23 +08009295
9296 @Override
9297 public boolean isIccLockEnabled(int subId) {
9298 enforceReadPrivilegedPermission("isIccLockEnabled");
9299
9300 // Now that all security checks passes, perform the operation as ourselves.
9301 final long identity = Binder.clearCallingIdentity();
9302 try {
9303 Phone phone = getPhone(subId);
9304 if (phone != null && phone.getIccCard() != null) {
9305 return phone.getIccCard().getIccLockEnabled();
9306 } else {
9307 return false;
9308 }
9309 } finally {
9310 Binder.restoreCallingIdentity(identity);
9311 }
9312 }
9313
9314 /**
9315 * Set the ICC pin lock enabled or disabled.
9316 *
9317 * @return an integer representing the status of IccLock enabled or disabled in the following
9318 * three cases:
9319 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9320 * successfully.
9321 * - Positive number and zero for remaining password attempts.
9322 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9323 *
9324 */
9325 @Override
9326 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9327 enforceModifyPermission();
9328
9329 Phone phone = getPhone(subId);
9330 if (phone == null) {
9331 return 0;
9332 }
9333 // Now that all security checks passes, perform the operation as ourselves.
9334 final long identity = Binder.clearCallingIdentity();
9335 try {
9336 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9337 new Pair<Boolean, String>(enabled, password), phone, null);
9338 return attemptsRemaining;
9339
9340 } catch (Exception e) {
9341 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9342 } finally {
9343 Binder.restoreCallingIdentity(identity);
9344 }
9345 return 0;
9346 }
9347
9348 /**
9349 * Change the ICC password used in ICC pin lock.
9350 *
9351 * @return an integer representing the status of IccLock changed in the following three cases:
9352 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9353 * - Positive number and zero for remaining password attempts.
9354 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9355 *
9356 */
9357 @Override
9358 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9359 enforceModifyPermission();
9360
9361 Phone phone = getPhone(subId);
9362 if (phone == null) {
9363 return 0;
9364 }
9365 // Now that all security checks passes, perform the operation as ourselves.
9366 final long identity = Binder.clearCallingIdentity();
9367 try {
9368 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9369 new Pair<String, String>(oldPassword, newPassword), phone, null);
9370 return attemptsRemaining;
9371
9372 } catch (Exception e) {
9373 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9374 } finally {
9375 Binder.restoreCallingIdentity(identity);
9376 }
9377 return 0;
9378 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009379
9380 /**
9381 * Request for receiving user activity notification
9382 */
9383 @Override
9384 public void requestUserActivityNotification() {
9385 if (!mNotifyUserActivity.get()
9386 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9387 mNotifyUserActivity.set(true);
9388 }
9389 }
9390
9391 /**
9392 * Called when userActivity is signalled in the power manager.
9393 * This is safe to call from any thread, with any window manager locks held or not.
9394 */
9395 @Override
9396 public void userActivity() {
9397 // ***************************************
9398 // * Inherited from PhoneWindowManager *
9399 // ***************************************
9400 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9401 // WITH ITS LOCKS HELD.
9402 //
9403 // This code must be VERY careful about the locks
9404 // it acquires.
9405 // In fact, the current code acquires way too many,
9406 // and probably has lurking deadlocks.
9407
9408 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9409 throw new SecurityException("Only the OS may call notifyUserActivity()");
9410 }
9411
9412 if (mNotifyUserActivity.getAndSet(false)) {
9413 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9414 USER_ACTIVITY_NOTIFICATION_DELAY);
9415 }
9416 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009417
9418 @Override
9419 public boolean canConnectTo5GInDsdsMode() {
9420 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9421 }
Jack Yud10cdd42020-09-28 20:28:01 -07009422
9423 @Override
9424 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9425 String callingFeatureId) {
9426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9427 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9428 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9429 }
9430
9431 Phone phone = getPhone(subId);
9432 if (phone == null) {
9433 throw new RuntimeException("phone is not available");
9434 }
9435 // Now that all security checks passes, perform the operation as ourselves.
9436 final long identity = Binder.clearCallingIdentity();
9437 try {
9438 return phone.getEquivalentHomePlmns();
9439 } finally {
9440 Binder.restoreCallingIdentity(identity);
9441 }
9442 }
Daniel Bright59e67312020-11-13 11:49:37 -08009443
9444 @Override
9445 public boolean isRadioInterfaceCapabilitySupported(
9446 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9447 RadioInterfaceCapabilities radioInterfaceCapabilities =
9448 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9449 if (radioInterfaceCapabilities == null) {
9450 throw new RuntimeException("radio interface capabilities are not available");
9451 } else {
9452 return radioInterfaceCapabilities.isSupported(capability);
9453 }
9454 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009455
Hui Wang641e81c2020-10-12 12:14:23 -07009456 @Override
9457 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9458 UaSecurityProtocolIdentifier securityProtocol,
9459 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9460 throws RemoteException {
9461 enforceModifyPermission();
9462 if (DBG) {
9463 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9464 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9465 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9466 }
9467
9468 if (!SubscriptionManager.isValidSubscriptionId(subId)
9469 || appType < TelephonyManager.APPTYPE_UNKNOWN
9470 || appType > TelephonyManager.APPTYPE_ISIM
9471 || nafUrl == null || securityProtocol == null || callback == null) {
9472 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9473 if (callback != null) {
9474 try {
9475 callback.onAuthenticationFailure(
9476 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9477 } catch (RemoteException exception) {
9478 log("Fail to notify onAuthenticationFailure due to " + exception);
9479 }
9480 return;
9481 }
9482 }
9483
9484 final long token = Binder.clearCallingIdentity();
9485 try {
9486 getGbaManager(subId).bootstrapAuthenticationRequest(
9487 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9488 forceBootStrapping, callback));
9489 } finally {
9490 Binder.restoreCallingIdentity(token);
9491 }
9492 }
9493
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009494 /**
9495 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9496 * requested radio power state will actually be set. See {@link
9497 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9498 *
9499 * @param subId the subscription ID of the phone requesting to set the radio power state.
9500 * @param enable {@code true} if trying to turn radio on.
9501 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9502 * false}.
9503 */
9504 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9505 Phone phone = getPhone(subId);
9506 if (phone != null) {
9507 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9508 return true;
9509 }
9510 return false;
9511 }
9512
9513 private int handleDataThrottlingRequest(int subId,
9514 DataThrottlingRequest dataThrottlingRequest) {
9515 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9516 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9517 if (!setRadioPowerForThermal(subId, true)) {
9518 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9519 }
9520
9521 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9522
9523 int thermalMitigationResult =
9524 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9525 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9526 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9527 }
9528 return thermalMitigationResult;
9529 }
9530
9531 /**
9532 * Thermal mitigation request to control functionalities at modem.
9533 *
9534 * @param subId the id of the subscription.
9535 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9536 *
9537 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9538 */
9539 @Override
9540 @ThermalMitigationResult
9541 public int sendThermalMitigationRequest(
9542 int subId,
9543 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9544 enforceModifyPermission();
9545
9546 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9547 final long identity = Binder.clearCallingIdentity();
9548
9549 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9550 try {
9551 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9552 switch (thermalMitigationAction) {
9553 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9554 thermalMitigationResult =
9555 handleDataThrottlingRequest(subId,
9556 thermalMitigationRequest.getDataThrottlingRequest());
9557 break;
9558 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9559 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9560 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9561 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9562 }
9563
9564 // Ensure that radio is on. If not able to power on due to phone being
9565 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9566 if (!setRadioPowerForThermal(subId, true)) {
9567 thermalMitigationResult =
9568 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9569 break;
9570 }
9571
9572 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9573 false);
9574 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9575 break;
9576 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9577 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9578 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9579 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9580 }
9581
9582 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9583 if (registry != null) {
9584 TelephonyConnectionService service =
9585 registry.getTelephonyConnectionService();
9586 Phone phone = getPhone(subId);
9587 if (phone == null) {
9588 thermalMitigationResult =
9589 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9590 break;
9591 }
9592
9593 if (PhoneConstantConversions.convertCallState(phone.getState())
9594 != TelephonyManager.CALL_STATE_IDLE
9595 || phone.isInEmergencySmsMode() || phone.isInEcm()
9596 || (service != null && service.isEmergencyCallPending())) {
9597 String errorMessage = "Phone state is not valid. call state = "
9598 + PhoneConstantConversions.convertCallState(phone.getState())
9599 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9600 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9601 errorMessage += service == null
9602 ? " TelephonyConnectionService is null"
9603 : " isEmergencyCallPending = "
9604 + service.isEmergencyCallPending();
9605 Log.e(LOG_TAG, errorMessage);
9606 thermalMitigationResult =
9607 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9608 break;
9609 }
9610 } else {
9611 thermalMitigationResult =
9612 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9613 break;
9614 }
9615
9616 // Turn radio off. If not able to power off due to phone being unavailable,
9617 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9618 if (!setRadioPowerForThermal(subId, false)) {
9619 thermalMitigationResult =
9620 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9621 break;
9622 }
9623 thermalMitigationResult =
9624 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9625 break;
9626 default:
9627 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9628 + "not exist. Requested action: " + thermalMitigationAction);
9629 }
9630 } catch (IllegalArgumentException e) {
9631 throw e;
9632 } catch (Exception e) {
9633 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9634 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9635 } finally {
9636 Binder.restoreCallingIdentity(identity);
9637 }
9638
9639 if (DBG) {
9640 log("thermalMitigationRequest returning with thermalMitigationResult: "
9641 + thermalMitigationResult);
9642 }
9643
9644 return thermalMitigationResult;
9645 }
Hui Wang641e81c2020-10-12 12:14:23 -07009646
9647 /**
9648 * Set the GbaService Package Name that Telephony will bind to.
9649 *
9650 * @param subId The sim that the GbaService is associated with.
9651 * @param packageName The name of the package to be replaced with.
9652 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9653 */
9654 @Override
9655 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9656 enforceModifyPermission();
9657
9658 final long identity = Binder.clearCallingIdentity();
9659 try {
9660 return getGbaManager(subId).overrideServicePackage(packageName);
9661 } finally {
9662 Binder.restoreCallingIdentity(identity);
9663 }
9664 }
9665
9666 /**
9667 * Return the package name of the currently bound GbaService.
9668 *
9669 * @param subId The sim that the GbaService is associated with.
9670 * @return the package name of the GbaService configuration, null if GBA is not supported.
9671 */
9672 @Override
9673 public String getBoundGbaService(int subId) {
9674 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9675
9676 final long identity = Binder.clearCallingIdentity();
9677 try {
9678 return getGbaManager(subId).getServicePackage();
9679 } finally {
9680 Binder.restoreCallingIdentity(identity);
9681 }
9682 }
9683
9684 /**
9685 * Set the release time for telephony to unbind GbaService.
9686 *
9687 * @param subId The sim that the GbaService is associated with.
9688 * @param interval The release time to unbind GbaService by millisecond.
9689 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9690 */
9691 @Override
9692 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9693 enforceModifyPermission();
9694
9695 final long identity = Binder.clearCallingIdentity();
9696 try {
9697 return getGbaManager(subId).overrideReleaseTime(interval);
9698 } finally {
9699 Binder.restoreCallingIdentity(identity);
9700 }
9701 }
9702
9703 /**
9704 * Return the release time for telephony to unbind GbaService.
9705 *
9706 * @param subId The sim that the GbaService is associated with.
9707 * @return The release time to unbind GbaService by millisecond.
9708 */
9709 @Override
9710 public int getGbaReleaseTime(int subId) {
9711 enforceReadPrivilegedPermission("getGbaReleaseTime");
9712
9713 final long identity = Binder.clearCallingIdentity();
9714 try {
9715 return getGbaManager(subId).getReleaseTime();
9716 } finally {
9717 Binder.restoreCallingIdentity(identity);
9718 }
9719 }
9720
9721 private GbaManager getGbaManager(int subId) {
9722 GbaManager instance = GbaManager.getInstance(subId);
9723 if (instance == null) {
9724 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9725 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9726 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9727 }
9728 return instance;
9729 }
Hui Wang761a6682020-10-31 05:12:53 +00009730
9731 /**
9732 * indicate whether the device and the carrier can support
9733 * RCS VoLTE single registration.
9734 */
9735 @Override
9736 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9737 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9738
9739 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9740 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9741 }
9742
9743 final long identity = Binder.clearCallingIdentity();
9744 try {
9745 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9746 if (rpm != null) {
9747 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9748 }
9749 return false;
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
9752 }
9753 }
9754
9755 /**
9756 * Register RCS provisioning callback.
9757 */
9758 @Override
9759 public void registerRcsProvisioningChangedCallback(int subId,
9760 IRcsConfigCallback callback) {
9761 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9762
9763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9764 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9765 }
9766 if (!isImsAvailableOnDevice()) {
9767 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9768 "IMS not available on device.");
9769 }
9770
9771 final long identity = Binder.clearCallingIdentity();
9772 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009773 if (!RcsProvisioningMonitor.getInstance()
9774 .registerRcsProvisioningChangedCallback(subId, callback)) {
9775 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9776 "Service not available for the subscription.");
9777 }
Hui Wang761a6682020-10-31 05:12:53 +00009778 } finally {
9779 Binder.restoreCallingIdentity(identity);
9780 }
9781 }
9782
9783 /**
9784 * Unregister RCS provisioning callback.
9785 */
9786 @Override
9787 public void unregisterRcsProvisioningChangedCallback(int subId,
9788 IRcsConfigCallback callback) {
9789 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9790
9791 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9792 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9793 }
9794 if (!isImsAvailableOnDevice()) {
9795 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9796 "IMS not available on device.");
9797 }
9798
9799 final long identity = Binder.clearCallingIdentity();
9800 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009801 RcsProvisioningMonitor.getInstance()
9802 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009803 } finally {
9804 Binder.restoreCallingIdentity(identity);
9805 }
9806 }
9807
9808 /**
9809 * trigger RCS reconfiguration.
9810 */
9811 public void triggerRcsReconfiguration(int subId) {
9812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9813 mApp, subId, "triggerRcsReconfiguration");
9814
9815 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9816 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9817 }
9818 if (!isImsAvailableOnDevice()) {
9819 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9820 "IMS not available on device.");
9821 }
9822
9823 final long identity = Binder.clearCallingIdentity();
9824 try {
9825 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9826 } finally {
9827 Binder.restoreCallingIdentity(identity);
9828 }
9829 }
9830
9831 /**
9832 * Provide the client configuration parameters of the RCS application.
9833 */
9834 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9836 mApp, subId, "setRcsClientConfiguration");
9837
9838 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9839 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9840 }
9841 if (!isImsAvailableOnDevice()) {
9842 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9843 "IMS not available on device.");
9844 }
9845
9846 final long identity = Binder.clearCallingIdentity();
9847
9848 try {
9849 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9850 if (configBinder == null) {
9851 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9852 } else {
9853 configBinder.setRcsClientConfiguration(rcc);
9854 }
9855 } catch (RemoteException e) {
9856 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9857 } finally {
9858 Binder.restoreCallingIdentity(identity);
9859 }
9860 }
9861
9862 /**
9863 * Overrides the config of RCS VoLTE single registration enabled for the device.
9864 */
9865 @Override
9866 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9868 "setDeviceSingleRegistrationEnabledOverride");
9869 enforceModifyPermission();
9870
9871 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9872 : Boolean.parseBoolean(enabledStr);
9873 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9874 }
9875
9876 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009877 * Sends a device to device communication message. Only usable via shell.
9878 * @param message message to send.
9879 * @param value message value.
9880 */
9881 @Override
9882 public void sendDeviceToDeviceMessage(int message, int value) {
9883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9884 "setCarrierSingleRegistrationEnabledOverride");
9885 enforceModifyPermission();
9886
9887 final long identity = Binder.clearCallingIdentity();
9888 try {
9889 TelephonyConnectionService service =
9890 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9891 if (service == null) {
9892 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9893 return;
9894 }
9895 service.sendTestDeviceToDeviceMessage(message, value);
9896 } finally {
9897 Binder.restoreCallingIdentity(identity);
9898 }
9899 }
9900
9901
9902 /**
Hui Wang761a6682020-10-31 05:12:53 +00009903 * Gets the config of RCS VoLTE single registration enabled for the device.
9904 */
9905 @Override
9906 public boolean getDeviceSingleRegistrationEnabled() {
9907 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9908 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9909 }
9910
9911 /**
9912 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9913 */
9914 @Override
9915 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9916 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9917 "setCarrierSingleRegistrationEnabledOverride");
9918 enforceModifyPermission();
9919
9920 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9921 : Boolean.parseBoolean(enabledStr);
9922 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9923 subId, enabled);
9924 }
9925
9926 /**
9927 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9928 */
9929 @Override
9930 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9931 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9932 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9933 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009934
9935 /**
9936 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9937 * their mobile plan.
9938 */
9939 @Override
9940 public String getMobileProvisioningUrl() {
9941 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9942 final long identity = Binder.clearCallingIdentity();
9943 try {
9944 return getDefaultPhone().getMobileProvisioningUrl();
9945 } finally {
9946 Binder.restoreCallingIdentity(identity);
9947 }
9948 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009949
James.cf Linbcdf8b32021-01-14 16:44:13 +08009950 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009951 * Get the EAB contact from the EAB database.
9952 */
9953 @Override
9954 public String getContactFromEab(String contact) {
9955 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9956 enforceModifyPermission();
9957 final long identity = Binder.clearCallingIdentity();
9958 try {
9959 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9960 } finally {
9961 Binder.restoreCallingIdentity(identity);
9962 }
9963 }
9964
9965 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009966 * Remove the EAB contacts from the EAB database.
9967 */
9968 @Override
9969 public int removeContactFromEab(int subId, String contacts) {
9970 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9971 enforceModifyPermission();
9972 final long identity = Binder.clearCallingIdentity();
9973 try {
9974 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9975 } finally {
9976 Binder.restoreCallingIdentity(identity);
9977 }
9978 }
9979
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009980 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009981 public boolean getDeviceUceEnabled() {
9982 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9983 final long identity = Binder.clearCallingIdentity();
9984 try {
9985 return mApp.getDeviceUceEnabled();
9986 } finally {
9987 Binder.restoreCallingIdentity(identity);
9988 }
9989 }
9990
9991 @Override
9992 public void setDeviceUceEnabled(boolean isEnabled) {
9993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9994 final long identity = Binder.clearCallingIdentity();
9995 try {
9996 mApp.setDeviceUceEnabled(isEnabled);
9997 } finally {
9998 Binder.restoreCallingIdentity(identity);
9999 }
10000 }
10001
10002 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010003 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10004 String callingPackage) {
10005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10006 mApp, subId, "setSignalStrengthUpdateRequest");
10007
10008 final int callingUid = Binder.getCallingUid();
10009 // Verify that tha callingPackage belongs to the calling UID
10010 mApp.getSystemService(AppOpsManager.class)
10011 .checkPackage(callingUid, callingPackage);
10012
10013 validateSignalStrengthUpdateRequest(request, callingUid);
10014
10015 final long identity = Binder.clearCallingIdentity();
10016 try {
10017 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10018 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10019
10020 if (result instanceof IllegalStateException) {
10021 throw (IllegalStateException) result;
10022 }
10023 } finally {
10024 Binder.restoreCallingIdentity(identity);
10025 }
10026 }
10027
10028 @Override
10029 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10030 String callingPackage) {
10031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10032 mApp, subId, "clearSignalStrengthUpdateRequest");
10033
10034 final int callingUid = Binder.getCallingUid();
10035 // Verify that tha callingPackage belongs to the calling UID
10036 mApp.getSystemService(AppOpsManager.class)
10037 .checkPackage(callingUid, callingPackage);
10038
10039 final long identity = Binder.clearCallingIdentity();
10040 try {
10041 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10042 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10043
10044 if (result instanceof IllegalStateException) {
10045 throw (IllegalStateException) result;
10046 }
10047 } finally {
10048 Binder.restoreCallingIdentity(identity);
10049 }
10050 }
10051
10052 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10053 int callingUid) {
10054 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10055 // phone/system process do not have further restriction on request
10056 return;
10057 }
10058
10059 // Applications has restrictions on how to use the request:
10060 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10061 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10062 // This is not system caller which has been checked above
10063 throw new IllegalArgumentException(
10064 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10065 }
10066
10067 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10068 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10069 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10070 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10071 || info.isEnabled()) {
10072 throw new IllegalArgumentException(
10073 "Only system can set hide fields in SignalThresholdInfo");
10074 }
10075
10076 // Thresholds length for each RAN need in range. This has been validated in
10077 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10078 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10079 final int[] thresholds = info.getThresholds();
10080 Objects.requireNonNull(thresholds);
10081 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10082 || thresholds.length
10083 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10084 throw new IllegalArgumentException(
10085 "thresholds length is out of range: " + thresholds.length);
10086 }
10087 }
10088 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010089
10090 /**
10091 * Gets the current phone capability.
10092 *
10093 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10094 * @return the PhoneCapability which describes the data connection capability of modem.
10095 * It's used to evaluate possible phone config change, for example from single
10096 * SIM device to multi-SIM device.
10097 */
10098 @Override
10099 public PhoneCapability getPhoneCapability() {
10100 enforceReadPrivilegedPermission("getPhoneCapability");
10101 final long identity = Binder.clearCallingIdentity();
10102 try {
10103 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10104 } finally {
10105 Binder.restoreCallingIdentity(identity);
10106 }
10107 }
Michele Berionne5e411512020-11-13 02:36:59 +000010108
10109 /**
10110 * Prepare TelephonyManager for an unattended reboot. The reboot is
10111 * required to be done shortly after the API is invoked.
10112 */
10113 @Override
10114 @TelephonyManager.PrepareUnattendedRebootResult
10115 public int prepareForUnattendedReboot() {
10116 enforceRebootPermission();
10117
10118 final long identity = Binder.clearCallingIdentity();
10119 try {
10120 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10121 } finally {
10122 Binder.restoreCallingIdentity(identity);
10123 }
10124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010125}